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> <!-- 读取db.properties文件 -->
<properties resource="db.properties" />
<!-- 全局配置参数,需要时再设置 -->
<settings>
<!-- 开启全局二级缓存 -->
<!-- <setting name="cacheEnabled" value="true" /> -->
<!-- 开启全局延迟加载 -->
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="aggressiveLazyLoading" 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> <!-- 配置数据源 -->
<environments default="development">
<environment id="development">
<!-- 配置事务 -->
<transactionManager type="JDBC" />
<!-- 配置连接池 -->
<dataSource type="POOLED">
<property name="driver" value="${dataSource.driverClass}" />
<property name="url" value="${dataSource.jdbcUrl}" />
<property name="username" value="${dataSource.user}" />
<property name="password" value="${dataSource.password}" />
</dataSource>
</environment>
</environments>
<!-- 映射Sql.xml文件 -->
<mappers>
<mapper resource="com/Mybaits/mapper/ctAniamlMapper.xml" />
<mapper resource="com/Mybaits/mapper/animalMapper.xml" />
</mappers>
</configuration>

SQL语句映射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">
<!-- 嵌套查询 -->
<resultMap type="Aniaml" id="SelectAnimalResultMap">
<id column="id" property="id" />
<result column="animal" property="animal" />
<association column="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> <!-- 嵌套结果 -->
<resultMap type="Aniaml" id="AniamlResultMapNest">
<id column="an_id" property="id" />
<result column="animal" property="animal" />
<!-- <result column="Species_id" property="speciesid" /> -->
<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> <!-- 扩展结果集 -->
<resultMap type="ThirdExtends" id="SelectAnimalExtendsResultMap">
<id column="a_id" property="Extend_id" />
<result column="a_animal" property="animal" />
<result column="b_species" property="species" /> </resultMap>
<select id="SelectAnimalByIdExtends" parameterType="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 和 mapper基本设置的更多相关文章

  1. Mybatis config.xml 配置

    <!-- xml标准格式 --><?xml version="1.0" encoding="UTF-8"?>  <!DOCTYPE ...

  2. mybatis入门篇:Mapper接口/关联查询/新增数据

    1.数据准备 2.编写实体类 package com.forest.owl.entity; import java.util.Date; public class User { private Lon ...

  3. MyBatis(2):config.xml文件

    前言 前一篇文章,讲了MyBatis入门,讲到了MyBatis有两个基本的配置文件,一个用来配置环境信息,一个用来写SQL语句.前者我把它命名为config.xml,config.xml的内容是: 1 ...

  4. MyBatis逆向工程生成配置 generator (生成pojo、mapper.xml、mapper.java)

    MyBatis逆向工程生成 mybatis需要程序员自己编写sql语句,mybatis官方提供逆向工程,可以针对单表自动生成mybatis执行所需要的代码(mapper.java.mapper.xml ...

  5. mybatis.xml和mapper.xml的配置

    mybatis.xml和mapper.xml的配置 1.创建一个Source Folder 2.完成分包mapper和mybatis 3.创建mybatis.xml文档 4xml文档名 5.名字规范 ...

  6. mybatis Mapper.xml和Mapper.java

    mybatis Mapper.xml和Mapper.java 通过Mapper.xml和Mapper.java来实现mybatis.环境和入门的一样的.关键:Mapper.xml + Mapper.j ...

  7. MyBatis model、xml、mapper 自动生成,附源码

    Mybatis 代码自动生成 model.xml.mapper 代码结构图 代码地址 https://github.com/shootercheng/codegen 需要修改的地方见 readme

  8. MyBatis2:config.xml文件

    前言 前一篇文章,讲了MyBatis入门,讲到了MyBatis有两个基本的配置文件,一个用来配置环境信息,一个用来写SQL语句.前者我把它命名为config.xml,config.xml的内容是: & ...

  9. mybatis系列笔记(2)---mapper代理方法

    mapper代理方法 在我们在写MVC设计的时候,都会写dao层和daoimp实现层,但假如我们使用mapper代理的方法,我们就可以不用先daoimp实现类 当然这得需要遵守一些相应的规则: (1) ...

随机推荐

  1. main特别之处

    //package new_Object; public class Main{ public static void main(String[] args) { System.out.println ...

  2. 解决xshell连接不上阿里云服务器问题

    最近购买了阿里云服务器准备玩玩,但是使用xshell连接阿里云服务器时,系统一直提示“Connection established. To escape to local shell, press ' ...

  3. deep_learning_Softmax()

    该节课中提到了一种叫作softmax的函数,因为之前对这个概念不了解,所以本篇就这个函数进行整理,如下: 维基给出的解释:softmax函数,也称指数归一化函数,它是一种logistic函数的归一化形 ...

  4. 使用HTML5 -Canvas追踪用户,Chrome隐身模式阵亡

    中国的一些精准营销公司又要偷着乐了= =从之前追踪Cookie到后面追踪FlashCookie,某些商家总在永无止境的追踪用户行为甚至是隐私,将其转化为所谓的“商业价值”.我们被迫面临“世风日下.道德 ...

  5. [CEOI1999]Sightseeing trip(Floyed)

    [CEOI1999]Sightseeing trip Description There is a travel agency in Adelton town on Zanzibar island. ...

  6. javascript代码实用方法实现

    javascript代码实用方法实现   针对现在大家平时开发中,都会写一些重复性的js处理代码,今天总结了几个比较常用的方法实现.获取get请求参数.去字符串空格.   1.获取get请求中的参数  ...

  7. MyBatis笔记-03-CRUD

    3.CRUD 1.namespace namespace中的包名要和Dao/mapper接口的包名保持一致 2.select 选择查询语句: id:就是对应的namespace中的方法名: resul ...

  8. 小程序生成海报 canvas

    前言 微信小程序需要生成海报进行朋友圈分享,但是不同的手机会有问题, 然后首先是图片的问题 图片 在模拟器上没有报错,可是真机测试却什么也没画出来. canvas.drawImage 是不支持网络图片 ...

  9. hdu 6065 RXD, tree and sequence

    题 OwO http://acm.hdu.edu.cn/showproblem.php?pid=6065 (2017 Multi-University Training Contest - Team ...

  10. Spring Security 解决X-Frame-Options deny

    错误信息: Refused to display 'https://github.com/hwclass/awesome-sound' in a frame because it set 'X-Fra ...