@Mapper public interface PersonInfoMapper { //如果一個參數 直接用#{參數名} 就可以 @Select("select * from table pi WHERE pi.ID = #{id}") PersonInfo selectByPrimaryKey(String id); @Select("select * from table pi WHERE pi.local_store_Datetime >= #{localStoreDatetime} ") List<PersonInfo> selectByBeginDate(Date localStoreDatetime); @Select("select * from table pi WHERE pi.local_store_Datetime <= #{localStoreDatetime} ") List<PersonInfo> selectByEndDate(Date localStoreDatetime);
//如果多個個參數 可以用${param1} 需要注意參數順序 或者下面@Select("select * from table pi WHERE pi.local_store_Datetime >= to_date('${param1}','yyyy-MM-dd HH24:mi:ss')" +
" and pi.local_store_Datetime <= to_date('${param2}','yyyy-MM-dd HH24:mi:ss')") List<PersonInfo> selectByBeginAndEnd(String beginDate, String endDate);// script 標籤 &(邏輯與) & <(小於) < >(大於) > "(雙引號) " '(單引號) '
//多個參數 還可以 如下 在參數列表中增加@Param註解 用${param中的名字} 獲取數據 如果需要判斷 在字符串中首尾增加
<script>標籤@Select("<script>" + select + " WHERE 1 = 1 " + "<if test='beginDate!=null'>" + "AND PI.local_store_Datetime >= to_date('${beginDate}','yyyy-MM-dd HH24:mi:ss') " + "</if>" + "<if test='endDate!=null'>" + "AND PI.local_store_Datetime <= to_date('${endDate}','yyyy-MM-dd HH24:mi:ss') " + "</if>" + "</script>") List<PersonInfo> selectByBeginDateAndEndDate(@Param("beginDate") String beginDate, @Param("endDate")String endDate);}