@PathVariable注解的使用和@Requestparam

一、 @PathVariable

 @PathVariable这是一个路径映射格式的书写方式注解,在类映射路径的后加上/{对应方法参数中属性@PathVariable("code")中的code},

@SuppressWarnings({ "unchecked", "rawtypes" })
@RequestMapping(value = "/decodeUserInfo/{codee}", method = RequestMethod.GET)
@ResponseBody
public Map decodeUserInfo(@PathVariable("codee") String codee) {

Map map = new HashMap();

/////////////////////////////////////////////////////////////////////////自己定义的code

String code = codee;

 

 二、@Requestparam注解将请求参数绑定至方法参数即你可以使用@RequestParam注解将请求参数绑定到你控制器的方法参数上

1.value:请求参数名(必须配置)

2.required:是否必须,默认true,即请求中必须包含该参数,如果没有包含,将会抛出异常(可选配置)

3.defaultValue:默认值,如果设置了该值,require将自动设为false,无论你是否配置了required,配置了什么值,required将自动设为false

@Requestparam(value="表示参数名字",require=boolean类型表示是否为必须,defaultValue=“表示默认值”)

@SuppressWarnings({ "unchecked", "rawtypes" })
@RequestMapping(value = "/decodeUserInfo", method = RequestMethod.GET)
@ResponseBody
public Map decodeUserInfo(@RequestParam String codee) {

Map map = new HashMap();

/////////////////////////////////////////////////////////////////////////自己定义的code

String code = codee;

 

猜你喜欢

转载自www.cnblogs.com/wym591273/p/10804731.html