Initial commit
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
package com.yv.service;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
			
		||||
import com.yv.admain.Book;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
@@ -38,4 +39,10 @@ public interface BookService {
 | 
			
		||||
     */
 | 
			
		||||
    List<Book> getAll();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param currentPage
 | 
			
		||||
     * @param pageSize
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    IPage<Book> getPage(int currentPage, int pageSize);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,12 @@
 | 
			
		||||
package com.yv.service;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.IService;
 | 
			
		||||
import com.yv.admain.Book;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author YoVinchen
 | 
			
		||||
 * @date 2023/3/17 上午 10:51
 | 
			
		||||
 */
 | 
			
		||||
public interface IBookService extends IService<Book> {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,45 +1,15 @@
 | 
			
		||||
package com.yv.service.impl;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
			
		||||
import com.yv.admain.Book;
 | 
			
		||||
import com.yv.dao.BookDao;
 | 
			
		||||
import com.yv.service.BookService;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import com.yv.service.IBookService;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author YoVinchen
 | 
			
		||||
 * @date 2023/3/15 下午 10:42
 | 
			
		||||
 * @date 2023/3/17 上午 11:13
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
public class BookServiceImpl implements BookService {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private BookDao bookDao;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Boolean save(Book book) {
 | 
			
		||||
        return bookDao.insert(book) > 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Boolean update(Book book) {
 | 
			
		||||
        return bookDao.updateById(book) > 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Boolean delete(Integer id) {
 | 
			
		||||
        return bookDao.deleteById(id) > 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Book getById(Integer id) {
 | 
			
		||||
        return bookDao.selectById(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Book> getAll() {
 | 
			
		||||
        return bookDao.selectList(null);
 | 
			
		||||
    }
 | 
			
		||||
public class BookServiceImpl extends ServiceImpl<BookDao, Book> implements IBookService {
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,55 @@
 | 
			
		||||
package com.yv.service.impl;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
			
		||||
import com.yv.admain.Book;
 | 
			
		||||
import com.yv.dao.BookDao;
 | 
			
		||||
import com.yv.service.BookService;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author YoVinchen
 | 
			
		||||
 * @date 2023/3/15 下午 10:42
 | 
			
		||||
 */
 | 
			
		||||
@Service
 | 
			
		||||
public class BookServiceImpl2 implements BookService {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private BookDao bookDao;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Boolean save(Book book) {
 | 
			
		||||
        return bookDao.insert(book) > 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Boolean update(Book book) {
 | 
			
		||||
        return bookDao.updateById(book) > 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Boolean delete(Integer id) {
 | 
			
		||||
        return bookDao.deleteById(id) > 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Book getById(Integer id) {
 | 
			
		||||
        return bookDao.selectById(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Book> getAll() {
 | 
			
		||||
        return bookDao.selectList(null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public IPage getPage(int currentPage, int pageSize) {
 | 
			
		||||
        IPage page = new Page(currentPage, pageSize);
 | 
			
		||||
        return bookDao.selectPage(page, null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,66 @@
 | 
			
		||||
package com.yv.service;
 | 
			
		||||
 | 
			
		||||
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/17 上午 10:58
 | 
			
		||||
 */
 | 
			
		||||
@SpringBootTest
 | 
			
		||||
public class BookServiceTeat {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private IBookService bookService;
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testGetById() {
 | 
			
		||||
        System.out.println(bookService.getById(4));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testSave() {
 | 
			
		||||
        Book book = new Book();
 | 
			
		||||
        book.setType("测试数据123");
 | 
			
		||||
        book.setName("测试数据123");
 | 
			
		||||
        book.setDescription("测试数据123");
 | 
			
		||||
        bookService.save(book);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testUpdate() {
 | 
			
		||||
        Book book = new Book();
 | 
			
		||||
        book.setId(15);
 | 
			
		||||
        book.setType("测试数据123");
 | 
			
		||||
        book.setName("测试数据123");
 | 
			
		||||
        book.setDescription("测试数据123");
 | 
			
		||||
        bookService.updateById(book);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testDelete() {
 | 
			
		||||
        bookService.removeById(15);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testGetAll() {
 | 
			
		||||
        bookService.list();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testGetPage() {
 | 
			
		||||
        IPage<Book> page = new Page<Book>(2, 5);
 | 
			
		||||
        bookService.page(page);
 | 
			
		||||
        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());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,64 @@
 | 
			
		||||
package com.yv.service;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
			
		||||
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/17 上午 10:58
 | 
			
		||||
 */
 | 
			
		||||
@SpringBootTest
 | 
			
		||||
public class BookServiceTeatCase {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private BookService bookService;
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testGetById(){
 | 
			
		||||
        System.out.println(bookService.getById(4));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testSave(){
 | 
			
		||||
        Book book = new Book();
 | 
			
		||||
        book.setType("测试数据123");
 | 
			
		||||
        book.setName("测试数据123");
 | 
			
		||||
        book.setDescription("测试数据123");
 | 
			
		||||
        bookService.save(book);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testUpdate(){
 | 
			
		||||
        Book book = new Book();
 | 
			
		||||
        book.setId(15);
 | 
			
		||||
        book.setType("测试数据abcdefg");
 | 
			
		||||
        book.setName("测试数据123");
 | 
			
		||||
        book.setDescription("测试数据123");
 | 
			
		||||
        bookService.update(book);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testDelete(){
 | 
			
		||||
        bookService.delete(15);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testGetAll(){
 | 
			
		||||
        bookService.getAll();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void testGetPage(){
 | 
			
		||||
        IPage<Book> page = bookService.getPage(2, 5);
 | 
			
		||||
        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());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user