- package com.xdu.mybatisplus.service;
-
- import com.baomidou.mybatisplus.extension.service.IService;
- import com.xdu.mybatisplus.pojo.User;
-
- public interface UserService extends IService
{ -
- }
- package com.xdu.mybatisplus.service.impl;
-
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.xdu.mybatisplus.mapper.UserMapper;
- import com.xdu.mybatisplus.pojo.User;
- import com.xdu.mybatisplus.service.UserService;
-
- public class UserServiceImpl extends ServiceImpl
implements UserService { -
- }
- package com.xdu.mybatisplus;
-
- import com.xdu.mybatisplus.pojo.User;
- import com.xdu.mybatisplus.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.ArrayList;
- import java.util.List;
-
- @SpringBootTest
- public class MyBatisPlusTest {
- @Autowired
- private UserService userService;
-
- @Test
- public void testService(){
- //查询总记录数
- long count = userService.count();
- System.out.println(count);
- }
-
- //批量添加
- @Test
- public void testInsetService(){
- List
list = new ArrayList<>(); - for(int i = 1; i <= 5; i++){
- User user = new User();
- user.setName("Joe"+i);
- user.setAge(20+i);
- list.add(user);
- }
- //批量添加
- boolean result = userService.saveBatch(list);
- System.out.println(result);
- }
- }
注意:使用的是 IService接口 中的方法