mybatis-config.xml 和 mapper基本设置
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基本设置的更多相关文章
- Mybatis config.xml 配置
<!-- xml标准格式 --><?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ...
- mybatis入门篇:Mapper接口/关联查询/新增数据
1.数据准备 2.编写实体类 package com.forest.owl.entity; import java.util.Date; public class User { private Lon ...
- MyBatis(2):config.xml文件
前言 前一篇文章,讲了MyBatis入门,讲到了MyBatis有两个基本的配置文件,一个用来配置环境信息,一个用来写SQL语句.前者我把它命名为config.xml,config.xml的内容是: 1 ...
- MyBatis逆向工程生成配置 generator (生成pojo、mapper.xml、mapper.java)
MyBatis逆向工程生成 mybatis需要程序员自己编写sql语句,mybatis官方提供逆向工程,可以针对单表自动生成mybatis执行所需要的代码(mapper.java.mapper.xml ...
- mybatis.xml和mapper.xml的配置
mybatis.xml和mapper.xml的配置 1.创建一个Source Folder 2.完成分包mapper和mybatis 3.创建mybatis.xml文档 4xml文档名 5.名字规范 ...
- mybatis Mapper.xml和Mapper.java
mybatis Mapper.xml和Mapper.java 通过Mapper.xml和Mapper.java来实现mybatis.环境和入门的一样的.关键:Mapper.xml + Mapper.j ...
- MyBatis model、xml、mapper 自动生成,附源码
Mybatis 代码自动生成 model.xml.mapper 代码结构图 代码地址 https://github.com/shootercheng/codegen 需要修改的地方见 readme
- MyBatis2:config.xml文件
前言 前一篇文章,讲了MyBatis入门,讲到了MyBatis有两个基本的配置文件,一个用来配置环境信息,一个用来写SQL语句.前者我把它命名为config.xml,config.xml的内容是: & ...
- mybatis系列笔记(2)---mapper代理方法
mapper代理方法 在我们在写MVC设计的时候,都会写dao层和daoimp实现层,但假如我们使用mapper代理的方法,我们就可以不用先daoimp实现类 当然这得需要遵守一些相应的规则: (1) ...
随机推荐
- IPC之util.h源码解读
/* SPDX-License-Identifier: GPL-2.0 */ /* * linux/ipc/util.h * Copyright (C) 1999 Christoph Rohland ...
- zabbix 3.2.2 server端(源码包)安装部署 (一)
环境准备: 操作系统 CentOS 6.8 2.6.32-642.11.1.el6.x86_64 zabbix server 172.16.10.150 zabbix agent 172.16.10. ...
- 【icpc2019网络赛南昌站】Yukino With Subinterval
傻b错误调一天系列 原题: 大意:给你一个数列a,字词两种操作: 1.把c[l]改成r 2.询问在区间[l,r]中,有多少个极大子区间满足子区间里的数全部一样,且在[x,y]范围内 (对于满足条件的区 ...
- ajax 向php发送请求
<html> <head> <script src="clienthint.js"></script> </head> ...
- 如何使用Laravel Debugbar?
非常好用的Laravel debug工具,一定要安装 Chrome/FireFox 都会自带一些 debug 工具可以帮助我们 debug 前端,如 CSS.JavaScript… 等,但若要 deb ...
- css实现单行、多行文本超出显示省略号
前言:项目中我们经常遇到这种需求,需要对单行.多行文本超出显示为省略号.这篇文章主要总结了小编解决此问题的方法,有不足之处欢迎大家指正. 单行文本省略 .ellipsis-line { border: ...
- java程序连接Liunx服务器并且执行命令
JSch 介绍 JSch 是SSH2的一个纯Java实现.它允许你连接到一个sshd 服务器,使用端口转发,X11转发,文件传输等等.你可以将它的功能集成到你自己的 程序中.同时该项目也提供一个J2M ...
- Acwing-168-生日蛋糕(搜索, 剪枝)
链接: https://www.acwing.com/problem/content/170/ 题意: 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆 ...
- 【转】分布式文件系统FastDFS原理介绍
什么是FastDFS? FastDFS是一个开源的轻量级分布式文件系统.它解决了大数据量存储和负载均衡等问题.特别适合以中小文件(建议范围:4KB < file_size <500MB)为 ...
- HDU 6047 - Maximum Sequence | 2017 Multi-University Training Contest 2
/* HDU 6047 - Maximum Sequence [ 单调队列 ] 题意: 起初给出n个元素的数列 A[N], B[N] 对于 A[]的第N+K个元素,从B[N]中找出一个元素B[i],在 ...