数据库
首页 > 数据库> > mybatis-plus 3.4.0 - SqlSource生成器

mybatis-plus 3.4.0 - SqlSource生成器

作者:互联网

// return Stream.of(
//         new Insert(),
//         new Delete(),
//         new DeleteByMap(),
//         new DeleteById(),
//         new DeleteBatchByIds(),
//         new Update(),
//         new UpdateById(),
//         new SelectById(),
//         new SelectBatchByIds(),
//         new SelectByMap(),
//         new SelectOne(),
//         new SelectCount(),
//         new SelectMaps(),
//         new SelectMapsPage(),
//         new SelectObjs(),
//         new SelectList(),
//         new SelectPage()
// ).collect(toList());
/**
 * 《SqlSource生成器》
 *
 * 《接口方法》
 * int insert(T entity);
 *
 * 《FooMapper.xml的sql模板》
 * <pre>
 * <script>
 *     INSERT INTO orders
 *     <trim prefix="(" suffix=")" suffixOverrides=",">
 *         <if test="benefitDetail != null">benefit_detail,</if>
 *         <if test="userId != null">user_id,</if>
 *         <if test="orderNo != null">order_no,</if>
 *         <if test="priceAmount != null">price_amount,</if>
 *         <if test="discountAmount != null">discount_amount,</if>
 *         <if test="payAmount != null">pay_amount,</if>
 *         <if test="orderStatus != null">order_status,</if>
 *         <if test="lockVersion != null">lock_version,</if>
 *         <if test="deleteFlag != null">delete_flag,</if>
 *         <if test="createdAt != null">created_at,</if>
 *         <if test="updatedAt != null">updated_at,</if>
 *     </trim>
 *     VALUES
 *     <trim prefix="(" suffix=")" suffixOverrides=",">
 *         <if test="benefitDetail != null">#{benefitDetail},</if>
 *         <if test="userId != null">#{userId},</if>
 *         <if test="orderNo != null">#{orderNo},</if>
 *         <if test="priceAmount != null">#{priceAmount},</if>
 *         <if test="discountAmount != null">#{discountAmount},</if>
 *         <if test="payAmount != null">#{payAmount},</if>
 *         <if test="orderStatus != null">#{orderStatus},</if>
 *         <if test="lockVersion != null">#{lockVersion},</if>
 *         <if test="deleteFlag != null">#{deleteFlag},</if>
 *         <if test="createdAt != null">#{createdAt},</if>
 *         <if test="updatedAt != null">#{updatedAt},</if>
 *     </trim>
 * </script>
 *  </pre>
 */
static class Insert_ extends Insert {

    public void inject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

        super.inject(builderAssistant, mapperClass, modelClass, tableInfo);
    }

    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

        return super.injectMappedStatement(mapperClass, modelClass, tableInfo);
    }

    protected MappedStatement addInsertMappedStatement(Class<?> mapperClass, Class<?> parameterType, String id,
                                                       SqlSource sqlSource, KeyGenerator keyGenerator,
                                                       String keyProperty, String keyColumn) {
        return super.addInsertMappedStatement(mapperClass, parameterType, id,
                sqlSource, keyGenerator,
                keyProperty, keyColumn);
    }

    protected MappedStatement addMappedStatement(Class<?> mapperClass, String id, SqlSource sqlSource,
                                                 SqlCommandType sqlCommandType, Class<?> parameterType,
                                                 String resultMap, Class<?> resultType, KeyGenerator keyGenerator,
                                                 String keyProperty, String keyColumn) {
        return super.addMappedStatement(mapperClass, id, sqlSource,
                sqlCommandType, parameterType,
                null, Integer.class, keyGenerator,
                keyProperty, keyColumn);
    }
}

