1. 程式人生 > >Spring Boot 使用DAO層不使用xml直接進行數據訪問

Spring Boot 使用DAO層不使用xml直接進行數據訪問

bat pro 快速 provide query off string 數據 rop

一般我們開發Spring boot的web應用的時候,一般會實現Service接口,然後實現對應的類,調用方法,通過對DAO映射進行數據訪問,我現在就說一下如何實現簡單快速的實現數據的訪問。通過對DAO層直接進行數據的訪問.

@Results({
@Result(column = "id",property = "id")
})

@SelectProvider(type = SqlProvider.class,method = "queryReceivableForm")
List<ReceivableForm> queryReceivableForm(Map<String, Object> map);

class SqlProvider{
public String queryReceivableForm(Map<String,Object> map){
String sql = new SQL(){
{
SELECT("id,settlement_cycle,tc_code,insurance_name,payment_channel,amount_receivable,refund_amount," +
"net_settlement,actual_amount_received,amount_paid,net_amount");
FROM("t_insurance_collection");
WHERE("batch_no = #{batchNo}");
WHERE("archive_flag = ‘1‘");
if(!StringUtils.isEmpty(map.get("paymentChannel")))
{
WHERE("payment_channel = #{paymentChannel}");
}
}
}.toString();
if (map.get("offset")!=null&&map.get("limit")!=null){
sql += "limit #{offset},#{limit}";
}
return sql;
}

Spring Boot 使用DAO層不使用xml直接進行數據訪問