mybatis 配置_配置Mybatis在Spring Boot工程中的整合
配置Mybatis在Spring Boot工程中的整合包,设置mybatis的实体类别名,输出执行sql语句配置项。
分析:
添加启动器依赖;
配置Mybatis:实体类别名包,日志,映射文件等;
配置MapperScan
小结:
添加mybatis官方对于spring boot的一个启动器
org.mybatis.spring.bootmybatis-spring-boot-starter2.0.1
mysqlmysql-connector-java5.1.10
com.alibabadruid-spring-boot-starter1.1.18
com.github.pagehelperpagehelper-spring-boot-starter1.2.10
配置mybatis
mybatis: type-aliases-package: com.itheima.pojo mapper-locations: classpath:/mappers/*.xml
或者
mybatis.type-aliases-package=com.itheima.pojomybatis.mapper-locations=classpath:mappers/*.xml
分页配置
```yaml pagehelper: reasonable: true support-methods-arguments: true params: countSql helper-dialect: mysql
编写UserDao
package com.itheima.dao;
import com.itheima.pojo.User;import org.apache.ibatis.annotations.Mapper;
//@Mapper 或者在这里指定加载,但是不推荐public interface UserDao {
/** * 保存用户 * @param user * @return */ public int saveUser(User user);
}
设置启动器类中的添加Mapper的扫描
package com.itheima;
import com.itheima.core.JdbcProperties;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.context.properties.EnableConfigurationProperties;import org.springframework.context.annotation.ComponentScan;
// 代表的程序的入口
@SpringBootApplication// 注册属性配置类@EnableConfigurationProperties(value={JdbcProperties.class})// 扫描mybatis的dao@MapperScan("com.itheima.dao")public class SpringBootMainApplication {//applicationConext.xml
public static void main(String[] args){ SpringApplication.run(SpringBootMainApplication.class); }}
定义UserMapper.xml配置文件
<?xml version="1.0" encoding="UTF-8" ?>
insert into keke_user (username,password,account) values (#{username},#{password},"zhangsan")
编写测试用例:
package com.itheima;
import com.itheima.core.JdbcProperties;import com.itheima.dao.UserDao;import com.itheima.pojo.User;import com.itheima.service.IUserService;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 java.util.Date;
@RunWith(SpringRunner.class)@SpringBootTestpublic class SpringBootMainApplicationTests {
@Autowired private UserDao userDao;
@Test public void saveMybatisUser(){ User user = new User(); user.setUsername("zhang22222sanssss22222"); user.setPassword("12322224562227"); userDao.saveUser(user); }}
回复关键词
docker 分布式限流 MySQL alibaba JVM性能调优
看更多精彩教程
喜欢本文,记得点击个在看,或者分享给朋友哦!
mybatis 配置_配置Mybatis在Spring Boot工程中的整合相关推荐
- springboot tomcat配置_告诉你,Spring Boot 真是个牛逼货!
现在 Spring Boot 非常火,各种技术文章,各种付费教程,多如牛毛,可能还有些不知道 Spring Boot 的,那它到底是什么呢?有什么用?今天给大家详细介绍一下. Spring Boot ...
- druid jar包_使用druid实现Spring boot配置文件中数据库密码密文存储
通常在编写代码的时候,数据库的用户名和密码以明文的方法写到配置文件中,系统运维为了保证一定的安全性,要求我们在配置文件中使用密文的方式存储,本文主要介绍使用druid实现数据库密码密文显示的方法. 一 ...
- springboot 读取配置文件_使用 @ConfigurationProperties 在 Spring Boot 中加载配置
本文地址: 使用 @ConfigurationProperties 在 Spring Boot 中加载配置 使用 Spring Boot 加载配置文件的配置非常便利,我们只需要使用一些注解配置一下就能 ...
- spring boot 1.5.4 整合 mybatis(十二)
上一篇:spring boot 1.5.4 整合log4j2(十一) Spring Boot集成Mybatis 更多更详细的配置参考文件:application.properties和<Spri ...
- Spring Boot 应用中 Spring Session 的配置(1) : 自动配置 SessionAutoConfiguration
概述 本文基于以下组合的应用,通过源代码分析一下一个Spring Boot应用中Spring Session的配置过程: Spring Boot 2.1.3.RELEASE Spring Sessio ...
- security面试_精选41 道 Spring Boot 面试题,附答案!
今天跟大家分享下SpringBoot 常见面试题的知识. 1 什么是springboot ? 用来简化spring应用的初始搭建以及开发过程 使用特定的方式来进行配置(properties或yml文件 ...
- springboot导包显示不存在_基础篇:Spring Boot入门体验(图文教程)
优质文章,及时送达 什么是 Spring Boot? Spring Boot 是由 Pivotal 团队提供的全新框架.Spring Boot 是所有基于 Spring Framework 5.0 开 ...
- springboot中文文档_登顶 Github 的 Spring Boot 仓库!艿艿写的最肝系列
源码精品专栏 中文详细注释的开源项目 RPC 框架 Dubbo 源码解析 网络应用框架 Netty 源码解析 消息中间件 RocketMQ 源码解析 数据库中间件 Sharding-JDBC 和 My ...
- java restful接口开发实例_实战:基于Spring Boot快速开发RESTful风格API接口
写在前面的话 这篇文章计划是在过年期间完成的,示例代码都写好了,结果亲戚来我家做客,文章没来得及写.已经很久没有更新文章了,小伙伴们,有没有想我啊.言归正传,下面开始,今天的话题. 目标 写一套符合规 ...
最新文章
- 数字孪生等前沿技术,将如何解码未来交通?
- 怎么从0开始学python_如何从零开始学python
- Android基础(八) – Service AIDL
- producer send源码_Kafka源码深度剖析系列(七)——Producer核心流程初探
- 分析cocos2d-x中的CrystalCraze示例游戏
- Linux文件IO-例会笔记总结
- 多图长文 | 聊聊C端转型B端产品那些事
- phphstudy运行不了网站_网站SEO优化之如何维护网站权重?
- 大访问量网站缓存的一点思考,个人看法,勿拍砖
- List求交并补集--IEqualityComparer实现
- 【15】淘宝sdk——入门实战之header.php制作(三)
- java中的上传下载----ajaxFileUpload+struts2
- 小程序之跨平台黑魔法
- java实例分析宠物商店_Java实现宠物商店管理
- 使用poi把Java对象转换成excel
- 泰坦尼克号各种因素对存活率的影响
- CCNA-思科网络基础(IP地址 MAC地址 DNS DHCP PING )
- 【360补天计划】记第一次漏洞提交
- JavaScript面试问题
- ServU:无法访问servu服务器
热门文章
- VC中树状控件(TreeCtrl)的用法
- 转:VC++常用数据类型转换
- 转载:一步一步和我学Apache JMeter
- bzoj 2330 糖果
- ARM GIC-400 寄存器
- jQuery插件写法
- C#下载文件和将文件转换为数据流下载的示例
- SVN提示: File or directory '*' is out of date; try updating 解决方案
- 开源ERP PK 传统ERP_开源ERP商业模式及前景访谈(视频) 转
- 20210722-20211010当项目经理积累的管理经验_血泪史_项目管理经验001