mybatics批量更改

controller

@ApiOperation(value ="批量更改审核及删除状态", notes ="批量更改审核及删除状态")

@ApiResponses({@ApiResponse(code =200, message ="操作成功", response = ResponseBodyDto.class)})

@ApiImplicitParam(name="ids",value ="逗号拼接id",dataType ="String",paramType ="query",example ="1,2",required=true)

@RequestMapping(value ="/batchUpdateVessel", method = RequestMethod.GET)

@ResponseBody

public ResponseBodyDto batchUpdateVessel(String ids,String state,String isDelete) {

String[] idStr = ids.split(",");

List list =new ArrayList();

for (String id : idStr) {

list.add(id);

}

int result=vesselService.batchUpdateVessel(list,state,isDelete);

if(result>0){

for (String id : idStr) {

Vessel vessel1=vesselService.selectVesselDetail(Long.parseLong(id));

if (vessel1!=null){

elasticSearch.writeDataToES("vessel","docs", JSON.toJSONString(vessel1));

}

}

}

return new ResponseBodyDto<>(result);

}


service

int batchUpdateVessel(List list, String state,String isDelete);


mapper

int batchUpdateVessel(@Param("ids") List ids,@Param("state") String state,@Param("isDelete")String isDelete);

sql

<update id="batchUpdateVessel">

update `vessel`

set `updated_at`= now(),

<if test="state != null" >

state = #{state,jdbcType=BIT}

</if>

<if test="isDelete != null" >

is_delete = #{isDelete,jdbcType=BIT}

</if>

where `id` in

<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">

${item}

</foreach>

</update>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,009评论 19 139
  • 先创建服务端的APP 1.官网下载Winrun4j。http://winrun4j.sourceforge.net...
    Alex_1799阅读 1,829评论 1 2
  • width: 65%;border: 1px solid #ddd;outline: 1300px solid #...
    邵胜奥阅读 4,894评论 0 1
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,516评论 0 13
  • 咖啡冥想8月8号 大目标:无论未来怎样,坚定目标,报答老高一直以来对我的关爱与支持:把丽塾经营好,用金刚智慧为店铺...
    wendy雯丽阅读 187评论 0 0