uniapp中这样写:this.$api.jsonHttp.get(`/api/TechnologicalItem/getTechnologicalItem/${this.paramId}?total=` + this .total).then(res => { then.array = res.data.data console.log(then.array) }) 后端 @GetMapping("getTechnologicalItem/{paramId}") public ResponseResult getTechnologicalItem(@PathVariable("paramId") String paramId,@RequestParam Integer total) { System.out.println(total); Map<String, List<AsStmTechnologicalItemEntity>> technologicalItem = asStmTechnologicalItemRestService.getTechnologicalItem(paramId); return ResponseResult.createSuccess(technologicalItem); } 帮我修正一下
时间: 2024-03-17 18:40:45 浏览: 143
你的后端代码中,`@RequestParam`注解的参数名应该与前端请求中查询参数的名字保持一致,即应该改写为`@RequestParam("total")`。同时,你的前端代码中,在发送请求时,拼接查询参数的方式可以改为使用ES6模板字符串嵌入变量的方式,代码如下:
前端代码:
```
this.$api.jsonHttp.get(`/api/TechnologicalItem/getTechnologicalItem/${this.paramId}?total=${this.total}`)
.then(res => {
this.array = res.data.data;
console.log(this.array);
});
```
后端代码:
```
@GetMapping("getTechnologicalItem/{paramId}")
public ResponseResult getTechnologicalItem(@PathVariable("paramId") String paramId, @RequestParam("total") Integer total) {
System.out.println(total);
Map<String, List<AsStmTechnologicalItemEntity>> technologicalItem = asStmTechnologicalItemRestService.getTechnologicalItem(paramId);
return ResponseResult.createSuccess(technologicalItem);
}
```
这样就可以正确获取前端传递的查询参数 `total` 的值了。
阅读全文