今天犯了一个蠢蠢的错误
前端vue的ajax请求是这么定义的
axios.get("/checkitem/findById?id=" + row.id).then((res) => {
alert(row.id + 1);
if(res.data.flag){
//进行回显,基于VUE的数据绑定实现
this.formData = res.data.data;
}else{
//查询失败,弹出提示
this.$message.error(res.data.message);
}
});
然后后端刚开始是这样接收的
@RestController
@RequestMapping("/checkitem")
@Slf4j
public class CheckitemController {
@Autowired
private BrandService brandService;
//TODO 5 根据id查找,数据回显
@GetMapping("/findById")
public Result findById(@PathVariable int id){
log.info("id为:{}",id);
Brand brand = brandService.getById(id);
if(brand!=null){
return new Result(true,"查询成功",brand);
}else {
throw new RuntimeException("查找失败");
}
}
}
感觉是不太对,但是改来改去不是404就是200之后参数获取不到,最后发现是这里不能加@PathVariable,它的用法是只有url是带有{id}是才能获取参数传参,删除@PathVariable之后问题解决