springboot配置mybatis的mapper路径

您所在的位置:网站首页 springboot注解配置扫描路径 springboot配置mybatis的mapper路径

springboot配置mybatis的mapper路径

2024-02-03 13:01| 来源: 网络整理| 查看: 265

原文地址:开发者导航 · 你想要的,我全都有!

1、创建xml目录

在src/main/resources/目录下新建mybatis文件夹,将xxx.xml文件放入该文件夹内(也可以创建多级目录)

2、在application.yml文件中配置:

mybatis:

  configuration:

    mapUnderscoreToCamelCase: true

  mapperLocations: mybatis/*Mapper.xml

3、在Dao接口文件中加注解@Mapper,注意使用xml文件写sql语句要将接口方法上的sql语句去掉

@Mapper public interface MrInfoMapper {     /**      * 根据条件查询MR信息      * @param param      * @return      */     public List findByCondition(Map param);     /**      * 获取页面展示数据      * @param param      * @return      */     // @Select("" + "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} "     // + "" + ""     // + " and ${item}='Y'" + "" + "" + "GROUP BY" + " mi.intf_file" + "")     public List findDisplayData(Map param);

4、在xxxmapper.xml文件中写SQL,注意namesapce值不要写错。

    SELECT         *     FROM         tb_mr_info tmi     WHERE 1=1     AND tmi.table_flag=#{searchDate}                             and ${item}='Y'              



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3