/**
 *《接口方法》
 * List<T> selectList(@Param("ew") Wrapper<T> queryWrapper);
 *
 * 《FooMapper.xml的sql模板》
 * <pre>
 * <script>
 *     <choose>
 *         <when test="ew != null and ew.sqlFirst != null">${ew.sqlFirst}</when>
 *         <otherwise></otherwise>
 *     </choose>
 *     SELECT
 *     <choose>
 *         <when test="ew != null and ew.sqlSelect != null">
 *             ${ew.sqlSelect}
 *         </when>
 *         <otherwise>
 *             id,benefit_detail AS benefitDetail,user_id AS userId,order_no AS orderNo,price_amount AS priceAmount,discount_amount AS discountAmount,pay_amount AS payAmount,order_status AS orderStatus,lock_version AS lockVersion,delete_flag AS deleteFlag,created_at AS createdAt,updated_at AS updatedAt
 *         </otherwise>
 *     </choose>
 *     FROM orders
 *     <where>
 *         <choose>
 *             <when test="ew != null">
 *                 <if test="ew.entity != null">
 *                     <if test="ew.entity.id != null">id=#{ew.entity.id}</if>
 *                     <if test="ew.entity['benefitDetail'] != null"> AND benefit_detail=#{ew.entity.benefitDetail}</if>
 *                     <if test="ew.entity['userId'] != null"> AND user_id=#{ew.entity.userId}</if>
 *                     <if test="ew.entity['orderNo'] != null"> AND order_no=#{ew.entity.orderNo}</if>
 *                     <if test="ew.entity['priceAmount'] != null"> AND price_amount=#{ew.entity.priceAmount}</if>
 *                     <if test="ew.entity['discountAmount'] != null"> AND discount_amount=#{ew.entity.discountAmount}</if>
 *                     <if test="ew.entity['payAmount'] != null"> AND pay_amount=#{ew.entity.payAmount}</if>
 *                     <if test="ew.entity['orderStatus'] != null"> AND order_status=#{ew.entity.orderStatus}</if>
 *                     <if test="ew.entity['lockVersion'] != null"> AND lock_version=#{ew.entity.lockVersion}</if>
 *                     <if test="ew.entity['createdAt'] != null"> AND created_at=#{ew.entity.createdAt}</if>
 *                     <if test="ew.entity['updatedAt'] != null"> AND updated_at=#{ew.entity.updatedAt}</if>
 *                 </if>
 *                 AND delete_flag=0
 *
 *                 <if test="ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfNormal">
 *                     AND ${ew.sqlSegment}
 *                 </if>
 *                 <if test="ew.sqlSegment != null and ew.sqlSegment != '' and ew.emptyOfNormal">
 *                     ${ew.sqlSegment}
 *                 </if>
 *             </when>
 *             <otherwise>
 *                 delete_flag=0
 *             </otherwise>
 *         </choose>
 *     </where>
 *     <choose>
 *         <when test="ew != null and ew.sqlComment != null">
 *             ${ew.sqlComment}
 *         </when>
 *         <otherwise></otherwise>
 *     </choose>
 * </script>
 *
 * </pre>
 */
static class SelectList_ extends SelectList {
    public void inject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

        super.inject(builderAssistant, mapperClass, modelClass, tableInfo);
    }

    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        return super.injectMappedStatement(mapperClass, modelClass, tableInfo);
    }
}

/**
 * 《接口方法》
 * <E extends IPage<T>> E selectPage(E page, @Param("ew") Wrapper<T> queryWrapper);
 *
 * 《插件》
 * @see com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor
 * @see com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor
 *
 * 《FooMapper.xml的sql模板》
 * <pre>
 *      sql模板同SelectList,分页通过《拦截器》实现
 * </pre>
 */
static class SelectPage_ extends SelectPage {
    public void inject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

        super.inject(builderAssistant, mapperClass, modelClass, tableInfo);
    }

    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        return super.injectMappedStatement(mapperClass, modelClass, tableInfo);
    }
}

/**
 * 《接口方法》
 * int updateById(@Param("et") T entity);
 *
 * 《乐观锁》
 * @see com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor
 * @see com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor
 *
 * 《FooMapper.xml的sql模板》
 * <pre>
 * <script>
 *     UPDATE orders
 *     <set>
 *         <if test="et['benefitDetail'] != null">benefit_detail=#{et.benefitDetail},</if>
 *         <if test="et['userId'] != null">user_id=#{et.userId},</if>
 *         <if test="et['orderNo'] != null">order_no=#{et.orderNo},</if>
 *         <if test="et['priceAmount'] != null">price_amount=#{et.priceAmount},</if>
 *         <if test="et['discountAmount'] != null">discount_amount=#{et.discountAmount},</if>
 *         <if test="et['payAmount'] != null">pay_amount=#{et.payAmount},</if>
 *         <if test="et['orderStatus'] != null">order_status=#{et.orderStatus},</if>
 *         <if test="et['lockVersion'] != null">lock_version=#{et.lockVersion},</if>
 *         <if test="et['createdAt'] != null">created_at=#{et.createdAt},</if>
 *         <if test="et['updatedAt'] != null">updated_at=#{et.updatedAt},</if>
 *     </set>
 *     WHERE id=#{et.id}
 *     <if test="et != null and et['lockVersion'] != null">
 *         AND lock_version=#{MP_OPTLOCK_VERSION_ORIGINAL}
 *     </if>
 *     AND delete_flag=0
 * </script>
 *
 * </pre>
 */
static class UpdateById_ extends UpdateById {
    public void inject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

        super.inject(builderAssistant, mapperClass, modelClass, tableInfo);
    }

    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        return super.injectMappedStatement(mapperClass, modelClass, tableInfo);
    }
}

 

 

 

标签:tableInfo,生成器,mapperClass,3.4,modelClass,mybatis,new,ew,Class
来源: https://blog.csdn.net/zhouzhiande/article/details/113697797