Browse Source

crud

master
mail_yanpeng@163.com 4 years ago
parent
commit
6a881eb76c
  1. 1
      src/main/java/com/aiprose/mbp/MbpApplication.java
  2. 7
      src/main/java/com/aiprose/mbp/controller/UserController.java
  3. 18
      src/main/java/com/aiprose/mbp/service/UserService.java
  4. 4
      src/main/resources/application.yml
  5. 10
      src/test/java/com/aiprose/mbp/MbpApplicationTests.java

1
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

7
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> user() {
return userService.list();
}
@GetMapping("page")
public Page<User> page() {
return userService.page();
}
}

18
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<UserMapper,User> {
@Autowired
private UserMapper userMapper;
public User save(User user){
int insert = userMapper.insert(user);
return user;
}
public List<User> list(){
List<User> userList1 = userMapper.queryList();
List<User> userList = userMapper.selectList(null);
List<User> userList = userMapper.selectList(new QueryWrapper<User>().lambda().eq(User::getName,"nelson"));
return userList;
}
public Page<User> page(){
Page<User> page = userMapper.selectPage(new Page<User>(1, 2), new QueryWrapper<User>().eq("name","nelson"));
return page;
}
}

4
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
# mapper-locations: classpath*:xxxxxx/*.xml,classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

10
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<User> list = userService.list();
System.out.println(list);
}
}

Loading…
Cancel
Save