java springBoot整合MyBatis Plus LTS
参考文章:
https://blog.youkuaiyun.com/wowocpp/article/details/124714567
next
Finish
ok
可以在 idea 里面 下载 插件 ,插件的名字是 mybatisX
在里面搜索 mybatis plus,选择 3.4.3 版本
然后把上面的内容复制到
pom.xml文件中去
添加 如下类和接口
Book.java
package com.itheima.domain;
public class Book {
private Integer id ;
private String type;
private String name;
private String description;
@Override
public String toString() {
return "Book{" +
"id=" + id +
", type='" + type + '\'' +
", name='" + name + '\'' +
", description='" + description + '\'' +
'}';
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
BookDao.java
package com.itheima.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.Book;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
@Repository
@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?useSSL=false&serverTimezone=UTC
username: root
password: "123456"
mybatis-plus:
global-config:
db-config:
table-prefix: tbl_
test文件
package com.itheima;
import com.itheima.dao.BookDao;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class Springboot06MybatisPlusApplicationTests {
@Autowired
private BookDao bookDao ;
@Test
void contextLoads() {
System.out.println(bookDao.selectById(2));
}
@Test
void testGetAll() {
System.out.println(bookDao.selectList(null));
}
}