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); //根据主键更新

原文链接:https://blog.csdn.net/feidao0/article/details/80731824

原文地址:https://www.cnblogs.com/qfdy123/p/11565207.html