Initial commit
This commit is contained in:
		
							
								
								
									
										2
									
								
								.idea/compiler.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								.idea/compiler.xml
									
									
									
										generated
									
									
									
								
							@@ -34,7 +34,7 @@
 | 
				
			|||||||
      <module name="springboot_06_mybatis_plus" target="17" />
 | 
					      <module name="springboot_06_mybatis_plus" target="17" />
 | 
				
			||||||
      <module name="springboot_07_druid" target="17" />
 | 
					      <module name="springboot_07_druid" target="17" />
 | 
				
			||||||
      <module name="springboot_07_durid" target="17" />
 | 
					      <module name="springboot_07_durid" target="17" />
 | 
				
			||||||
      <module name="springboot_08_ssmp" target="17" />
 | 
					      <module name="springboot_08_ssmp" target="1.8" />
 | 
				
			||||||
    </bytecodeTargetLevel>
 | 
					    </bytecodeTargetLevel>
 | 
				
			||||||
  </component>
 | 
					  </component>
 | 
				
			||||||
  <component name="JavacSettings">
 | 
					  <component name="JavacSettings">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,7 +14,7 @@
 | 
				
			|||||||
    <name>springboot_08_ssmp</name>
 | 
					    <name>springboot_08_ssmp</name>
 | 
				
			||||||
    <description>Demo project for Spring Boot</description>
 | 
					    <description>Demo project for Spring Boot</description>
 | 
				
			||||||
    <properties>
 | 
					    <properties>
 | 
				
			||||||
        <java.version>17</java.version>
 | 
					        <java.version>1.8</java.version>
 | 
				
			||||||
    </properties>
 | 
					    </properties>
 | 
				
			||||||
    <dependencies>
 | 
					    <dependencies>
 | 
				
			||||||
        <dependency>
 | 
					        <dependency>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										20
									
								
								springboot_08_ssmp/src/main/java/com/yv/config/MPConfig.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								springboot_08_ssmp/src/main/java/com/yv/config/MPConfig.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					package com.yv.config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
 | 
				
			||||||
 | 
					import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 | 
				
			||||||
 | 
					import org.springframework.context.annotation.Bean;
 | 
				
			||||||
 | 
					import org.springframework.context.annotation.Configuration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @author YoVinchen
 | 
				
			||||||
 | 
					 * @date 2023/3/15 下午 9:58
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Configuration
 | 
				
			||||||
 | 
					public class MPConfig {
 | 
				
			||||||
 | 
					    @Bean
 | 
				
			||||||
 | 
					    public MybatisPlusInterceptor mybatisPlusInterceptor() {
 | 
				
			||||||
 | 
					        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
 | 
				
			||||||
 | 
					        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
 | 
				
			||||||
 | 
					        return interceptor;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					package com.yv.service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.yv.admain.Book;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @author YoVinchen
 | 
				
			||||||
 | 
					 * @date 2023/3/15 下午 10:39
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public interface BookService {
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @param book
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    Boolean save(Book book);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @param book
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    Boolean update(Book book);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @param id
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    Boolean delete(Integer id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @param id
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    Book getById(Integer id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    List<Book> getAll();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,45 @@
 | 
				
			|||||||
 | 
					package com.yv.service.impl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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 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);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -13,7 +13,10 @@ mybatis-plus:
 | 
				
			|||||||
    db-config:
 | 
					    db-config:
 | 
				
			||||||
      table-prefix: tbl_
 | 
					      table-prefix: tbl_
 | 
				
			||||||
      id-type: auto
 | 
					      id-type: auto
 | 
				
			||||||
 | 
					  configuration:
 | 
				
			||||||
 | 
					    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#端口配置
 | 
					#端口配置
 | 
				
			||||||
server:
 | 
					server:
 | 
				
			||||||
  port: 8080
 | 
					  port: 8080
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -55,12 +55,17 @@ public class BookDaoTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    void testGetPage() {
 | 
					    void testGetPage() {
 | 
				
			||||||
        IPage page = new Page(2, 5);
 | 
					        IPage page = new Page(1, 5);
 | 
				
			||||||
        bookDao.selectPage(page, null);
 | 
					        bookDao.selectPage(page, null);
 | 
				
			||||||
 | 
					        //当前页
 | 
				
			||||||
        System.out.println(page.getCurrent());
 | 
					        System.out.println(page.getCurrent());
 | 
				
			||||||
 | 
					        //每页中数据数
 | 
				
			||||||
        System.out.println(page.getSize());
 | 
					        System.out.println(page.getSize());
 | 
				
			||||||
 | 
					        //总数据
 | 
				
			||||||
        System.out.println(page.getTotal());
 | 
					        System.out.println(page.getTotal());
 | 
				
			||||||
 | 
					        //总页数
 | 
				
			||||||
        System.out.println(page.getPages());
 | 
					        System.out.println(page.getPages());
 | 
				
			||||||
 | 
					        //数据
 | 
				
			||||||
        System.out.println(page.getRecords());
 | 
					        System.out.println(page.getRecords());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -73,9 +78,21 @@ public class BookDaoTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    void testGetBy2() {
 | 
					    void testGetBy2() {
 | 
				
			||||||
        String name = "1";
 | 
					        String name = "Spring";
 | 
				
			||||||
        LambdaQueryWrapper<Book> lqw = new LambdaQueryWrapper<Book>();
 | 
					        LambdaQueryWrapper<Book> lqw = new LambdaQueryWrapper<Book>();
 | 
				
			||||||
        //if(name != null) lqw.like(Book::getName,name);
 | 
					        //JDK17报错ew.sqlSegment != null,JDK1.8没有问题
 | 
				
			||||||
 | 
					        if (name != null) lqw.like(Book::getName, name);
 | 
				
			||||||
 | 
					        bookDao.selectList(lqw);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 以Test3为标准
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    void testGetBy3() {
 | 
				
			||||||
 | 
					        String name = null;
 | 
				
			||||||
 | 
					        LambdaQueryWrapper<Book> lqw = new LambdaQueryWrapper<Book>();
 | 
				
			||||||
 | 
					        //JDK17报错ew.sqlSegment != null,JDK1.8没有问题
 | 
				
			||||||
        lqw.like(name != null, Book::getName, name);
 | 
					        lqw.like(name != null, Book::getName, name);
 | 
				
			||||||
        bookDao.selectList(lqw);
 | 
					        bookDao.selectList(lqw);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user