基于EasyCode 的mybatis-plus 的代码生成器, 支持多表多条件分页查询

基于EasyCode 的mybatis-plus 的代码生成器, 支持多表多条件分页查询_第1张图片
//注意mapper.xml不要用 AS 来定义表的别名字段的别名,where标签不要用大写,ew是mybatisplus写死的,不要修改!使用mybatis的@Select注解来写page有bug,例子:

//    @Select(
//            {
//                    ""
//            }
//    )分页使用Select注解有bug,数据不能封装到page里面,所以要写成xml格式

mapper.xml

##导入宏定义
$init
$!define
##引入mybatis支持
$!mybatisSupport

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Dao.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/mapper"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
    #set($pk = $tableInfo.pkColumn.get(0))
#end



<mapper namespace="$!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao">




    <select id="getCascadePageing" resultMap="Mapper">
        SELECT ${ew.sqlSelect} ${query.fromJoinString} ${ew.customSqlSegment}
    select>

    <select id="getCascadeList" resultMap="Mapper">
        SELECT ${ew.sqlSelect} ${query.fromJoinString} ${ew.customSqlSegment}
    select>
mapper>

dao.java

##导入宏定义
$init
$!define
##设置表后缀(宏定义)
#setTableSuffix("Dao")
##保存文件(宏定义)
#save("/dao", "Dao.java")
##包路径(宏定义)
#setPackageSuffix("dao")
import org.apache.ibatis.annotations.Mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;

##表注释(宏定义)
#tableComment("表数据库访问层")
@Mapper
public interface $!{tableName} extends BaseMapper<$tool.append($!tableInfo.name,"Entity")> {

    /**
     * @author $!author   $!time.currTime()
     * 级联分页查询
     */
    Page<$tool.append($!tableInfo.name,"DTO")> getCascadePageing(Page<$tool.append($!tableInfo.name,"DTO")> page,@Param("query") $tool.append($!tableInfo.name,"Query") query, @Param("ew") QueryWrapper<$tool.append($!tableInfo.name,"Entity")> queryWrapper);

    /**
     * @param queryWrapper
     * @author $!author   $!time.currTime()
     * 级联查询
     */
    List<$tool.append($!tableInfo.name,"DTO")> getCascadeList(@Param("query") $tool.append($!tableInfo.name,"Query") query, @Param("ew") QueryWrapper<$tool.append($!tableInfo.name,"Entity")> queryWrapper);
}

serviceImpl.java

##导入宏定义
$init
$!define
##设置表后缀(宏定义)
#setTableSuffix("ServiceImpl")
##保存文件(宏定义)
#save("/service/impl", "ServiceImpl.java")
##包路径(宏定义)
#setPackageSuffix("service.impl")
##定义Dao名
#set($daoName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Dao"))

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

##表注释(宏定义)
#tableComment("表服务实现类")
@Service
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Dao, $tool.append($!tableInfo.name,
    "Entity")> implements $!{tableInfo.name}Service {

    @Autowired
    private $!{tableInfo.name}Dao ${daoName};

    /**
     * @author $!author   $!time.currTime()
     * 是否逻辑删除
     */
    @Override
    public Boolean delFlag(List<Long> ids, DeletedEnum deletedEnum) {
        $tool.append($!tableInfo.name,"Entity") entity = new $tool.append($!tableInfo.name,"Entity")();
        entity.setDelFlag(deletedEnum);
        return this.${daoName}.update(entity, new LambdaQueryWrapper<$tool.append($!tableInfo.name,
    "Entity")>().in($tool.append($!tableInfo.name,"Entity")::getId, ids)) > 0;
    }
    
    /**
     * @author $!author   $!time.currTime()
     * 新增或者修改结果
     */
    @Override
    public Boolean saveOrUpdata($!{tableInfo.name}Entity entity) {
        // TODO: @author $!author   $!time.currTime()

        return null;
    }
    
    /**
     * @author $!author   $!time.currTime()
     * 级联分页查询
     */
    /**
    @Override
    public Result getCascadePageing(Page<$tool.append($!tableInfo.name,"DTO")> page, $tool.append($!tableInfo.name,
    "Query") query) {
        query.setFromJoinString(" FROM t_sys_user_medal tsum " +
                " LEFT JOIN t_app_usermlq tau ON tsum.user_id = tau.id ");
        Page<$tool.append($!tableInfo.name,
    "DTO")> pageing = this.baseMapper.getCascadePageing(page,query, new QueryWrapper<$tool.append($!tableInfo.name,
    "Entity")>()
                .select("tau.name tau_name, " +
                        "tau.rank_name tau_rank_name, " +
                        "tau.id tau_id, " +
                        "tsum.* ")
                .eq("tau.address", "浦东")
                .eq("tsum.del_flag", 0)
                .eq("tsum.user_id", 100000155)
                .orderByDesc("tsum.create_time"));
        return Result.ok().put("data", pageing);
    }

    @Override
    public Result getCascadeList($tool.append($!tableInfo.name,"Query") query) {
        query.setFromJoinString(" FROM t_sys_user_medal tsum " +
                " LEFT JOIN t_app_usermlq tau ON tsum.user_id = tau.id ");
        List<$tool.append($!tableInfo.name,
    "DTO")> cascadeList = this.baseMapper.getCascadeList(query,new QueryWrapper<$tool.append($!tableInfo.name,"Entity")>()
                .select("tau.name tau_name, " +
                        "tau.rank_name tau_rank_name, " +
                        "tau.id tau_id, " +
                        "tsum.* ")
                .eq("tau.address", "浦东")
                .eq("tsum.del_flag", 0)
                .eq("tsum.user_id", 100000155)
                .orderByDesc("tsum.create_time"));
        return Result.ok().put("data", cascadeList);
    }
    */
}

你可能感兴趣的:(mybatis)