Springboot Configuring the Mapper path for MyBatis

Source: Internet
Author: User

1. Create a new MyBatis folder in the src/main/resources/directory and put the Xxx.xml file in the folder

2. Configure in the Application.yml file:

MyBatis

Configuration

Mapunderscoretocamelcase:true

Mapperlocations:mybatis/*mapper.xml

3, in the DAO interface file annotated @mapper, note that the interface method on the SQL statement to remove

@Mapper Public Interfacemrinfomapper{/*** Query Mr Information on condition *@paramparam *@return     */     PublicList<map<string, object>> findbycondition (map<string, object>param); /*** Get page display data *@paramparam *@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 is mi.ce= ' Y ' then ' ce ' end, '),"//+ "ifnull (case is mi.ne= ' Y ' Then ' ne ' End, '),"//+ "ifnull (case is mi.ptn= ' Y ' then ' ptn ' End, '),"//+ "ifnull (case is mi.rtn= ' Y ' then ' rtn ' End, '),"//+ "ifnull (case is 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>")     PublicList

4, write SQL in the Xxxmapper.xml file, note the NAMESAPCE value do not write wrong.

<?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 "><Mappernamespace= "Com.huawei.nos.nosimsys.dao.MrInfoMapper"><SelectID= "Findbycondition"ParameterType= "Map"Resulttype= "Map">SELECT * from Tb_mr_info TMI WHERE 1=1 and Tmi.table_flag=#{searchdate}<ifTest= "ProductList ! = null and ProductList! =" ">          <foreachCollection= "ProductList"Item= "Item">and ${item}= ' Y '</foreach>    </if></Select>

Springboot Configuring the Mapper path for MyBatis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.