package com.huacheng;
import com.huacheng.mybatisPlus.domain.User;
import com.huacheng.mybatisPlus.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
@SpringBootTest
@RunWith(SpringRunner.class)
public class Test_service {
@Autowired
private UserService userService;
@Test
public void t_saveBatch() {
//批量保存
ArrayList<User> users = new ArrayList<>();
User yeding = new User(6l, "yeding", 23, "5444@163.com");
User fudadiao = new User(7l, "fudadiao", 24, "55144@qq.com");
users.add(yeding);
users.add(fudadiao);
userService.saveBatch(users);
}
@Test
public void t_getById() {
//根据ID获取
User user = userService.getById(6);
System.out.println(user);
}
@Test
public void t_removeById() {
//根据ID删除
userService.removeById(6);
}
@Test
public void t_removeByIds() {
//批量删除
ArrayList<Integer> ids = new ArrayList<>();
ids.add(6);
ids.add(7);
userService.removeByIds(ids);
}
@Test
public void t_updateById() {
//根据ID更新
userService.updateById(new User(1l, "fu", 23, "23954545@qq.com"));
}
}