SpringBoot入门-集成mybatis(四)
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.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>
</properties> <dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency> <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency> <!-- 阿里巴巴连接池Druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.5</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
application.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&serverTimezone=GMT%2B8 jpa:
hibernate:
ddl-auto: update
show-sql: true mybatis:
# mapper.xml文件中resultMap的type或者parameterType会使用自定义的pojo
type-aliases-package: com.vast.entity
mapper-locations: classpath:mapper/*.xml
config-location: classpath:mapper/mybatis-config.xml
configuration:
cache-enabled: true # mybatis核心配置文件中settings中配置,指定 MyBatis 应如何自动映射列到字段或属性。 NONE 表示取消自动映射;PARTIAL 只会自动映射没有定义嵌套结果集映射的结果集。 FULL 会自动映射任意复杂的结果集(无论是否嵌套)。默认是partial,这是一种全局设置
auto-mapping-behavior: FULL
# executor-type值为SIMPLE、REUSE,可通过insert、update、delete方法的返回值判断sql是否执行成功,返回非0表示执行sql成功的条数,返回0表示sql执行失败
# executor-type值为BATCH,insert、update、delete方法返回值一直会是负数-2147482646,在该模式下insert、update、delete返回值将无任何意义,不能作为判断sql执行成功的判断依据
default-executor-type: REUSE
map-underscore-to-camel-case: true
lazy-loading-enabled: true
# 会依层次分别延迟加载,但是不管POJO这个属性是否被调用都会加载进来
aggressive-lazy-loading: false
# 将log集成到控制台
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#指定某个包发生日志操作就在后台打印,不设置无法打印预编译SQL
logging:
level:
com:
vast: debug
mybatis-config.xml (打印预编译SQL语句)
<?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>
<!-- 打印SQL语句到控制台 -->
<setting name="logImpl" value="STDOUT_LOGGING" />
</settings>
<typeAliases> </typeAliases>
</configuration>
Dao
package com.vast.dao; import com.vast.entity.Account;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository; import java.util.List; @Mapper
@Repository
public interface IAccountMybatisDao { public int saveAccount(Account account); public List<Account> queryAccountInfoById(Integer id);
}
资源文件夹下建立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="com.vast.dao.IAccountMybatisDao"> <insert id="saveAccount" parameterType="account">
insert into account(id, name, money)
values (#{id}, #{name}, #{money})
</insert> <select id="queryAccountInfoById" resultType="account">
select * from Account
</select> </mapper>
Dao注入被调用类
@Autowired
private IAccountMybatisDao accountMybatisDao;
SpringBoot入门-集成mybatis(四)的更多相关文章
- 在springboot中集成mybatis开发
在springboot中利用mybatis框架进行开发需要集成mybatis才能进行开发,那么如何在springboot中集成mybatis呢?按照以下几个步骤就可以实现springboot集成myb ...
- springboot之集成mybatis mongo shiro druid redis jsp
闲来无事,研究一下spingboot 发现好多地方都不一样了,第一个就是官方默认不支持jsp 于是开始狂找资料 终于让我找到了 首先引入依赖如下: <!-- tomcat的支持.--> ...
- springboot入门系列(四):SpringBoot和Mybatis配置多数据源连接多个数据库
SpringBoot和Mybatis配置多数据源连接多个数据库 目前业界操作数据库的框架一般是 Mybatis,但在很多业务场景下,我们需要在一个工程里配置多个数据源来实现业务逻辑.在SpringBo ...
- springboot如何集成mybatis的pagehelper分页插件
mybatis提供了一个非常好用的分页插件,之前集成的时候需要配置mybatis-config.xml的方式,今天我们来看下它是如何集成springboot来更好的服务的. 只能说springboot ...
- SpringBoot系列: 集成MyBatis
本文主要修改自下面博客:http://www.ityouknow.com/springboot/2016/11/06/spring-boo-mybatis.htmlhttp://tengj.top/2 ...
- Spring Boot入门——集成Mybatis
步骤: 1.新建maven项目 2.在pom.xml文件中引入相关依赖 <!-- mysql依赖 --> <dependency> <groupId>mysql&l ...
- (二十一)SpringBoot之集成mybatis:使用mybatis xml
一.引入maven依赖 <dependencies> <dependency> <groupId>org.springframework.boot</grou ...
- (二十)SpringBoot之集成mybatis:使用mybatis注解
一.使用mybatis注解的集成 1.1 引入maven依赖 <dependencies> <dependency> <groupId>org.springfram ...
- SpringBoot之集成MyBatis
引入工程依赖包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
随机推荐
- zabbix--CPU监控并告警
zabbix监控CPU超值则报警 由于默认没有 cpu 的使用率监控,需要添加一个监控项,通过 system.cpu.util[,,] 来进行配置 添加监控项 添加图形 添加触发器 展示图
- SqlServer中的更新锁(UPDLOCK和READPAST)
UPDLOCK和READPAST,通过UPDLOCK和READPAST的结合我们能够解决许多问题,比如我当前项目中对于更新预约人数,则用到了UPDLOCK和READPAST,因为考虑到并发如果固定预约 ...
- Linux GCC下strstr的实现以及一个简单的Kmp算法的接口
今天做了一道题,要用判断一个字符串是否是另一个字符串的子串,于是查了一下strstr的实现. 代码如下: char *strstr(const char*s1,const char*s2) { con ...
- Kotlin匿名函数与闭包详解
Lambda表达式实例演练: 继续先来编写一些Lambda表达式相关的代码: 接下来想从上面的字符串数组中找到带有"h"的字符串并打印出来: 如果学习了Java8的Lambda表达 ...
- Educational Codeforces Round 68 E. Count The Rectangles
Educational Codeforces Round 68 E. Count The Rectangles 传送门 题意: 给出不超过\(n,n\leq 5000\)条直线,问共形成多少个矩形. ...
- AI人工智能-Python实现前后端人机聊天对话
[前言] AI 在人工智能进展的如火如荼的今天,我们如果不尝试去接触新鲜事物,马上就要被世界淘汰啦~ 本文拟使用Python开发语言实现类似于WIndows平台的“小娜”,或者是IOS下的“Siri” ...
- pycharm连不上数据库:报警代码Connection to api@localhost failed. [08001] Could not create connection to d
pycharm 换成2019之后连接数据库用户名密码数据库名字都没错,就是连接不上去,网上百度一下,试试将URL后面拼接 ?useSSL=false&serverTimezone=UTC 发现 ...
- php怎么识别真实ip
PHP 里用来获取客户端 IP 的变量有这些: $_SERVER['HTTP_CLIENT_IP'] 这个头是有的,但是很少,不一定服务器都实现了.客户端可以伪造.(推荐学习:PHP编程从入门到精通) ...
- Java Excel 导入导出(二)
本文主要叙述定制导入模板——利用XML解析技术,确定模板样式. 1.确定模板列 2.定义标题(合并单元格) 3.定义列名 4.定义数据区域单元格样式 引入jar包: 一.预期格式类型 二.XML模板格 ...
- hdu1010-Tempter of the Bone-(dfs+奇偶剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 翻译:有只狗被困了,S是起点,D是门,W是墙不能走,‘ . ’是可以走的路,走一次就会在1秒内坍塌,也就是 ...