Mybatis-config.xml and mapper Basic settings

Source: Internet
Author: User
Tags connection pooling

Mybatis-config.xml:

<?xml version= "1.0" encoding= "UTF-8"? ><!DOCTYPE Configuration Public"-//mybatis.org//dtd Config 3.0//en" "Http://mybatis.org/dtd/mybatis-3-config.dtd" ><configuration> <!- -Read db.properties Files--<properties resource= "db.properties"/> <!--global configuration parameters, when needed and then set to <settin Gs> <!--turn on global level two cache-<!--<setting name= "cacheenabled" value= "true"/>--< !--turn on global delay load-<setting name= "lazyloadingenabled" value= "true"/> <setting name= "Aggressivelazy Loading "value=" false "/> </settings> <typeAliases> <typealias type=" com. Mybaits.pojo.ctAniamlPojo "alias= "Ctaniaml"/> <typealias type= "com. Mybaits.pojo.animalPojo "alias= "Aniaml"/> <typealias type= "com. Mybaits.pojo.thirdExtendsPojo "alias= "Thirdextends"/> </typeAliases> <!--configuration data Source-<environmentsdefault= "Development" > <environment id= "Development" > <!--Configuration Transactions--<transactionma Nager type= "JDBC"/> <!--Configure connection pooling-<datasource type= "pooled" > <pro Perty name= "Driver" value= "${datasource.driverclass}"/> <property name= "url" value= "${datasource.jdb CURL} "/> <property name=" username "value=" ${datasource.user} "/> <property name = "Password" value= "${datasource.password}"/> </dataSource> </environment> </enviro nments> <!--map Sql.xml file--<mappers> <mapper resource= "Com/mybaits/mapper/ctaniamlmapper. xml "/> <mapper resource=" Com/mybaits/mapper/animalmapper.xml "/> </mappers></configuration&gt ;

SQL Statement Mapping Mapper:

<?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. Mybaits.mapper.animalmapperInteger > <!--nested query-<resultmap type= "Aniaml" id= "Selectanimalresultmap" &G        T <id column= "id" property= "id"/> <result column= "Animal" property= "Animal"/> <association Co Lumn= "species_id" property= "Ctaniaml"Javatype= "Ctaniaml"Select= "com. Mybaits.mapper.ctAnimalmapperInteger.SelectCtAnimalById "/> </resultMap> <select id=" Selectanimalbyid " parametertype= "int"Resultmap= "Selectanimalresultmap" >Select*from Animal where id=#{id}</select> <!--nesting results-<resultmap type= "Aniaml" id= "Aniamlresultmapnest" > <id column= "a n_id "property=" id "/> <result column=" Animal "property=" Animal "/> <!--<result column=" Spec ies_id "property=" Speciesid "/>-to <association column=" species_id "property=" Ctaniaml "Javatype= "Ctaniaml" > <id column= "id" property= "id"/> <result column= "species" property= "species "/> </association> </resultMap> <select id=" selectcontent "resultmap=" Aniamlresultmapnest " >SELECT a.id, A.species, b.id as an_id, B.animal from cttable a left JOIN Animal B on a.ID=b.species_id ORDER by a.ID</select> <!--extended result set-<resultmap type= "Thirdextends" id= "Selectanimalextendsresultmap" > <id column= "a_id" property= "extend_id"/> <result column= "a_animal" property= "Animal"/> <res Ult column= "b_species" property= "species"/> </resultMap> <select id= "Selectanimalbyidextends" pa rametertype= "int"Resultmap= "Selectanimalextendsresultmap" >SELECT a.id as a_id, a.animal as A_animal, b.species as b_species from animal a left JOIN Cttable B on a.species_id=b.id WHERE a.id=#{id}; </select></mapper>

Mybatis-config.xml and mapper Basic settings

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.