provider 可以動(dòng)態(tài)生成 sql
在處理復(fù)雜邏輯而又不能使用存儲(chǔ)過(guò)程的時(shí)候有很大優(yōu)勢(shì)
Mapper 中配置
@UpdateProvider(type = MerchantProvider.class, method = "updateSalesman")
void updateSalesman(@Param("M") MerchantSalesDTO merchantSalesDTO);
Provider 中配置
import com.icekredit.merchant.entity.DTO.MerchantDTO;
import com.icekredit.merchant.entity.DTO.MerchantSalesDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
/**
* Created by johnzh on
* 2017/4/27. 10:01
*/
public class MerchantProvider {
public String updateSalesman(@Param("M") MerchantSalesDTO merchantSalesDTO){
SQL sql = new SQL(){{
UPDATE("merchant_sales");
if (merchantSalesDTO.getSalesName() != null){
SET("sales_name = #{M.salesName}");
}
if (merchantSalesDTO.getUpper() != null){
SET("upper = #{M.upper}");
}
WHERE("sales_id = #{M.salesId}");
}};
return sql.toString();
}
}