目录
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-webartifactId>
- dependency>
- <dependency>
- <groupId>org.mybatis.spring.bootgroupId>
- <artifactId>mybatis-spring-boot-starterartifactId>
- <version>2.2.1version>
- dependency>
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- <scope>runtimescope>
- dependency>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-testartifactId>
- <scope>testscope>
- dependency>
-
- @Mapper
- public interface UserMapper {
- List
findall(); - }
- "1.0" encoding="UTF-8"?>
- mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.gq.springnootdemo.mapper.UserMapper">
- <select id="findall" resultType="com.gq.springnootdemo.pojo.Users">
- select *from user;
- select>
-
- mapper>
# 数据源 spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql:///mybatis?serverTimezone=UTC username: root password: root # mybatis配置 mybatis: # 映射文件位置 mapper-locations: com/gq/springnootdemo/mapper/*Mapper.xml # 别名 type-aliases-package: com.gq.springnootdemo.pojo #日志格式 logging: pattern: console: '%d{HH:mm:ss.SSS} %clr(%-5level) --- [%-15thread] %cyan(%-50logger{50}):%msg%n'
- @SpringBootTest
- class SpringnootdemoApplicationTests {
-
- @Autowired
- private UserMapper userMapper;
- @Test
- void contextLoads() {
- List
users=userMapper.findall(); - users.forEach(System.out::println);
- }
-
- }
总体架构图: