Initial commit
This commit is contained in:
@@ -1,58 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.11</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.yv</groupId>
|
||||
<artifactId>springboot_08_ssmp</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>springboot_08_ssmp</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.4.3</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.6</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.49</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.11</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.yv</groupId>
|
||||
<artifactId>springboot_08_ssmp</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>springboot_08_ssmp</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.4.3</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.6</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.49</version>
|
||||
</dependency>
|
||||
<!--lombok-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
@@ -3,11 +3,14 @@ package com.yv;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author YoVinchen
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class Springboot08SsmpApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Springboot08SsmpApplication.class, args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Springboot08SsmpApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
18
springboot_08_ssmp/src/main/java/com/yv/admain/Book.java
Normal file
18
springboot_08_ssmp/src/main/java/com/yv/admain/Book.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.yv.admain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author YoVinchen
|
||||
* @date 2023/3/15 下午 9:24
|
||||
*
|
||||
* lombok
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class Book {
|
||||
private int id;
|
||||
private String type;
|
||||
private String name;
|
||||
private String description;
|
||||
}
|
14
springboot_08_ssmp/src/main/java/com/yv/dao/BookDao.java
Normal file
14
springboot_08_ssmp/src/main/java/com/yv/dao/BookDao.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.yv.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yv.admain.Book;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author YoVinchen
|
||||
* @date 2023/3/15 下午 9:31
|
||||
*/
|
||||
@Mapper
|
||||
public interface BookDao extends BaseMapper<Book> {
|
||||
|
||||
}
|
@@ -1,16 +1,19 @@
|
||||
# 配置相关配置
|
||||
#spring:
|
||||
# datasource:
|
||||
# driver-class-name: com.mysql.jdbc.Driver
|
||||
# url: jdbc:mysql://localhost:3306/ssm_db?useSSL=false
|
||||
# username: root
|
||||
# password: 8520
|
||||
# type: com.alibaba.druid.pool.DruidDataSource
|
||||
|
||||
#数据库配置
|
||||
spring:
|
||||
datasource:
|
||||
druid:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/ssm_db?useSSL=false
|
||||
url: jdbc:mysql://localhost:3306/ssm_db?useSSL=false&useUnicode=true&characterEncoding=utf8
|
||||
username: root
|
||||
password: 8520
|
||||
password: 8520
|
||||
|
||||
#配置Mp相关配置
|
||||
mybatis-plus:
|
||||
global-config:
|
||||
db-config:
|
||||
table-prefix: tbl_
|
||||
id-type: auto
|
||||
|
||||
#端口配置
|
||||
server:
|
||||
port: 8080
|
||||
|
@@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class Springboot08SsmpApplicationTests {
|
||||
class SMMPApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
82
springboot_08_ssmp/src/test/java/com/yv/dao/BookDaoTest.java
Normal file
82
springboot_08_ssmp/src/test/java/com/yv/dao/BookDaoTest.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package com.yv.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yv.admain.Book;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
/**
|
||||
* @author YoVinchen
|
||||
* @date 2023/3/15 下午 9:33
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class BookDaoTest {
|
||||
|
||||
@Autowired
|
||||
private BookDao bookDao;
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
System.out.println(bookDao.selectById(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSave() {
|
||||
Book book = new Book();
|
||||
book.setType("测试数据123");
|
||||
book.setName("测试数据123");
|
||||
book.setDescription("测试数据123");
|
||||
bookDao.insert(book);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdate() {
|
||||
Book book = new Book();
|
||||
book.setId(14);
|
||||
book.setType("测试数据abcdefg");
|
||||
book.setName("测试数据123");
|
||||
book.setDescription("测试数据123");
|
||||
bookDao.updateById(book);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDelete() {
|
||||
bookDao.deleteById(15);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAll() {
|
||||
System.out.println(bookDao.selectList(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetPage() {
|
||||
IPage page = new Page(2, 5);
|
||||
bookDao.selectPage(page, null);
|
||||
System.out.println(page.getCurrent());
|
||||
System.out.println(page.getSize());
|
||||
System.out.println(page.getTotal());
|
||||
System.out.println(page.getPages());
|
||||
System.out.println(page.getRecords());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetBy() {
|
||||
QueryWrapper<Book> qw = new QueryWrapper<>();
|
||||
qw.like("name", "Spring");
|
||||
bookDao.selectList(qw);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetBy2() {
|
||||
String name = "1";
|
||||
LambdaQueryWrapper<Book> lqw = new LambdaQueryWrapper<Book>();
|
||||
//if(name != null) lqw.like(Book::getName,name);
|
||||
lqw.like(name != null, Book::getName, name);
|
||||
bookDao.selectList(lqw);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user