爬梯:TKMapper的api记录

TK.Mapper

核心API

增
Mapper.insert(record);

保存一个实体,null的属性也会保存,不会使用数据库默认值

Mapper.insertSelective(record);

保存一个实体,null的属性不会保存,会使用数据库默认值

删
Mapper.delete(record);

根据实体属性作为条件进行删除,查询条件使用等号

Mapper.deleteByExample(example)

根据Example条件删除数据

Mapper.deleteByPrimaryKey(key)

根据主键字段进行删除,方法参数必须包含完整的主键属性

改
Mapper.updateByExample(record, example)

根据Example条件更新实体`record`包含的全部属性,null值会被更新

Mapper.updateByExampleSelective(record, example)

根据Example条件更新实体`record`包含的不是null的属性值

Mapper.updateByPrimaryKey(record)

根据主键更新实体全部字段,null值会被更新

Mapper.updateByPrimaryKeySelective(record)

根据主键更新属性不为null的值

查
Mapper.select(record)

根据实体中的属性值进行查询,查询条件使用等号

Mapper.selectAll()

查询全部结果

Mapper.selectByExample(example)

根据Example条件进行查询

Mapper.selectByExampleAndRowBounds(example, rowBounds)

根据example条件和RowBounds进行分页查询

Mapper.selectByPrimaryKey(key)

根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号

Mapper.selectByRowBounds(record, rowBounds)

根据实体属性和RowBounds进行分页查询

Mapper.selectCount(record)

根据实体中的属性查询总数,查询条件使用等号

Mapper.selectCountByExample(example)

根据Example条件进行查询总数

Mapper.selectOne(record)

根据实体中的属性进行查询,只能有一个返回值,有多个结果是抛出异常,查询条件使用等号

Example 查询语句

 //注意:(addEqualTo)这里的userId是映射的实体类。
    @Test
    public void selectAllTest2() {
        Example example = new Example(Category.class);
        example.createCriteria()
                .andEqualTo("categoryID",1)
                .andEqualTo("categoryName","Beverages");

        List<Category> categories = categoryDao.selectByExample(example);
        System.out.println(categories);
        assertEquals(true, categories.size() > 0);
    }

    //注意:(addCondition)这里的user_id是数据库的字段。即where后面的条件。应该写sql语句。
    @Test
    public void selectAllTest3() {
        Example example = new Example(Category.class);
        example.createCriteria()
                .andCondition("category_id=",1)
                .andCondition("category_name=","Beverages");

        List<Category> categories = categoryDao.selectByExample(example);
        System.out.println(categories);
        assertEquals(true, categories.size() > 0);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值