標籤:return 條件查詢 org 建立 doc turn change object col
1、在src/main/resources/目錄下建立mybatis檔案夾,將xxx.xml檔案放入該檔案夾內
2、在application.yml檔案中配置:
mybatis:
configuration:
mapUnderscoreToCamelCase: true
mapperLocations: mybatis/*Mapper.xml
3、在Dao介面檔案中加註解@Mapper,注意要將介面方法上的sql語句去掉
@Mapperpublic interface MrInfoMapper{ /** * 根據條件查詢MR資訊 * @param param * @return */ public List<Map<String, Object>> findByCondition(Map<String, Object> param); /** * 擷取頁面展示資料 * @param param * @return */ // @Select("<script>" + "SELECT" + " group_concat(id) id," + " max(mi.mr) mr," + " mi.intf_file," // + " max(mi.area) area," + " max(mi.rversion) rversion," + " concat(" // + " ifnull(case when mi.ce=‘Y‘ then ‘CE ‘ end,‘‘)," // + " ifnull(case when mi.ne=‘Y‘ then ‘NE ‘ end,‘‘)," // + " ifnull(case when mi.ptn=‘Y‘ then ‘PTN ‘ end,‘‘)," // + " ifnull(case when mi.rtn=‘Y‘ then ‘RTN ‘ end,‘‘)," // + " ifnull(case when mi.trans=‘Y‘ then ‘TRANS ‘ end,‘‘)" + ") products," // + " group_concat(distinct mi.change_type) change_type," + " max(mi.table_flag) table_flag" + " FROM " // + " tb_mr_info mi " + "WHERE" + " mi.intf_file IS NOT NULL" + " AND mi.table_flag = #{searchDate} " // + "<if test=\"productList != null \">" + "<foreach item=\"item\" collection=\"productList\" >" // + " and ${item}=‘Y‘" + "</foreach>" + "</if>" + "GROUP BY" + " mi.intf_file" + "</script>") public List<HashMap<String, String>> findDisplayData(Map<String, Object> param);
4、在xxxmapper.xml檔案中寫SQL,注意namesapce值不要寫錯。
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.huawei.nos.nosimsys.dao.MrInfoMapper"><select id="findByCondition" parameterType="map" resultType="map"> SELECT * FROM tb_mr_info tmi WHERE 1=1 AND tmi.table_flag=#{searchDate} <if test="productList != null and productList != ‘‘"> <foreach collection="productList" item="item"> and ${item}=‘Y‘ </foreach> </if></select>
springboot配置mybatis的mapper路徑