springboot配置mybatis的mapper路徑

來源:互聯網
上載者:User

標籤: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路徑

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.