首页 > 编程语言 > 详细

SpringMVC(二)传值

时间:2016-08-07 18:39:10      阅读:352      评论:0      收藏:0      [点我收藏+]

 

 

1、HelloController.java

 

通过model.addAttribute(key,value)进行传值

package zttc.itat.controller;  
import org.springframework.stereotype.Controller;  
import org.springframework.web.bind.annotation.RequestMapping;  
  
@Controller  
public class HelloController{  
    //RequestMapping表示用哪个URL来对应  
    @RequestMapping{{"/hello","/"}}  
    public String hello(String username, Model model){  
           System.out.println("hello");  
model.addAttribute(
"username", username);
       model.addAttribute(username);//默认使用对象的类型作为key,即
model.addAttribute("string",username),注意string开头是小写
       System.out.println(username);
           return "hello";  
     }   
    @RequestMapping{{"/welcome"}}  
     public String welcome(){  
           System.out.println("welcome");  
           return "welcome";  
      }   
}  

 

2、hello.jsp

<head>  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
<title></title>  
</head>  
<body>  
<h1>hello!! ${username}</h1>  
<h2>hello!!!! ${string}</h2>  
</body>

 

在客户端地址栏输入:localhost……/hello?username=value

SpringMVC(二)传值

原文:http://www.cnblogs.com/Donnnnnn/p/5746744.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!