码迷,mamicode.com
首页 > 编程语言 > 详细

SpringMVC(二)传值

时间:2016-08-07 18:41:47      阅读:206      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!