1.入门案例
1.1 pom依赖引用
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.3.1</version>
</dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.49</version>
</dependency>
1.2 yml配置文件
spring:datasource:driver -class-name: com.mysql.jdbc.Driverurl: jdbc: mysql://192.168.2.17:3306/test?useUnicode=true&characterEncoding=utf-8username: rootpassword: roottype: com.zaxxer.hikari.HikariDataSource
1.3 启动类
@SpringBootApplication
@MapperScan("com.atguigu.mybatisplus.mapper")
public class MybatisplusApplication {public static void main(String[] args) {SpringApplication.run(MybatisplusApplication.class, args);}
}
1.4 添加实体
package com.atguigu.boot.bean;
@Data
@TableName("t_user")
public class User {private int id;private String userName;private int age;
}
1.5 添加mapper接口
package com.atguigu.boot.mapper;
@Mapper
public interface UserMapper extends BaseMapper<t_user> {}
1.6 测试
@GetMapping("all")
public List<User> getAll()
{List<User> users = this.userMapper.selectList(null);return users;
}
1.7 添加日志
mybatis-plus:
configuration:
map-underscore-to-camel-case: false
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl