mybatis-generator+Criteria+swagger+lombok自动生成实体类和dao层以及mapper.xml

自动生成mapper和domain,可以减少写sql语句的时间,一般的逻辑都可以使用,复杂的逻辑当然还是需要我们自己来写sql语句的,只是一些基本的增删改查就不需要浪费时间去写了,能够大大的提高效率,把重心放在代码逻辑上。
先来看结果

//实体类
@ApiModel(value="com.example.springboot_shiro.domain.test.User")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class User extends UserExt {
   
    /**
     * 
     */
    @ApiModelProperty(value="id")
    private Integer id;

    /**
     * 
     */
    @ApiModelProperty(value="username")
    private String username;

    /**
     * 
     */
    @ApiModelProperty(value="password")
    private String password;

    /**
     * 
     */
    @ApiModelProperty(value="salt")
    private String salt;
}

//userExample 即使用Criteria增加查询条件所用的

public class UserExample {
   
    protected String orderByClause;

    protected boolean distinct;

    protected List<Criteria> oredCriteria;

    public UserExample() {
   
        oredCriteria = new ArrayList<Criteria>();
    }

    public void setOrderByClause(String orderByClause) {
   
        this.orderByClause = orderByClause;
    }
    public Criteria createCriteria() {
   
        Criteria criteria = createCriteriaInternal();
        if (oredCriteria.size() == 0) {
   
            oredCriteria.add(criteria);
        }
        return criteria;
    }
    public Criteria andIdBetween(Integer value1, Integer value2) {
   
        addCriterion("id between", value1, value2, "id");
        return (Criteria) this;
    }

    public Criteria andIdNotBetween(Integer value1, Integer value2) {
   
       addCriterion("id not between", value1, value2, "id");
       return (Criteria) this;
    }
    ········等等,由于文件太长就不全部展示了
    
}

//UserMapper
@Mapper
@Repository
public interface UserMapper {
   
    long countByExample(UserExample example);

    int deleteByExample(UserExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(User record);

    int insertSelective(User record);

    List<User> selectByExample(UserExample example);

    User selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);

    int updateByExample(@Param("record") User record, @Param("example") UserExample example);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);
}

UserMapper.xml
在这里插入图片描述
下面记录一下如何实现
1.添加依赖

//pom.xml
<!--mysql依赖 -->
        <dependency>
            
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值