From 6a881eb76c2a1964258ab6dfb30d8a6206a79f66 Mon Sep 17 00:00:00 2001 From: "mail_yanpeng@163.com" Date: Tue, 25 Aug 2020 11:19:20 +0800 Subject: [PATCH] crud --- .../java/com/aiprose/mbp/MbpApplication.java | 1 - .../aiprose/mbp/controller/UserController.java | 7 ++++++- .../com/aiprose/mbp/service/UserService.java | 18 ++++++++++++------ src/main/resources/application.yml | 4 +++- .../com/aiprose/mbp/MbpApplicationTests.java | 10 ++++++++++ 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/aiprose/mbp/MbpApplication.java b/src/main/java/com/aiprose/mbp/MbpApplication.java index ab9d2c0..bbf4779 100644 --- a/src/main/java/com/aiprose/mbp/MbpApplication.java +++ b/src/main/java/com/aiprose/mbp/MbpApplication.java @@ -7,7 +7,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; -//@MapperScan({"com.aiprose.mbp.mapper"}) @MapperScan({"com.aiprose.mbp.mapper","com.gitee.sunchenbin.mybatis.actable.dao.*"}) @ComponentScan({"com.gitee.sunchenbin.mybatis.actable.manager.*","com.aiprose.mbp.*"}) @SpringBootApplication diff --git a/src/main/java/com/aiprose/mbp/controller/UserController.java b/src/main/java/com/aiprose/mbp/controller/UserController.java index 382282a..ad935a4 100644 --- a/src/main/java/com/aiprose/mbp/controller/UserController.java +++ b/src/main/java/com/aiprose/mbp/controller/UserController.java @@ -2,6 +2,7 @@ package com.aiprose.mbp.controller; import com.aiprose.mbp.entity.User; import com.aiprose.mbp.service.UserService; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -17,11 +18,15 @@ public class UserController { public void save() { User user = new User(); user.setName("nelson"); - userService.save(user); + System.out.println(userService.save(user)); } @GetMapping("list") public List user() { return userService.list(); } + @GetMapping("page") + public Page page() { + return userService.page(); + } } diff --git a/src/main/java/com/aiprose/mbp/service/UserService.java b/src/main/java/com/aiprose/mbp/service/UserService.java index e0f4d77..9179782 100644 --- a/src/main/java/com/aiprose/mbp/service/UserService.java +++ b/src/main/java/com/aiprose/mbp/service/UserService.java @@ -2,25 +2,31 @@ package com.aiprose.mbp.service; import com.aiprose.mbp.entity.User; import com.aiprose.mbp.mapper.UserMapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service -public class UserService { +public class UserService extends ServiceImpl { @Autowired private UserMapper userMapper; - public User save(User user){ - int insert = userMapper.insert(user); - return user; - } public List list(){ List userList1 = userMapper.queryList(); - List userList = userMapper.selectList(null); + List userList = userMapper.selectList(new QueryWrapper().lambda().eq(User::getName,"nelson")); return userList; } + + + public Page page(){ + Page page = userMapper.selectPage(new Page(1, 2), new QueryWrapper().eq("name","nelson")); + return page; + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 34200fe..5c56288 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -20,4 +20,6 @@ actable: type: mysql mybatis-plus: mapper-locations: classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml -# mapper-locations: classpath*:xxxxxx/*.xml,classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml \ No newline at end of file +# mapper-locations: classpath*:xxxxxx/*.xml,classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl \ No newline at end of file diff --git a/src/test/java/com/aiprose/mbp/MbpApplicationTests.java b/src/test/java/com/aiprose/mbp/MbpApplicationTests.java index 9578908..b5cf492 100644 --- a/src/test/java/com/aiprose/mbp/MbpApplicationTests.java +++ b/src/test/java/com/aiprose/mbp/MbpApplicationTests.java @@ -1,13 +1,23 @@ package com.aiprose.mbp; +import com.aiprose.mbp.entity.User; +import com.aiprose.mbp.service.UserService; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import java.util.List; + @SpringBootTest class MbpApplicationTests { + @Autowired + private UserService userService; + @Test void contextLoads() { + List list = userService.list(); + System.out.println(list); } }