7-Spring Boot ( 整合使用mybatis )
2018-02-25 14:43
726 查看
1.pom文件引入
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
2.配置文件引入
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
3.Mapper代码
public interface UserMapper {
@Select("SELECT * FROM USERS WHERE NAME = #{name}")
User findByName(@Param("name") String name);
@Insert("INSERT INTO USERS(NAME, AGE) VALUES(#{name}, #{age})")
int insert(@Param("name") String name, @Param("age") Integer age);
}
4.启动方式
@ComponentScan(basePackages = "com.itmayiedu")
@MapperScan(basePackages = "com.itmayiedu.mapper")
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
相关文章推荐
- spring boot整合mybatis使用c3p0数据源连接mysql
- springboot使用之二:整合mybatis(xml方式)并添加PageHelper插件
- springboot整合mybatis使用阿里(阿里连接池)和xml方式
- thymeleaf :springboot整合mybatis的web项目中使用html而不是jsp当页面渲染
- spring boot整合mybatis使用c3p0数据源连接mysql
- Spring-Boot整合mybatis(一),使用默认的数据库连接池
- spring-boot整合mybatis(使用Fiddler抓包工具进行测试)
- Spring Boot 整合mybatis 使用多数据源的实现方法
- spring boot(四):springboot整合使用mybatis
- spring Boot 整合mybatis 如何使用多数据源
- (十一)Spring Boot整合Mybatis使用druid实现多数据源自动切换
- 在idea里使用SpringBoot整合MyBatis时遇到的Mapper扫描不到的问题
- Spring-Boot整合mybatis(二),使用阿里的druid包,进行监控SQL执行速度
- SpringBoot学习:整合MyBatis,使用Druid连接池
- 8-Spring Boot ( 整合使用mybatis )
- SpringBoot整合Mybatis时使用Druid数据库连接池
- Spring Boot整合使用mybatis
- 关于spring boot整合mybatis使用oracle数据库出现could not load:oracle.jdbc.driver.OracleDriver问题的终极解决方案