public void testSelectById(){ User user = new User(); user.setId(16L); User user = user.selectById(); }
新增
1 2 3 4 5 6 7 8 9 10 11 12 13 14
public void testInsert(){ User user = new User(); user.setUserName("diaochan"); user.setPassword("123456"); user.setAge(20); user.setName("貂蝉"); user.setMail("diaochan@itcast.cn"); user.setVersion(1); user.setSex(SexEnum.WOMAN); //使用的是枚举 // 调用AR的insert方法进行插入数据 boolean insert = user.insert(); System.out.println("result => " + insert); }
更新
1 2 3 4 5 6 7 8
public void testUpdate(){ User user = new User(); user.setId(13L);// 查询条件 user.setAge(31); // 更新的数据 boolean result = user.updateById(); System.out.println("result => " + result); }
删除
1 2 3 4 5 6 7
public void testDelete(){ User user = new User(); user.setId(13L); boolean delete = user.deleteById(); System.out.println("result => " + delete); }
查询
1 2 3 4 5 6 7 8 9 10 11
public void testSelect(){ User user = new User(); QueryWrapper<User> wrapper = new QueryWrapper<>(); wrapper.ge("age", 30); //大于等于30岁的用户查询出来 List<User> users = user.selectList(wrapper); for (User user1 : users) { System.out.println(user1); } }