springMvc @RequestParam注解技巧

简介: springMvc @RequestParam注解技巧
    
@RequestMapping("/testRequestParamNoAnnotation")
public String testRequestParamNoAnnotation(String name){
    return name + ",testRequestParam success.";
}

        
/**
* 由于@RequestParam 中的定义 boolean required() default true;
* 默认  required 是必须的
* 如果直接写成@RequestParam String name,访问的时候不加name参数的话,会请求报错: [org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'name' is not present]
* 很明显它说你必须要给定name参数
* 
* produces="text/plain;charset=UTF-8"解决中文乱码
* @param name
* @return
*/
@RequestMapping(path="/testRequestParamWithAnnotation",produces="text/plain;charset=UTF-8")
public String testRequestParamWithAnnotation(@RequestParam(required = false) String name){
    return name + ",testRequestParamWithAnnotation success.";
}
目录
相关文章
|
前端开发 网络架构
SpringMVC -->ant风格的路径 -->占位符 -->获取请求参数 -->@RequestParam
SpringMVC -->ant风格的路径 -->占位符 -->获取请求参数 -->@RequestParam
134 0
|
XML JSON 数据格式
SpringMVC - @RequestMapping、@ResponseBody、@RequestBody、@RequestParam、@PathVariable(二)
SpringMVC - @RequestMapping、@ResponseBody、@RequestBody、@RequestParam、@PathVariable(二)
184 0
SpringMVC - @RequestMapping、@ResponseBody、@RequestBody、@RequestParam、@PathVariable(二)
SpringMVC - @RequestMapping、@ResponseBody、@RequestBody、@RequestParam、@PathVariable(一)
SpringMVC - @RequestMapping、@ResponseBody、@RequestBody、@RequestParam、@PathVariable(一)
119 0
SpringMVC - @RequestMapping、@ResponseBody、@RequestBody、@RequestParam、@PathVariable(一)
|
XML JSON Java
SpringMVC - @RequestMapping、@ResponseBody、@RequestBody、@RequestParam、@PathVariable(三)
SpringMVC - @RequestMapping、@ResponseBody、@RequestBody、@RequestParam、@PathVariable(三)
139 0
|
前端开发 Java Spring
|
JSON 数据格式 XML
springMVC中@RequestParam和@RequestBody之contentType
springmvc @RequestBody @RequestParam
7166 0
|
前端开发 Java Spring
Spring MVC @RequestParam @RequestHeader @CookieValue用法
package com.hust.springmvc1; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation
1496 0
springmvc中@PathVariable和@RequestParam的区别
http://localhost:8080/Springmvc/user/page.do?pageSize=3&pageNow=2 你可以把这地址分开理解,其中问号前半部分:http://localhost:8080/Springmvc/user/page.
940 0
|
JavaScript 前端开发
SpringMVC中通过@ResponseBody返回对象,Js中调用@ResponseBody返回值,统计剩余评论字数的js,@RequestParam默认值,@PathVariable的用法
1、SpringMVC中通过@ResponseBody返回对象,作为JQuery中的ajax返回值 package com.kuman.cartoon.controller;   import java.util.Map;   import javax.servlet.http.HttpServletRequest;   import org.apac
2964 0