1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| package com.xiaoguan.test;
import com.xiaoguan.mapper.CarMapper; import com.xiaoguan.pojo.Car; import com.xiaoguan.utils.SqlSessionUtils; import org.apache.ibatis.session.SqlSession; import org.junit.Test;
import java.util.ArrayList; import java.util.List;
public class CarTest { @Test public void testdeleteByIds2(){ SqlSession sqlSession = SqlSessionUtils.openSession(); CarMapper mapper = sqlSession.getMapper(CarMapper.class); Long[] ids= {37L,38L}; int count=mapper.deleteByIds2(ids); System.out.println(count); sqlSession.commit(); sqlSession.close(); }
@Test public void testInsertinsertBatch(){ SqlSession sqlSession = SqlSessionUtils.openSession(); CarMapper mapper = sqlSession.getMapper(CarMapper.class); List<Car> carLists=new ArrayList<>(); for (int i = 0; i < 4; i++) { carLists.add(new Car(null, "1200", "帕萨特", 200.0, "2023-07-18", "燃油车")); } int count=mapper.insertBatch(carLists); System.out.println(count); sqlSession.commit(); sqlSession.close(); } @Test public void testdeleteByIds(){ SqlSession sqlSession = SqlSessionUtils.openSession(); CarMapper mapper = sqlSession.getMapper(CarMapper.class); Long[] ids= {29L,31L}; int count=mapper.deleteByIds(ids); System.out.println(count); sqlSession.commit(); sqlSession.close(); } @Test public void testselectByChoose(){ SqlSession sqlSession = SqlSessionUtils.openSession(); CarMapper mapper = sqlSession.getMapper(CarMapper.class); List<Car>cars=mapper.selectByChoose("",null,"燃油车 "); cars.forEach(car -> System.out.println(car)); sqlSession.close(); } @Test public void testupdateCarBySet(){ SqlSession sqlSession = SqlSessionUtils.openSession(); CarMapper mapper = sqlSession.getMapper(CarMapper.class); Car car = new Car(34L, "8888888888", null, null, null, null); mapper.updateCarBySet(car); sqlSession.commit(); sqlSession.close(); } @Test public void testupdateCarById(){ SqlSession sqlSession = SqlSessionUtils.openSession(); CarMapper mapper = sqlSession.getMapper(CarMapper.class); Car car = new Car(34L, "88888888", "保时捷", 200.0, "2023-07-18", "燃油车"); mapper.updateCarById(car); sqlSession.commit(); sqlSession.close(); } @Test public void testselectByMultiConditionWithTrim(){ SqlSession sqlSession = SqlSessionUtils.openSession(); CarMapper mapper = sqlSession.getMapper(CarMapper.class); List<Car> cars=mapper.selectByMultiConditionWithTrim("特斯拉",50.0,""); cars.forEach(car -> System.out.println(car)); sqlSession.close(); } @Test public void testselectByMultiConditionWithWhere(){ SqlSession sqlSession = SqlSessionUtils.openSession(); CarMapper mapper = sqlSession.getMapper(CarMapper.class); List<Car> cars=mapper.selectByMultiConditionWithWhere("特斯拉",50.0,""); cars.forEach(car -> System.out.println(car)); sqlSession.close(); } @Test public void testselectByMultiCondition(){ SqlSession sqlSession = SqlSessionUtils.openSession(); CarMapper mapper = sqlSession.getMapper(CarMapper.class); List<Car> cars=mapper.selectByMultiCondition("特斯拉",null,""); cars.forEach(car -> System.out.println(car)); sqlSession.close(); } }
|