spring mvc应用

1:@RequestParam(value="id",defaultValue="0") String id
id:get set


UI:?id=***


可以用Map<String, Object>,其键值可以在页面上用EL表达式${键值名}得到,


3)也可以用Model类对象来传递,有addAttribute(key, value)方法,其键值可以在页面上用EL表达式${键值名}得到,


即有一个User类,如下
package model;


public class User {
       private String name ;
       private String hobby ;
       public User(){
            
      }
       public User(String name, String hobby) {
             this.name = name;
             this.hobby = hobby;
      }
//...get/set方法略  


则页面上可以用
<form name="form1" action="hello4" method="post">
     <input type="text" name="name"/>
     <input type="text" name="hobby"/>




2 consumes、produces 示例
cousumes的样例:
[java] view plaincopy在CODE上查看代码片派生到我的代码片
@Controller  
@RequestMapping(value = "/pets", method = RequestMethod.POST, consumes="application/json")  
public void addPet(@RequestBody Pet pet, Model model) {      
    // implementation omitted  
}  
方法仅处理request Content-Type为“application/json”类型的请求。






produces的样例:


[java] view plaincopy在CODE上查看代码片派生到我的代码片
@Controller  
@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, produces="application/json")  
@ResponseBody  
public Pet getPet(@PathVariable String petId, Model model) {      
    // implementation omitted  
}  
方法仅处理request请求中Accept头中包含了"application/json"的请求,同时暗示了返回的内容类型为application/json;




如果请求中有多个同名的应该如何接收呢?如给用户授权时,可能授予多个权限,首先看下如下代码:
public String requestparam7(@RequestParam(value="role") String roleList)
如果请求参数类似于url?role=admin&rule=user,则实际roleList参数入参的数据为“admin,user”,即多个数据之间使用“,”分割;我们应该使用如下方式来接收多个请求参数:
var arr = new Array();
arr.push()
public String requestparam7(@RequestParam(value="role") String..args)
   

 
public String requestparam8(@RequestParam(value="list") List<String> list)     
 到此@RequestParam我们就介绍完了,以上测试代码在cn.javass.chapter6.web.controller. paramtype.RequestParamTypeController中。





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tony168hongweigan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值