业务需求:根据传进来的服务id(多个),更新该服务id对应的某个字段。
java
抛开业务,纯sql以下sql
UPDATE t_customer_services SET USE_FLAG = 1 WHERE CUSTOMER_ID = 1000000001 AND SERVICE_ID IN ( 10000000000000000, 10000000000000001 )
1、mybatis xml中以下
mybatis
<update id="updateByPrimaryKeyStringSelective" parameterType="com.readygo.pet.vo.ServiceIdListVO"> UPDATE t_customer_services SET USE_FLAG = #{useFlag}, UPD_PID = #{updPid}, UPD_TIME = DATE_FORMAT(NOW(),'%Y%m%d%H%m%s') WHERE CUSTOMER_ID = #{customerId} AND SERVICE_ID IN <foreach collection="serviceIdList" item="item" index="index" open="(" separator="," close=")"> #{item} </foreach> </update>
2、com.readygo.pet.vo.ServiceIdLisVO 以下
this
package com.readygo.pet.vo; import java.util.List; public class ServiceIdListVO { /** * 用户ID */ private Integer customerId; /** * 更改程序ID */ private String updPid; /** * 废止区分 */ private Integer useFlag; /** * 服务ID list */ private List<String> serviceIdList; public Integer getCustomerId() { return customerId; } public void setCustomerId(Integer customerId) { this.customerId = customerId; } public List<String> getServiceIdList() { return serviceIdList; } public void setServiceIdList(List<String> serviceIdList) { this.serviceIdList = serviceIdList; } public String getUpdPid() { return updPid; } public void setUpdPid(String updPid) { this.updPid = updPid; } public Integer getUseFlag() { return useFlag; } public void setUseFlag(Integer useFlag) { this.useFlag = useFlag; } }