MyBatis-Spring-Boot 使用总结
首先,MyBatis-Spring-Boot-Starter will:
- Autodetect an existing DataSource.
- Will create and register an instance of a SqlSessionFactoryBean passing that DataSource as an input.
- Will create and register an instance of a SqlSessionTemplate got out of the SqlSessionFactoryBean.
- Autoscan your mappers, link them to the SqlSessionTemplate and register them to Spring context so they can be injected into your beans.
Property | Description |
---|---|
config-location | MyBatis xml config file (optional) |
mapper-locations | Mapper xml config files (optional) |
type-aliases-package | Package to search for type aliases (optional) |
type-handlers-package | Package to search for type aliases (optional) |
executor-type | Executor type: SIMPLE, REUSE, BATCH (optional) |
configuration | A MyBatis Configuration bean. About available properties see the MyBatis reference page. NOTE This property cannot use at the same time with the config-location. |
#application.properties
mybatis.config-location=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>
<typeAliases>
<package name="sample.mybatis.domain"/>
</typeAliases>
<mappers>
<mapper resource="sample/mybatis/mapper/CityMapper.xml"/>
<mapper resource="sample/mybatis/mapper/HotelMapper.xml"/>
</mappers>
</configuration>
#application.properties
mybatis.type-aliases-package=com.expert.pojo
package com.expert.dao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import com.expert.pojo.User;
@Mapper
public interface UserMapper {
// @Select("SELECT * FROM user WHERE id = #{ id }")
User getById(String id); @Select("SELECT * FROM user WHERE id = #{ id }")
User getById2(String id);
}
MyBatis-Spring-Boot 使用总结的更多相关文章
- mybatis+spring boot, mapper 提示Could not autowire. No beans of … type found
工具及背景: IntelliJ IDEA 2016.1.3 Ultimate.spring boot, maven项目,利用mybatis 注解的方式查询mysql. 业务逻辑关系:controlle ...
- spring boot:配置shardingsphere(sharding jdbc)使用druid数据源(druid 1.1.23 / sharding-jdbc 4.1.1 / mybatis / spring boot 2.3.3)
一,为什么要使用druid数据源? 1,druid的优点 Druid是阿里巴巴开发的号称为监控而生的数据库连接池 它的优点包括: 可以监控数据库访问性能 SQL执行日志 SQL防火墙 但spring ...
- spring boot:使用分布式事务seata(druid 1.1.23 / seata 1.3.0 / mybatis / spring boot 2.3.2)
一,什么是seata? Seata:Simpe Extensible Autonomous Transcaction Architecture, 是阿里中间件开源的分布式事务解决方案. 前身是阿里的F ...
- mybatis spring boot深入
[size=large]头一篇博文说了整合了spring boot和mybatis大家都可以对后台数据进行操作但是如何才能进行高效的操作数据库节省代码,下面来一起谈论哈mybatis的通用mapper ...
- Parameter 0 of method sqlSessionTemplate in org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration required a single bean, but 2 were found:
Parameter 0 of method orderSqlSessionFactory in com.config.MultipleDBConfig required a single bean, ...
- mybatis+spring boot+vue
参考https://www.cnblogs.com/wlovet/p/8317282.html
- spring boot(六):如何优雅的使用mybatis
*:first-child{margin-top: 0 !important}.markdown-body>*:last-child{margin-bottom: 0 !important}.m ...
- 超简单,spring boot 添加mybatis
看了很多人写的博客,要么太复杂,要么没有添加xml的方式,自己亲自配置了一下,供各位参考. 项目截图 1.添加pom文件 <!-- 设置mybatis --> <dependency ...
- Spring Boot 4 MyBatis
SpringBoot内使用MyBatis,可以不使用xml映射配置,通过注解方式映射. pom.xml添加依赖 <dependency> <groupId>org.mybati ...
- Spring Boot MyBatis 连接数据库
最近比较忙,没来得及抽时间把MyBatis的集成发出来,其实mybatis官网在2015年11月底就已经发布了对SpringBoot集成的Release版本,Github上有代码:https://gi ...
随机推荐
- 利用Lucene把文本的字体格式进行改动,然后输出到一个新的文件里
这里书中写的是charactorProcess(File file, String destFile) 这里被我改成.(String file, String destFIle) 一个代表现有的文件 ...
- MSS & MTU
- Appium(JAVA)Windows 7系统搭建及示例运行
Appium(JAVA)Windows 7系统搭建及示例运行 分类: Appium 2014-11-14 17:44 4323人阅读 评论(2) 收藏 举报 1.搭建Android环境 http:// ...
- 点滴的积累---初学Javascript
在学习知识的路上,我们须要的不断的去接触新的知识,同一时候我们也不要不停地对自己旧的知识进行总结.近期通过<牛腩Javascript>和姜昊的<Javascript专题视频>对 ...
- 【LeetCode】105. Construct Binary Tree from Preorder and Inorder Traversal
Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a ...
- 在ASP.Net和IIS中删除不必要的HTTP响应头[转]
http://www.cnblogs.com/CareySon/archive/2009/12/14/1623624.html 引入 每次当浏览器向Web服务器发起一个请求的时,都会伴随着一些HTTP ...
- 树莓派/RaspberryPi 内核源码下载
树莓派的源码有两种下载方式:压缩包下载和git clone指令下载. 1.压缩包下载 选择对应分支,点击Github界面的 下载按钮即可,如下图: 测试发现,同样的分支,用压缩包方式下载后编译会出错, ...
- const与#define、结构体对齐、函数重载name mangling、new/delete 等
一.bool 类型 逻辑型也称布尔型,其取值为true(逻辑真)和false(逻辑假),存储字节数在不同编译系统中可能有所不同,VC++中为1个字节. 声明方式:bool result; result ...
- 用string存取二进制数据
STL的string很强大,用起来也感觉很舒服,这段时间在代码中涉及到了用string存取二进制数据的问题,这里记录一下,以供以后参考. 首先提一下STL中string的参考资料:http://www ...
- java递归算法实现拼装树形JSON数据
有时候页面需要使用jQuery easy ui中的combotree,需要给combotree提供一个JSON数据,使用如下方法(递归)实现(下面是dao层的实现层): /** * 根据表名和父id拼 ...