get 请求参数是对象怎么办 | 您所在的位置:网站首页 › get方法传数组 › get 请求参数是对象怎么办 |
在开发中,我们知道 Restful 对查询的规范是使用 get 请求,而一个管理画面的查询条件是多个,那么就需要前台传给后台一个对象。 本篇文章介绍如何使用 get 请求传递对象。 前端传参在前台不能使用 this.$axios.get ,而是需要使用 this.$axios.request ,使用方法如下。 this.$axios.request({ method: 'GET', url: '/person/getByConditions', params: { name: 'Mary', sex: '女', } }).then((res) => { this.records = res })params 也可以直接指定一个对象,和上面的写法作用一样。 const reqData = { name: 'Mary', sex: '女' } this.$axios.request({ method: 'GET', url: '/person/getByConditions', params: reqData }).then((res) => { this.records = res }) 后台接收存放查询条件的 Dto /** * person 表查询用dto * @author admin */ @Data @NoArgsConstructor @AllArgsConstructor public class PersonQueryDto { private String name; private String sex; }Controller 中的 get 请求对于参数不需要添加任何注解。 @RestController @RequestMapping("/person") public class PersonController { @Autowired PersonService personService; @GetMapping("/getByConditions") public List getByNameAndSex(PersonQueryDto personQueryDto) { return personService.getByNameAndSex(personQueryDto); } } |
CopyRight 2018-2019 实验室设备网 版权所有 |