1.pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.23</version>
<!--<version>8.0.11</version>-->
</dependency>
<!--mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.2.0</version>
</dependency>
2.配置application.properties或者application.yml
jdbc.ds.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false
jdbc.ds.username=****
jdbc.ds.password=****
#mysql8以后驱动类有所不一样
jdbc.ds.driver-class-name=com.mysql.jdbc.Driver
#mybatis配置
mybatis.type-aliases-package=packeage.*.model
mybatis.mapper-locations=classpath:mapper/*.xml
3.加载数据库配置
@Configuration
@MapperScan(basePackages = "package.mapper*")
public class DataSourceConfiguration {
@Bean
@ConfigurationProperties(prefix = "jdbc.ds")
public DruidDataSource readDataSource(){
return new DruidDataSource();
}
}
4.mapper映射,Java类型映射mapper.xml
@Component(value = "testMapper ")
public interface TestMapper {
void Test(String test1, int test2);
}
<?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="package.FsApiMapper">
<insert id="Test">
<!--值得注意的是,mybatis在传参已经有所变化,旧版本的(#{0}变成了#{arg0})-->
insert into testTable(test1, test2) values(#{arg0}, #{arg1})
</insert>
</mapper>
5.调用
@Service
public class TestService {
@Autowired
private TestMapper testMapper;
public void Test() {
testMapper.Test("1234",1234);
}
}
6.总结
以上就是简易的配置过程,至于性能调优,特色功能等,可在application.properties中添加配置或是直接添加组件的实现类