失效链接处理 |
Mybatis-Plus文档 PDF 下载
本站整理下载:
相关截图:
主要内容:
快速入门
1、导入依赖
<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> <!-- mysql 数据库连接 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.34</version>
</dependency> <!-- 实体类增强 https://www.jianshu.com/p/2543c71a8e45 --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.8</version> <scope>provided</scope> </dependency> <!-- mybatis-plus --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.1.1</version> </dependency> </dependencies> 2、编写配置
# DataSource Config spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://203.187.186.206:3306/caic_basic? useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 username: root password: Jcgj20201028 3、实体类及mapper
@Data // @ToString @EqualsAndHashCode @Getter @Setter @RequiredArgsConstructor 注 解集合 @AllArgsConstructor // 生成全参构造器 @NoArgsConstructor // 生成无参构造器 @TableName(value = "user_practice") // 解决实体类名与表名不一致 public class User { @TableField("id")// 解决实体类字段名与表字段名明不一致 private Long id; private String name; private Integer age; private String email; private Object object; }@Repository public interface UserMapper extends BaseMapper<User> { }
4、测试
日志配置
mybatis-plus 原生输出
@SpringBootApplication @MapperScan("com.liang.demo.mapper") //开启包扫描 public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }@SpringBootTest class DemoApplicationTests { @Autowired private UserMapper userMapper; @Test void contextLoads() { System.out.println(("----- 查询所有用户 ------")); List<User> userList = userMapper.selectList(null); userList.forEach(System.out::println); } }
|