@ApiOperation(value = "多个参数查询_通过Java Bean传递多个参数") @PostMapping("findByBeans") public ResultMsg findByBeans(@RequestBody Employee employee) { List result= employeeMapper.selectByBeans(employee); return ResultMsg.getMsg(result); }
mapper
1
List <Employee> selectByBeans(Employee employee);
xml
参数的引用直接使用bean的字段
1 2 3 4 5
<selectid="selectByBeans"resultMap="BaseResultMap"parameterType="com.wg.demo.po.Employee"> select * from employee where gender = #{gender} and age = #{age} </select>
@ApiOperation(value = "多个参数查询_通过JSON传递多个参数") @PostMapping("findByJSONObject") public ResultMsg findByJSONObject(@RequestBody JSONObject params) { List result= employeeMapper.findByJSONObject(params); return ResultMsg.getMsg(result); }
mapper
1
List <Employee> findByJSONObject(JSONObject params);
xml
1 2 3 4 5 6
<selectid="findByJSONObject"resultMap="BaseResultMap"parameterType="com.alibaba.fastjson.JSONObject"> select * from employee where gender = #{gender} and age = #{age} </select>
@ApiOperation(value = "多个参数查询_通过List、Set、Array传递多个参数") @PostMapping("findByList") public ResultMsg findByList(@RequestBody List<String> list) { List result= employeeMapper.findByList (list); return ResultMsg.getMsg(result); }
mapper
1
List <Employee> findByList(List list);
xml
1 2 3 4 5 6
<selectid="findByList"resultMap="BaseResultMap" > SELECT * from employee where age in <foreachcollection="list"open="("separator=","close=")"item="age"> #{age} </foreach> </select>
@ApiOperation(value = "多个参数查询_对象+集合参数") @PostMapping("findByDepartment") public ResultMsg findByDepartment(@RequestBody Department department) { List result= employeeMapper.findByDepartment(department); return ResultMsg.getMsg(result); }
mapper
1
List <Employee> findByDepartment(@Param("department")Department department);
xml
1 2 3 4 5 6
<selectid="findByDepartment"resultMap="BaseResultMap"parameterType="com.wg.demo.po.Department"> SELECT * from employee where dept_id =#{department.id} and age in <foreachcollection="department.employees"open="("separator=","close=")"item="employee"> #{employee.age} </foreach> </select>