業務需求:根據傳進來的服務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; } }