Initial commit
This commit is contained in:
@@ -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