一文总结之MyBatis
MyBatis
标签(空格分隔): 一文总结
目标
MyBatis动态代码生成
映射文件
与Spring集成
与SpringBoot集成
MyBatis演示
Configuration.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>
<settings>
<setting name="useGeneratedKeys" value="false"/>
<setting name="useColumnLabel" value="true"/>
</settings>
<typeAliases>
<typeAlias alias="UserAlias" type="org.apache.ibatis.submitted.complex_property.User"/>
</typeAliases> -
<environments default="development">
<environment id="development">
<transactionManager type="JDBC">
<property name="" value=""/>
</transactionManager>
<dataSource type="UNPOOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.0.0.1:3306/micro_message"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/imooc/config/sqlxml/Message.xml"/>
</mappers>
</configuration>
映射文件
<?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="org.zln.domain.Message">
<resultMap id="messageResult" type="message">
<id property="id" column="ID" jdbcType="INTEGER"/>
<result property="command" column="COMMAND" jdbcType="VARCHAR"/>
<result property="description" column="DESCRIPTION" jdbcType="VARCHAR"/>
<result property="content" column="CONTENT" jdbcType="VARCHAR"/>
</resultMap>
<select id="queryMessageList" resultMap="messageResult">
SELECT id,command,description,content FROM message
</select>
</mapper>
初始化配置文件
package com.imooc.db;
import java.io.IOException;
import java.io.Reader;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
/**
* 访问数据库类
*/
public class DBAccess {
public SqlSession getSqlSession() throws IOException {
// 通过配置文件获取数据库连接信息
Reader reader = Resources.getResourceAsReader("com/imooc/config/Configuration.xml");
// 通过配置信息构建一个SqlSessionFactory
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
// 通过sqlSessionFactory打开一个数据库会话
SqlSession sqlSession = sqlSessionFactory.openSession();
return sqlSession;
}
}
Dao
package org.zln.dao;
import org.springframework.stereotype.Repository;
import org.zln.domain.Message;
import java.util.List;
/**
* Created by sherry on 000006/7/6 19:16.
*/
@Repository
public class MessageDao extends BaseDao {
public List<Message> queryMessageList(String command,String description){
return sqlSessionTemplate.selectList("org.zln.domain.Message.queryMessageList");
}
}
Spring与MyBatis集成
pom
4.0.0
<groupId>org.zln.bms</groupId>
<artifactId>bms</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<spring.version>4.3.7.RELEASE</spring.version>
<slf4j-api.version>1.7.25</slf4j-api.version>
<log4j-slf4j-impl.version>2.8.1</log4j-slf4j-impl.version>
<log4j-core.version>2.8.1</log4j-core.version>
<commons-lang3.version>3.5</commons-lang3.version>
<h2.version>1.4.194</h2.version>
<mybatis.version>3.4.2</mybatis.version>
<mybatis-spring.version>1.3.1</mybatis-spring.version>
<jstl.version>1.2</jstl.version>
<servlet-api.version>4.0.0-b01</servlet-api.version>
<jackson-databind.version>2.8.7</jackson-databind.version>
<pagehelper.version>4.2.1</pagehelper.version>
<junit.version>4.12</junit.version>
<quartz.version>2.2.2</quartz.version>
<ehcache.version>2.10.3</ehcache.version>
<poi.version>3.16</poi.version>
<poi-contrib.version>3.1-FINAL</poi-contrib.version>
<commons-io.version>2.2</commons-io.version>
<mysql-connector-java.version>5.1.42</mysql-connector-java.version>
<lombok.version>1.16.16</lombok.version>
<druid.version>1.0.29</druid.version>
<mock.version>1.10.19</mock.version>
<aspect.version>1.8.10</aspect.version>
<thymeleaf.version>3.0.5.RELEASE</thymeleaf.version>
</properties>
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.7</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>${thymeleaf.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>${thymeleaf.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--神器-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<!--MySQL驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
</dependency>
<!--生产环境数据源-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<!--Spring-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspect.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspect.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<!--Excel操作-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>poi</groupId>
<artifactId>poi-contrib</artifactId>
<version>${poi-contrib.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<!--日志-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j-slf4j-impl.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j-core.version}</version>
</dependency>
<!--commons-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<!--h2嵌入式数据库-->
<!--开发环境数据源-->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
<!--MyBatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis-spring.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<!--jstl-->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<!--jackson-databind-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
</dependency>
<!--junit-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!--ehcache-->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.sql</include>
<include>**/*.html</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<!-- 配置插件 -->
<plugins>
<!-- 资源文件拷贝插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- java编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8080</port>
<path>/bms</path>
<!--<url>http://192.168.25.135:8080/manager/text</url>-->
<!--<username>tomcat</username>-->
<!--<password>tomcat</password>-->
</configuration>
</plugin>
</plugins>
</build>
Spring配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<!--MyBatis配置-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource"
p:configLocation="classpath:myBatisConf.xml"
p:mapperLocations="classpath:org/zln/**/*Mapper.xml"/>
<!--扫描Mapper类-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage="org.zln"/>
<!--sqlSessionTemplate-->
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"
c:sqlSessionFactory-ref="sqlSessionFactory" primary="true"/>
<bean id="sqlSessionTemplateBatch" class="org.mybatis.spring.SqlSessionTemplate"
c:_0-ref="sqlSessionFactory"
c:_1="BATCH"/>
<!--事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource"/>
<!--使用注解配置事务-->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
MyBatis配置文件
<?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>
<settings>
<!--配置日志框架-->
<setting name="logImpl" value="LOG4J2"/>
</settings>
<!--别名-->
<!--<typeAliases>-->
<!--</typeAliases>-->
<!-- 配置分页插件 -->
<plugins>
<!--正式执行SQL前,先执行实现了 interceptor 接口的类-->
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
</configuration>
其它
Mapper接口的生成与XML都可以使用代码生成工具生成
如果有需要修改,再在此基础上进行修改
如果需要执行批量操作,建议使用JDBC,用MyBatis有点麻烦
SpringBoot与MyBatis集成
POM
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.zln.spb</groupId>
<artifactId>spb02-web</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spb02-web</name>
<description>JavaWeb开发模板</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.4</thymeleaf-layout-dialect.version>
<lombok.version>1.16.16</lombok.version>
<commons-lang3.version>3.5</commons-lang3.version>
<h2.version>1.4.194</h2.version>
<mybatis.starter.version>1.3.0</mybatis.starter.version>
<pagehelper.version>4.2.1</pagehelper.version>
</properties>
<dependencies>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<!--starter pom-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.starter.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
数据准备
schema.sql
-- 测试用表
create table User (
id identity
,username varchar(100)
,password varchar(100)
);
test-data.sql
insert into User (username,password) values ('姓名1','pd1');
insert into User (username,password) values ('姓名2','pd2');
insert into User (username,password) values ('姓名3','pd3');
insert into User (username,password) values ('姓名4','pd4');
insert into User (username,password) values ('姓名5','pd5');
insert into User (username,password) values ('姓名6','pd6');
insert into User (username,password) values ('姓名7','pd7');
insert into User (username,password) values ('姓名8','pd8');
insert into User (username,password) values ('姓名9','pd9');
insert into User (username,password) values ('姓名10','pd10');
insert into User (username,password) values ('姓名11','pd11');
数据源配置
package org.zln.spb.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import javax.sql.DataSource;
/**
* 数据库相关配置
* Created by nbcoolkid on 2017-06-26.
*/
@Configuration
public class DbConfig {
/**
* H2嵌入式数据库,用于开发
* @return
*/
@Bean(destroyMethod = "shutdown")
@Primary
@Profile("dev")
public DataSource dataSourceH2(){
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScript("classpath:sql/schema.sql")
.addScript("classpath:sql/test-data.sql")
.setScriptEncoding("UTF-8")
.build();
}
}
Dao
UserMapper
package org.zln.spb.dao.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.zln.spb.pojo.vo.User;
/**
* Created by nbcoolkid on 2017-06-26.
*/
@Mapper
public interface UserMapper {
User selectByPrimaryKey(int id);
}
UserMapper.xml
<?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="org.zln.spb.dao.mapper.UserMapper">
<select id="selectByPrimaryKey" parameterType="int" resultType="org.zln.spb.pojo.vo.User">
SELECT id,username,password FROM User where id = #{_parameter}
</select>
</mapper>
测试
package org.zln.spb.dao.mapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.*;
/**
* Created by nbcoolkid on 2017-06-26.
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class UserMapperTest {
@Autowired
private UserMapper userMapper;
@Test
public void selectByPrimaryKey() throws Exception {
System.out.println("UserMapper:"+userMapper);
System.out.println(userMapper.selectByPrimaryKey(1));
}
}
MyBatis配置文件详解
Mybatis映射文件详解
动态SQL元素
if
<if test="roleName!=null and rowName!=''">
and role_name like concat('%',#{roleName},'%')
</if>
choose、when、otherwise
<choose>
<when test="roleNo!=null">
and role_no=#{roleNo}
</when>
<when test="roleName!=null">
and role_name like concat('%',#{roleName},'%')
</when>
<otherwise>
and note is not null
</otherwise>
</choose>
where、trim、set
where
<where>
<if test="roleName!=null and rowName!=''">
and role_name like concat('%',#{roleName},'%')
</if>
</where>
当条件满足的时候,才会拼接where
关键字
而且前缀and
会自动去掉
trim
<trim prefix="where" prefixOverrides="and">
<if test="roleName!=null and rowName!=''">
and role_name like concat('%',#{roleName},'%')
</if>
</trim>
prefix
表示语句的前缀
prefixOverrides
表示需要去掉的第一个字符串,如果有多种,可以这样子prefixOverrides="and|or"
set
用于执行更新语句
update t_tole
<set>
<if test="roleName!=null">
tole_name=#{roleName},
</if>
where role_no=#{roleNo}
</set>
使用trim改写
update t_tole
<trim prefix="set" suffixOverrides=",">
<if test="roleName!=null">
tole_name=#{roleName},
</if>
where role_no=#{roleNo}
</set>
suffixOverrides
表示需要去掉的最后一个字符串
foreach
<select id="getStudentListByClassIDs" resultMap="studentResultMap">
SELECT * FROM STUDENT_TBL ST
WHERE ST.CLASS_ID IN
<foreach collection="list" item="classList" open="(" separator="," close=")">
#{classList}
</foreach>
</select>
bind与模糊查询
bind
一般用于模糊查询的字符串连接
MySQL
中使用concat
Oracle
中使用||
<select id="" resultType="">
<bind name="pattern" value="'%'+_parameter+'%'"/>
select * from tt where role_name like #{pattern}
</select>
如果传递过来的参数有多个,
则编写多个bind
标签即可
MyBatis中使用OGNL表达式
在MyBatis中,通过使用OGNL表达式,从传递的参数中获取数据,组装SQL
String与基本数据类型 _parameter
自定义类型(对象) 属性名
集合
数组 array
List list
Map _parameter
获取集合中的一条数据
数组 array[索引] 基本数据类型数组
array[索引].属性名 对象数据类型数组
List list[索引]
list[索引].属性名
Map _parameter.key
_parameter.key.属性名
利用foreach标签从集合中取出数据(遍历拼接SQL)
如果collection中的数组或List,i表示下标,如果collection是Map,i表示key。item(或item.属性名)表示迭代出来的值
separator 表示 迭代出来的元素之间的分隔符
举例
<delete id="deleteBatch" parameterType="java.util.List">
delete from MESSAGE where ID in(
<foreach collection="list" item="item" separator=",">
#{item}
</foreach>
)
</delete>
一文总结之MyBatis的更多相关文章
- SpringBoot+rest接口+swagger2生成API文档+validator+mybatis+aop+国际化
代码地址:JillWen_SpringBootDemo mybatis 1. 添加依赖: <dependency> <groupId>org.mybatis.spring.bo ...
- 一文搞定 Mybatis 的应用
Mybatis 介绍 Mybatis 是一个开源的持久层框架,原来叫 ibatis ,它对 jdbc 操作数据库的过程进行了封装,使开发者只需要关注 SQL 本身,而不需要花费精力去处理例如注册驱动. ...
- 一文彻底吃透MyBatis源码!!
写在前面 随着互联网的发展,越来越多的公司摒弃了Hibernate,而选择拥抱了MyBatis.而且,很多大厂在面试的时候喜欢问MyBatis底层的原理和源码实现.总之,MyBatis几乎成为了Jav ...
- MyBatis Generator 详解
MyBatis Generator中文文档 MyBatis Generator中文文档地址:http://mbg.cndocs.tk/ 该中文文档由于尽可能和原文内容一致,所以有些地方如果不熟悉,看中 ...
- MyBatis Generator 详解 【转来纯为备忘】
版权声明:版权归博主所有,转载请带上本文链接!联系方式:abel533@gmail.com 目录(?)[+] MyBatis Generator中文文档 运行MyBatis Generator X ...
- mybatis 使用记录
首先,贴一个好文.把mybatis中的<if></if>的条件扒到源码分析了一遍.PS:目前还看不懂... http://cheng-xinwei.iteye.com/blog ...
- 转载:mybatis自动生成
MyBatis Generator中文文档 MyBatis Generator中文文档地址: http://generator.sturgeon.mopaas.com/ 该中文文档由于尽可能和原文内容 ...
- MyBatis 实践 -配置
MyBatis 实践 标签: Java与存储 Configuration mybatis-configuration.xml是MyBatis的全局配置文件(文件名任意),其配置内容和顺序如下: pro ...
- MyBatis 实践 -Mapper与DAO
MyBatis 实践 标签: Java与存储 MyBatis简介 MyBatis前身是iBatis,是一个基于Java的数据持久层/对象关系映射(ORM)框架. MyBatis是对JDBC的封装,使开 ...
随机推荐
- 用CSS中的Alpha实现渐变
效果一:<div id="Layer1" style="position:absolute; left:161px; top:160px; width:2 ...
- 【总结】详细说说Html.ActionLink的用法
Html.ActionLink概述 在MVC的Rasor视图引擎中,微软采用一种全新的方式来表示从前的超链接方式,它代替了从前的繁杂的超链接标签,让代码看起来更加简洁,通过浏览器依然会解析成传统的a标 ...
- Html.RenderPartial与Html.RenderAction的区别
Html.RenderPartial与Html.RenderAction这两个方法都是用来在界面上嵌入用户控件的. Html.RenderPartial是直接将用户控件嵌入到界面上: <%Htm ...
- ci框架学习整理
-- -- 表的结构 `yi_article` -- CREATE TABLE IF NOT EXISTS `yi_article` ( `id` int(11) unsigned NOT NULL ...
- WebGL——osg框架学习三
今天继续来Draw绘制的osg模块的学习,昨天我们学习的是StateBin渲染状态树节点类,今天我们来继续学习下一个Draw的基础类DrawableEntity渲染对象实体类.这个类和Drawable ...
- c语言数字图像处理(八):噪声模型及均值滤波器
图像退化/复原过程模型 高斯噪声 PDF(概率密度函数) 生成高斯随机数序列 算法可参考<http://www.doc.ic.ac.uk/~wl/papers/07/csur07dt.pdf&g ...
- 【Python学习笔记】正则表达式
Ref:https://deerchao.net/tutorials/regex/regex.htm#greedyandlazy 1. 常用元字符 2.字符转义 查找元字符本身时,需要使用\来取消这些 ...
- 前端常见算法面试题之 - 从尾到头打印链表[JavaScript解法]
题目描述 输入一个链表的头结点,从尾到头反过来打印出每个结点的值 实现思路 前端工程师看到这个题目,直接想到的就是,写个while循环来遍历链表,在循环中把节点的值存储在数组中,最后在把数组倒序后,遍 ...
- Controller组件- 集合点的功能-loadrunner
1.添加集合点功能的做法 ,注意在开始事务前加,不然就会把等待时间也加进去. 2.Controller 中也要开启集合点的功能,才能使用
- 010 --MySQL查询优化器的局限性
MySQL的万能"嵌套循环"并不是对每种查询都是最优的.不过还好,mysql查询优化器只对少部分查询不适用,而且我们往往可以通过改写查询让mysql高效的完成工作.在这我们先来看看 ...