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> ;
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