目录
Mybatis-Plus官方推荐在SpringBoot工程中使用,Spring过程自然也是可以用的,这里我只介绍SpringBoot的使用
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starterartifactId>
- dependency>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-testartifactId>
- <scope>testscope>
- dependency>
-
- <dependency>
- <groupId>com.baomidougroupId>
- <artifactId>mybatis-plus-boot-starterartifactId>
- <version>3.5.0version>
- dependency>
-
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- <version>8.0.26version>
- dependency>
-
- <dependency>
- <groupId>org.projectlombokgroupId>
- <artifactId>lombokartifactId>
- <optional>trueoptional>
- dependency>
# 数据源 spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql:///mybatis?serverTimezone=UTC username: root password: root #日志格式 logging: pattern: console: '%d{HH:mm:ss.SSS} %clr(%-5level) --- [%-15thread] %cyan(%-50logger{50}):%msg%n'
- public interface UserMapper extends BaseMapper
{ -
- }
- @SpringBootApplication
- @MapperScan("com.gq.springnootdemo.mapper")
- public class SpringnootdemoApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(SpringnootdemoApplication.class, args);
- }
-
- }
-
- @SpringBootTest
- class SpringnootdemoApplicationTests {
-
- @Autowired
- private UserMapper userMapper;
- @Test
- void contextLoads() {
- user users = userMapper.selectById(1);
- System.out.println(users);
- }
-
- }