spring boot + mybaties plus

2021-06-28 02:05

阅读:691

@RunWith(SpringRunner.class)
@SpringBootTest
public class MpApplicationTests {

@Resource
private PeopleMapper userMapper;

//添加一个用户
@Test
public void contextLoads() {
People p = new People();
p.setName("b123");
p.setAge("1234");
userMapper.insert(p);
//得到返回的主键ID
int id = p.getId();

}

//根据用户ID删除记录
@Test
public void delete(){
userMapper.deleteById(5);
}

//根据主键修改
@Test
public void update(){
People p = new People();
p.setName("bao");
p.setAge("18");
p.setId(1);
userMapper.updateById(p);

}

//根据不同的条件查询
@Test
public void select() {
People p = new People();
// name 和 age 都是数据库People表的字段
//该查询语句==》查询 select * from People where name = ‘b‘ and age between 124 and 1235;
//当然后面还是可以继续添加条件
List list = userMapper.selectList(new QueryWrapper().eq("name","b").
between("age",124,1235));
for(People people:list){
System.out.println(people.getAge()+"====="+people.getName());
}
}
}

上一篇:python字符串的拼接

下一篇:python基础


评论


亲,登录后才可以留言!