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) ...
随机推荐
- 静态static最基础的知识
static静态: 常见修饰的内容: 1.变量: 修饰变量时,叫静态变量或类变量.此变量为类所有随着虚拟机加载类是而加载入方法区,此静态变量为该类所有对象共享,在内存中只有一个副本,它 当且仅当 类的 ...
- 【网络协议】动态主机配置协议DHCP
动态主机配置协议DHCP 当某组织获得一块地址后,就可以为本组织内的主机或者路由器分配IP地址.这个分配工作可以由系统管理员手动通过网络管理工具来完成.也可以由动态主机配置协议(Dynamic Hos ...
- Linux配置JDK环境
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-co ...
- Scala(一)——基本类型
Scala语言快速入门(基本类型) (参考视频:av39126512,韩顺平281集scala精讲) 一.Linux和Windows环境安装 这部分跳过,直接使用IDEA进行搭建,和其他编程语言配置差 ...
- Oracle修改表,提示“资源正忙,要求指定NOWAIT”
今天往一个表里面多增加了两个字段,修改完毕,保存的时候,提示如下内容:“资源正忙,要求指定nowait”.重试好几遍,都没有解决,于是搜索了一下,找到了解决方法,如下: 首先执行下面一段代码,得到锁定 ...
- 5 LAMP配置管理:模块(state、file、pkg、service)、jinja模板、job管理、redis主从
1. 配置管理:state和file https://docs.saltstack.com/en/latest/topics/states/index.html Full list of states ...
- expect无交互操作
#!/usr/bin/expect set ip '192.168.4.5' set ' set timeout spawn ssh root@$ip expect { "yes/no&qu ...
- springboot错误1 Failed to execute goal org.springframework.boot:spring-boot-maven-plugin
关于Springboot打包错误的问题 | Failed to execute goal org.springframework.boot:spring-boot-maven-plugin https ...
- Linux系统启动顺序
Linux启动顺序 加电—加电自检(BIOS)—硬件检查 —MBR(找到需要启动的系统,由于实际计算机上可能会装有多个系统) —bootloader系统初始化,装载kenel到内存 —内核执行,决定哪 ...
- 最近公共祖先LCA(Tarjan算法)的思考和算法实现——转载自Vendetta Blogs
LCA 最近公共祖先 Tarjan(离线)算法的基本思路及其算法实现 小广告:METO CODE 安溪一中信息学在线评测系统(OJ) //由于这是第一篇博客..有点瑕疵...比如我把false写成了f ...