问题
- 前端在使用 axios.post()携带参数强求后端Controller接口时,不使用实体类接收,导致接收的参数为 null 。为了搞清楚有哪些用法,也是研究了一下。
GET请求
- 方式一:参数格式:{params:{key1:val1, key2:val2}}
//前端
this.$axios.get("http://localhost:8080/api/function/login/loginget",
{params:{name:"carlget1", password:"password"}})
// 后端代码
@RequestMapping("loginget")
public Map<String, Object> login(String name, String password){}
//前端
axios.get("/checkitem/getItemIdByGroupId/"+row.id)
//后端
@GetMapping("/getItemIdByGroupId/{id}")
public List<Integer> getItemIdByGroupId(@PathVariable("id") Integer id){}
POST请求
//前端
var param = {
currentPage: this.pagination.currentPage, //页码
pageSize: this.pagination.pageSize, //每页显示的记录数
queryString: this.pagination.queryString //查询条件
};
axios.post("/checkitem/groupPageQuery",param)
//后端
@PostMapping("/groupPageQuery")
public PageResult groupPageQuery(@RequestBody QueryPageBean queryPageBean){}
//前端
axios.post("/checkitem/addGroup/"+this.checkitemIds,this.formData)
//后端
@PostMapping("/updateGroup/{checkitemIds}")
public Result updateGroup(@PathVariable("checkitemIds") Integer[] checkitemIds, @RequestBody CheckGroup checkGroup){
总结下来,最好还是使用 实体类 接收参数