• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
java幼儿园小哥哥
博客园    首页    新随笔    联系   管理    订阅  订阅

@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;

 


 

posted @ 2019-05-03 11:55  java幼儿园小哥哥  阅读(1527)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3