建立一个Vo类
public class Vo {
private List<Integer> ids;
public List<Integer> getIds()
{
return ids;
}
public void setIds(List<Integer> ids)
{
this.ids = ids;
}
}
原因是Swagger拼入的字符串不一定是数组 所以借助一个Vo类
Controller
@PostMapping("deletevideos")
@ApiOperation(value = "删除摄像头")
public boolean deleteCarByIds(@RequestBody Vo voids){
return videoService.deletevideos(voids);
}
Service
public boolean deletevideos(Vo voids) {
// TODO Auto-generated method stub
try {
List<Integer> ids = voids.getIds();
videoMapper.deletevideos(ids);
return true;
} catch (Exception e) {
log.error("deletevideos————批量删除摄像头异常: ");
log.error(e.getMessage());
}
return false;
}
Dao
void deletevideos(List<Integer> voids);
Mapper
<delete id="deletevideos" parameterType="java.lang.Integer">
DELETE FROM T_DEVICE_VIDEO
WHERE ID
IN
<foreach item="item" collection="list" open="(" separator="," close=")">
#{item,jdbcType=INTEGER}
</foreach>
</delete>
或者可以 让开始参数传入一个字符串 我们自己来分割成 数组。
String[] arrids = ids.split(",");
List<String> list=Arrays.asList(arrids);
或者直接拿数组去变量查询或者删除
下面是controller到mapper的小例子
controller
@GetMapping(value="dept/getsubordinate")
@ApiOperation("获取传入部门下级部门")
public List<Map<String, Object>> getSubordinate(@RequestParam("depts")String depts){
List<Map<String, Object>> list = null;
list = resourcesService.getSubordinate(depts);
return list;
}
service
public List<Map<String, Object>> getSubordinate(String depts) {
// TODO Auto-generated method stub
List<Map<String, Object>> list = null;
try {
String[] dept = depts.split(",");
list = resourcesMapper.getSubordinate(dept);
} catch (Exception e) {
log.error("getSubordinate————获取所属下级部门error: ");
log.error(e.getMessage());
}
return list;
}
dao
/** 传入多个上级部门查询所有下属单位 */
public List<Map<String, Object>> getSubordinate(String[] dept);
mapper
<select id="getSubordinate" parameterType="java.lang.String" resultType="java.util.Map">
SELECT T.DEPTNO,T.DEPTNAME,T.DEPTGRADE,T.GRADENAME,T.SHORTNAME,T.CENTERPOINT,T.MAPLEVEL,T.AREACOLOR,T.SORTID,T.PARENTDEPT,T.PARENTDEPTNAME
FROM VMGR_DEPT_LAST T
WHERE T.PARENTDEPT IN
<foreach collection="array" item="dept" open="(" separator="," close=")">
#{dept}
</foreach>
</select>
搞定-------------------------------