- 导入坐标
<dependency>
<groupId>com.baomidougroupId>
<artifactId>mybatis-plus-boot-starterartifactId>
<version>3.5.1version>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starterartifactId>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<scope>runtimescope>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-testartifactId>
<scope>testscope>
dependency>
- 实现类及其接口
public class Book {
private Integer id;
private String name;
private double price;
private String author;
private int count;
}
- 定义数据层接口与映射配置,继承BaseMapper
@Mapper
public interface BookDao extends BaseMapper<Book> {
}
- application.yml 配置
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/ssm_db
username: root
password: root
- 测试
@SpringBootTest
class Springboot06MybatisPlusApplicationTests {
@Autowired
private BookDao bookDao;
@Test
void contextLoads() {
System.out.println(bookDao.selectById(2));
}
@Test
void selectAll() {
List<Book> bookList = bookDao.selectList(null);
for (Book book : bookList) {
System.out.println(book);
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)