Mybatis batch update multiple field values
Controller
/** * * @Description: production materials - Indicators publishing interface * @Creator: tangsw * @CreateTime: 2019-12-25 10:37:34 * @Modifier: * @ModifyTime: * @Reasons: * @Param the Output production output * @Param Capacity capacity utilization * @Param Contract compliance rate schedule * @Param Vendor vendor misconduct disposal rate * @return * @throws Exception */ @RequestMapping(value = { "/updStatus/output/publish", "/updStatus/capacity/publish", "/updStatus/contract/publish", "/updStatus/vendor/publish" }) @ResponseBody @OptLog (Module1 = "Production Material - Index", operate = "The Status Update distribution ids" ) public R & lt updatePublishByIds (@RequestBody List <String> ids) throws Exception { Assert.notNull (IDS, "IDS can not be empty" ); Map<String, Object> params = new HashMap<>(); List<Map<String, Object>> list = new ArrayList<>(); for (String id : ids) { Map<String, Object> map = new HashMap<>(); map.put("id", id); map.put("status", PgCommonIndexFinalKV.INDEX_ADMIN_PUBLISH_STATUS); map.put("mdate", new Date()); map.put("muser_id", getCurrentUser().getId()); list.add(map); } params.put ( "List" , List); int the n-= indexProdcutService.updatePublishByIds (params); return R.ok ( "production materials - indicators released successful" , the n-); }
Service
public int updatePublishByIds( Map<String,Object>params);
ServiceImpl
@Override public int updatePublishByIds(Map<String, Object> params) { return super.dao.updatePublishByIds(params); }
Dao
public int updatePublishByIds(Map<String,Object>params);
sql.xml
<update id="updatePublishByIds" parameterType="java.util.Map"> <foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";"> update INDEX_PRODCUT <set> <if test="item.status != null and item.status !='' "> status=#{item.status,jdbcType=VARCHAR}, </if> <if test="item.mdate != null "> mdate=#{item.mdate,jdbcType=TIMESTAMP}, </if> <if test="item.muser_id != null and item.muser_id !='' "> muser_id=#{item.muser_id,jdbcType=VARCHAR} </if> </set> where id = #{item.id} </foreach> </update>