0% found this document useful (0 votes)
74 views4 pages

Springboot MybatisPlus Mysql CRUD

The document provides a guide for setting up a Spring Boot application with MyBatis Plus and MySQL for CRUD operations. It includes the necessary dependencies in the pom.xml, configuration settings in application.properties, a model class for 'Girl', a mapper interface, and a test class demonstrating CRUD functionality. The test class includes methods for selecting, inserting, deleting, and updating records in the database.

Uploaded by

kisswxm99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views4 pages

Springboot MybatisPlus Mysql CRUD

The document provides a guide for setting up a Spring Boot application with MyBatis Plus and MySQL for CRUD operations. It includes the necessary dependencies in the pom.xml, configuration settings in application.properties, a model class for 'Girl', a mapper interface, and a test class demonstrating CRUD functionality. The test class includes methods for selecting, inserting, deleting, and updating records in the database.

Uploaded by

kisswxm99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Springboot MybatisPlus mysql CRUD

1、[Link]
<dependencies>
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>[Link]</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>[Link]</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

2、[Link]

[Link]=jdbc:mysql://localhost:3306/hi?
serverTimezone=UTC&amp;characterEncoding=utf-8
[Link]=root
[Link]=root
[Link]-class-name=[Link]
[Link]-type=auto
#显示 SQL 语句
[Link]=DEBUG

3、
模型
package [Link];

import [Link];

@Data
public class Girl {
private Integer id;
private String name;
private Double price;

public Girl() {
}

public Girl(String name, Double price) {


[Link] = name;
[Link] = price;
}
}

Mapper 接口:
package [Link];

import [Link];
import [Link];

public interface GirlMapper extends BaseMapper<Girl> {


}

启动类:
package [Link];

import [Link];
import [Link];
import [Link];
@MapperScan("[Link]")
@SpringBootApplication
public class HimybatisplusApplication {

public static void main(String[] args) {


[Link]([Link], args);
}

CRUD 测试类
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

@RunWith([Link])
@SpringBootTest
public class HimybatisplusApplicationTests {

@Autowired
private GirlMapper girlMapper;
@Test
public void all() {
[Link]("select method test");
List<Girl> girls = [Link](null);
[Link]([Link]::println);

@Test
public void insert() {
[Link](new Girl("貂蝉", 6666.12d));
all();
}

@Test
public void del() {
[Link](12);
all();
}

@Test
public void update() {
Girl girl = new Girl();
[Link](15);
[Link](9999.88d);
[Link](girl);
girl = [Link](15);
[Link](girl);
}

You might also like