2021-05-26

前后端分离springmvc关于遇到Post提交踩的坑

org.springframework.web.bind.MissingServletRequestParameterException: Required int parameter 'userName' is not present

 public User getByAll(@RequestParam(value = "username")int userName,@RequestParam(value = "password")int passWord)
formSubmit(e){
				const that=this
				uni.request({
					url:Vue.prototype.server_url+'/shop/user/login',
					method:'POST',
					
					data:{
						username:e.detail.value.userName,
						password:e.detail.value.passWord,
					},
					success(res) {
						console.log(res)
					}
				})
				
			}

解决方式

1.请求参数和@RequestParam(value = "userName ", required = true) String userName,注解@RequestParam的value值不一样的

2.一定在前端请求中加请求头

header: {
						'content-type': 'application/x-www-form-urlencoded' // 默认值
					},

 

上一篇:InnoDB Purge是工作原理?


下一篇:application/x-www-form-urlencoded与application/json