MyBatis逆向工程生成dao层增删改查方法解释使用

如下:
int countByExample(BUserExample example); //根据条件查询数量

    /**
     * 示例
     * public int countByExample() {
     * BUserExample userExample = new BUserExample();
     * BUserExample.Criteria criteria = userExample.createCriteria();
     * criteria.andUsernameEqualTo("fan");
     * int count = userMapper.countByExample(userExample);
     * return count;
     * }
     * 相当于:select count(*) from user where username = 'fan'
     */

    int deleteByExample(BUserExample example); //根据条件删除数据(一条或多条)

    /**
     * 示例
     * public int deleteByExample() {
     * BUserExample userExample = new BUserExample();
     * BUserExample.Criteria criteria = userExample.createCriteria();
     * criteria.andUsernameEqualTo("fan");
     * int count = userMapper.deleteByExample(userExample);
     * return count;
     * }
     * 相当于:delete from user where username = 'fan'
     */

    int deleteByPrimaryKey(Integer id); //根据主键删除数据

    int insert(BUser record); //插入数据(插入一条数据)

    int insertSelective(BUser record); //插入数据(插入一条数据,只插入不为null的字段,不会影响有默认值的字段)

    List<BUser> selectByExample(BUserExample example); //根据条件查询数据

    /**
     * 示例:
     * public List<BUser> getList() {
     * BUserExample userExample = new BUserExample();
     * BUserExample.Criteria criteria = userExample.createCriteria();
     * criteria.andUsernameEqualTo("fan");
     * userExample.setOrderByClause("username desc");
     * List<BUser> users = userMapper.selectByExample(userExample);
     * return users;
     * }
     * 相当于:select * from user where username = 'fan' order by username desc
     */

    BUser selectByPrimaryKey(Integer id);  //根据主键查询

    int updateByExampleSelective(@Param("record") BUser record, @Param("example") BUserExample example); //按条件更新值不为null的字段

    /**
     * 示例:
     * public int updateByParam(String username) {
     * BUserExample userExample = new BUserExample();
     * BUserExample.Criteria criteria = userExample.createCriteria();
     * criteria.andUsernameEqualTo(username);
     * BUser user = new BUser();
     * user.setNickname("jdk");
     * int update = userMapper.updateByExampleSelective(user, userExample);
     * return update;
     * }
     * 相当于:update user set nickname = 'jdk' where username = #{username}
     */

    int updateByExample(@Param("record") BUser record, @Param("example") BUserExample example); //按条件更新

    int updateByPrimaryKeySelective(BUser record); //根据主键与条件更新
    /**
     * 示例:
     * public int updateByIdAndParam(String username) {
     * BUser user = new BUser();
     * user.setId(101);
     * user.setUsername(username);
     * int update = userMapper.updateByPrimaryKeySelective(user);
     * return update;
     * }
     * 相当于:update user set username = #{username} where id = 101
     */

    int updateByPrimaryKey(BUser record); //根据主键更新

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值