【spring mvc】spring mvc POST方式接收单个字符串参数,不加注解,接收到的值为null,加上@RequestBody,接收到{"uid":"品牌分类大”},加上@RequestP...

spring mvc POST方式 接收单个参数,不加任何注解,参数名对应,接收到的值为null

【spring mvc】spring mvc POST方式接收单个字符串参数,不加注解,接收到的值为null,加上@RequestBody,接收到{"uid":"品牌分类大”},加上@RequestP...

 

spring mvc POST方式 接收单个参数,加上@RequestBody,接收到参数格式:{"uid":"品牌分类大”}

【spring mvc】spring mvc POST方式接收单个字符串参数,不加注解,接收到的值为null,加上@RequestBody,接收到{"uid":"品牌分类大”},加上@RequestP...

 

spring mvc POST方式 接收单个参数,加上@RequestParam报错:

org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'uid' is not present

 

 

解决方法:

最简单的解决方式,就是将要接受的字段封装在一个实体中,实体中的属性为uid,并且在spring mvc中接收时加上@RequestBody注解,这样就可以解决这个问题

示例代码:

【spring mvc】spring mvc POST方式接收单个字符串参数,不加注解,接收到的值为null,加上@RequestBody,接收到{"uid":"品牌分类大”},加上@RequestP...

 

 

 

 

 

下面看GET方式解决接收单个参数的问题:

只需要在接收的单个参数前加上@RequestParam注解即可

示例代码:

【spring mvc】spring mvc POST方式接收单个字符串参数,不加注解,接收到的值为null,加上@RequestBody,接收到{"uid":"品牌分类大”},加上@RequestP...