Initial commit

This commit is contained in:
Yo Vinchen 2023-03-15 21:48:15 +08:00
parent 3e396faf41
commit 4496f8c783
10 changed files with 219 additions and 68 deletions

View File

@ -2,6 +2,7 @@
<project version="4"> <project version="4">
<component name="CompilerConfiguration"> <component name="CompilerConfiguration">
<annotationProcessing> <annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Maven default annotation processors profile" enabled="true"> <profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" /> <sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />

View File

@ -0,0 +1,12 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="MavenPackageUpdate" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="excludeList">
<list>
<option value="mysql:mysql-connector-java" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.projectlombok:lombok:1.18.24">
<CLASSES>
<root url="jar://E:/maven-cangku/org/projectlombok/lombok/1.18.24/lombok-1.18.24.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://E:/maven-cangku/org/projectlombok/lombok/1.18.24/lombok-1.18.24-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://E:/maven-cangku/org/projectlombok/lombok/1.18.24/lombok-1.18.24-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -39,6 +39,11 @@
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version> <version>5.1.49</version>
</dependency> </dependency>
<!--lombok-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>

View File

@ -3,6 +3,9 @@ package com.yv;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author YoVinchen
*/
@SpringBootApplication @SpringBootApplication
public class Springboot08SsmpApplication { public class Springboot08SsmpApplication {

View 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;
}

View 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> {
}

View File

@ -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: spring:
datasource: datasource:
druid: druid:
driver-class-name: com.mysql.jdbc.Driver 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 username: root
password: 8520 password: 8520
#配置Mp相关配置
mybatis-plus:
global-config:
db-config:
table-prefix: tbl_
id-type: auto
#端口配置
server:
port: 8080

View File

@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest @SpringBootTest
class Springboot08SsmpApplicationTests { class SMMPApplicationTests {
@Test @Test
void contextLoads() { void contextLoads() {

View 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);
}
}