vue向后台传参的问题
2019-35-18 11:35:43:890[http-nio-8081-exec-10]WARNo.s.w.s.m.support.DefaultHandlerExceptionResolver-Resolved exception caused by Handler execution: org.springframework.web.bind.MissingServletRequest..
·
2019-35-18 11:35:43:890[http-nio-8081-exec-10]WARN o.s.w.s.m.support.DefaultHandlerExceptionResolver-Resolved exception caused by Handler execution: org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter ‘pName’ is not present
作为一个刚接触vue的小菜鸡,经常会出现一些问题,这个就是其中的一个
就是在多个input查询时用get方法向后台访问时出现的问题
findlists() {
let p1 = this.formInline.pCate ||undefined
let p2 = this.formInline.pName.join||undefined
let p3 = this.formInline.pPrice|undefined
let p4 = this.formInline.pJianjie||undefined
console.log(p2)
console.log(p1)
console.log(p3)
console.log(p4)
axios({
url:'http://localhost:8081/product/searchnumcha',
method:'get',
params:{
pCate:p1,
pName:p2,
pPrice:p3,
pJianjie: p4,
},
}).then(({data})=>{
this.allpro = data;
console.log(this.tabledatel.pCate)
}
)
},
这边是前台的方法
@RequestMapping("/searchnumcha")
public int searchnumcha(@RequestParam(value = "pCate" ) String cate,@RequestParam(value = "pName") String name,
@RequestParam(value = "pPrice") String price,@RequestParam(value = "pJianjie") String info){
return productService.searchnumcha(cate,name,price,info);
}
这是后台方法
出错的原因就是某一个input的值是空的,pName是空的,需要改成
let p2 = this.formInline.pName.join+''||undefined
就是在他没数据的时候p2为undefined
然后后台加入判断
if(name.equals("undefined")){
name = null;
}
这样就能让某一个或者几个input为空了
鉴于刚接触vue 可能有些东西说的不对 希望能帮助到你
感谢查看
更多推荐
已为社区贡献3条内容
所有评论(0)