在前面的文章里介绍了使用beetl模版生成mybatis-plus后台的增删改查代码。主要方式是通过读取数据库表的元数据信息生成增删改查代码。但是如果我们生成前端网页的话,页面需要指定组件的输入类型,比如输入框、日期组件、下拉组件等,而且还要给下拉组件指定数据字典,且前端页面生成需要设置哪些字段是显示的,哪些字段是隐藏的,哪些字段在列表页中显示、哪些字段在编辑页显示,在列表页中还要设置哪些字段是查询条件字段等等。所以这些信息依靠从数据库拿表中获取注释信息就不能满足我们的需求。

        在基于OpenJWeb的项目开发中,是先在后台界面中录入表结构信息,表字段信息,并定义字段的名称、中文名、类型、输入组件、是否在列表页显示、是否在编辑页显示、是否查询条件字段等等,然后通过低代码生成工具生成后端代码和前端页面。

 一  表结构定义和表字段定义表

        在进行前端页面生成前,先介绍一下comm_table_def表结构定义表和comm_column_def表字段定义表。

        openjweb低代码平台的comm_table_def定义了500多个数据库表,表的DDL语法大家可以从github上下载,在总工程的sql目录的db-mysql.sql中是数据库建表语法,而且comm_table_def和comm_column_def中含完整的表结构定义和表字段定义信息,因为openjweb平台的数据库结构是先在平台上录入数据库表字段信息后,然后根据录入的字段信息创建数据库表的。

        下面是本文示例项目的github下载地址:

GitHub - openjweb/cloud at masterOpenJWeb is a java bases low code platform. Contribute to openjweb/cloud development by creating an account on GitHub.icon-default.png?t=O83Ahttps://github.com/openjweb/cloud/tree/mastercomm_table_def表存储了表名、表中文名、表的说明、所属子系统等,示例数据:

        comm_column_def中定义了表字段信息,包括所属数据库表,表字段名、表字段中文名、数据类型、页面输入组件、是否在列表页显示、是否在编辑页显示、显示的顺序、是否查询条件字段等等。下面是comm_column_def表字段的信息:

cls_field_name 类属性名 clsFieldName
code_sql 反查代码SQL 根据EXCEL字段的文字反查编码 codeSql
column_datatype 字段类型 columnDatatype
column_desc 字段说明 columnDesc
column_digit_len 小数位数 columnDigitLen
column_group 字段分组 对于字段多的表,可进行分组或分Tab展示 columnGroup
column_length 字段长度 columnLength
column_name 字段名 columnName
column_name_cn 字段中文名 columnNameCn
default_value 默认值 defaultValue
default_val_cretype 默认值生成规则 默认值生成规则 defaultValCretype
dict_type_code 数据字典类型 dictTypeCode
edit_sort_no 编辑页显示顺序 editSortNo
input_type 页面输入方式 inputType
is_auth_control 是否控制字段权限 是否控制字段的读写权限 isAuthControl
is_code_col 是否编码字段 是否编码字段 isCodeCol
is_cust_cond 是否定制查询条件列 isCustCond
is_edit_col 是否在编辑页显示 isEditCol
is_excel_key_col 是否EXCEL主键 根据几个EXCEL主键确定是否新记录 isExcelKeyCol
is_export_excel 是否导出EXCEL 是否导出EXCEL isExportExcel
is_list_col 是否列表页面显示 isListCol
is_name_col 是否名称字段 是否名称字段 isNameCol
is_not_null 是否非空 是否非空 isNotNull
is_query_col 是否查询条件列 是否查询条件列 isQueryCol
is_readonly 是否只读 isReadonly
is_search 是否全文检索 isSearch
is_tree_sel_col 是否树分类查询字段 是否树查询节点字段 isTreeSelCol
list_sort_no 列表页显示顺序 listSortNo
name_sql 显示值SQL 用于EXCEL导出由编码查找名称 nameSql
pattern_value 校验正则表达式 校验正则表达式 patternValue
pop_win 弹出窗口 通过参照弹出式窗口输入 popWin
query_type 查询设置 queryType
search_field_type 全文检索字段分类 searchFieldType
serial_no 字段编号 serialNo
table_serial_no 表ID .. tableSerialNo

        现在我们改造一下前面章节介绍的从数据库表的元数据信息生成增删改查页面,改为从comm_table_def和comm_column_def中获取表和表字段信息生成增删改查页面。

        首先在application-dev.yml中设置一下工程的路径和Beetl模板的路径:

openjweb:
  dev:
    javaTemplatePath: D:/project/openjweb-cloud/openjweb-dev/src/main/resources/templates
    rootProjectPath: D:/project/openjweb-cloud

        关于comm_table_def和comm_column_def对应的增删改查程序代码已经由上一篇文章中介绍的代码生成器生成出来了,在这里可以直接使用对应的CommTableDefService和CommColumnDefService的方法开发新的基于这两个表的表结构信息和表字段信息来生成增删改查程序代码,我们在openjweb-dev中创建一个DevUtilV2工具类,代码如下:

        

package org.openjweb.dev.util;

import lombok.extern.slf4j.Slf4j;
import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.Template;
import org.beetl.core.resource.FileResourceLoader;
import org.openjweb.common.util.FileUtil;
import org.openjweb.common.util.StringUtil;
import org.openjweb.core.entity.CommColumnDef;
import org.openjweb.core.entity.CommTableDef;
import org.openjweb.core.module.params.CommColumnDefParam;
import org.openjweb.core.module.params.CommTableDefParam;
import org.openjweb.core.service.CommColumnDefService;
import org.openjweb.core.service.CommTableDefService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class DevUtilV2 {

    @Resource
    private CommTableDefService commTableDefService;

    @Resource
    private CommColumnDefService commColumnDefService;

    //设置Java模版文件路径
    @Value("${openjweb.dev.javaTemplatePath:}") String javaTemplatePath;

    //java主工程的路径
    @Value("${openjweb.dev.rootProjectPath:}") String rootProjectPath;

    //FLOKI TURBO puppies


    public void  createJavaSource(String tableName){
        log.info("查询的表结构名:"+tableName);
        CommTableDefParam param = new CommTableDefParam();
        param.setTableName(tableName);
        CommTableDef tableDef = null;
        List<CommTableDef> list = this.commTableDefService.queryList(param);
        GroupTemplate gt = null;
        Configuration cfg = null;
        Template t = null;


        if(list==null){
            log.info("没查到表结构........");
        }
        else{
            //tableDef = list.get
            log.info("查到表结构......"+String.valueOf(list.size()));

        }
        List<CommColumnDef> colList = null;
        List<Map<String,String>>  colMapList = new ArrayList<>();
        if(list!=null&&list.size()==1){
            tableDef = list.get(0);
            CommColumnDefParam commColumnDefParam = new CommColumnDefParam();
            commColumnDefParam.setTableSerialNo(tableDef.getSerialNo());
            log.info("表结构的serial_No:"+String.valueOf(tableDef.getSerialNo()));
            colList = this.commColumnDefService.queryList(commColumnDefParam);


            if(colList!=null&&colList.size()>0){
                log.info("列数量:"+colList.size());
                for(CommColumnDef entity:colList){
                    String tableId = "";

                    if(entity.getColumnName().toLowerCase().equals("row_id")){
                        //默认ROWID为主键
                        tableId = "@TableId(type = IdType.ASSIGN_UUID)";
                    }
                    Map map = new HashMap();
                    map.put("tableId",tableId);

                    //生成ApiPerperty
                    String colDesc = entity.getColumnDesc();
                    String colField = StringUtil.getFieldNameByColName(entity.getColumnName());
                    map.put("apiProperty","@ApiModelProperty(value =\""+colDesc+"\" )");

                    //下面生成类属性定义
                    String colType = entity.getColumnDatatype().toLowerCase();
                    if(colType.indexOf("varchar")>-1||colType.indexOf("char")>-1
                            ||colType.indexOf("text")>-1||colType.indexOf("clob")>-1 ||colType.indexOf("string")>-1
                            ||colType.indexOf("time")>-1||colType.indexOf("str_")>-1){
                        colType = "String";

                    }
                    else if(colType.equals("number")||colType.endsWith("int")||colType.equals("integer")){
                        colType = "Long";//整数类型
                    }
                    else if(colType.equals("decimal")||colType.equals("numeric")){
                        colType = "Double";
                    }
                    String fieldDeclare = "private "+colType+" "+colField;
                    if(colField.equals("record_version")){
                        log.info("乐观锁字段..........");
                        fieldDeclare   += " = 0L";//乐观锁字段设置默认值
                    }
                    fieldDeclare += ";";
                    map.put("fieldDeclare",fieldDeclare);
                    log.info("map中的fieldName::::"+colField);
                    map.put("fieldName",colField);//类属性名
                    String fieldNameUpper = colField.substring(0,1).toUpperCase()+colField.substring(1);
                    //log.info("fieldNameUpper:");
                    //log.info(fieldNameUpper);

                    map.put("fieldNameUpper",fieldNameUpper);//类属性名
                    map.put("columnName",entity.getColumnName());
                    map.put("fieldNameDesc",entity.getColumnDesc());
                    //对于设置默认值的字段
                    String defaultValueExpr = "";
                    if(entity.getColumnName().toLowerCase().equals("record_version")){
                        defaultValueExpr = "@Version";//乐观锁
                    }
                    else if(entity.getColumnName().toLowerCase().equals("create_dt")){
                        defaultValueExpr = "@TableField(fill = FieldFill.INSERT)";//
                    }
                    else if(entity.getColumnName().toLowerCase().equals("create_uid")){
                        defaultValueExpr = "@TableField(fill = FieldFill.INSERT)";//
                    }
                    else if(entity.getColumnName().toLowerCase().equals("update_dt")){
                        defaultValueExpr = "@TableField(fill = FieldFill.INSERT_UPDATE)";//
                    }
                    else if(entity.getColumnName().toLowerCase().equals("update_uid")){
                        defaultValueExpr = "@TableField(fill = FieldFill.INSERT_UPDATE)";//
                    }
                    map.put("defaultValueExpr",defaultValueExpr);
                    colMapList.add(map);
                }
            }
            else{
                log.info("没查到表字段数量.....");
            }
            String entityClassName = StringUtil.getEntityNameByTableName(tableName);

            log.info("表对应的类名:"+entityClassName);
            String tableDesc =  tableDef.getTableDesc()==null?"":tableDef.getTableDesc();

            //这里暂时硬编码设置下子系统对应的模块路径
            String modulePath = "";
            String packagePath = "";
            String packageName = "";//这个指的是实体类的包路径
            //根据表名转换为类名
            String basePackage = "";



            if(tableName.startsWith("comm_")||tableName.startsWith("sms_")){
                modulePath = "openjweb-core";
                packagePath = "org/openjweb/core/";

            }
            else if(tableName.startsWith("b2c_")){
                modulePath = "openjweb-b2b2c";
                packagePath = "org/openjweb/b2c/";
            }
            else if(tableName.startsWith("cms_")){
                modulePath = "openjweb-cms";
                packagePath = "org/openjweb/cms/";
            }
            else if(tableName.startsWith("sns_")){
                modulePath = "openjweb-sns";
                packagePath = "org/openjweb/sns/";
            }
            else if(tableName.startsWith("weixin_")){
                modulePath = "openjweb-weixin";
                packagePath = "org/openjweb/weixin/";
            }
            else{
                modulePath = "openjweb-core";
                packagePath = "org/openjweb/core/";
            }
            //packageName = packagePath.substring(0,packagePath.length()-1).replace("/","");
            packageName = packagePath.replace("/",".")+"entity";
            basePackage = packagePath.substring(0,packagePath.length()-1).replace("/",".");
            String fullEntityClassName = basePackage+".entity."+entityClassName;


            FileResourceLoader fileResourceLoader = new FileResourceLoader(javaTemplatePath,"utf-8");

            try {
                cfg = Configuration.defaultConfiguration();
                cfg.setCharset("utf-8");//设置文件的字符集
            } catch (IOException e) {
                e.printStackTrace();
            }
            //开始逐个生成,先生成实体类
            gt = new GroupTemplate(fileResourceLoader, cfg);
            t = gt.getTemplate("dev/EntityTemplate.java");
            t.binding("packageName",packageName);
            t.binding("tableDesc",tableDesc);
            t.binding("tableName",tableName);
            t.binding("entityClassName",entityClassName);
            t.binding("fieldList",colMapList);
            String str = null;
            try{
                str = t.render();//模版中的中文昨天没乱码,怎么今天有乱码了?
            }
            catch(Exception ex){
                ex.printStackTrace();
            }
            String saveFilePath = rootProjectPath+"/"+modulePath+"/src/main/java/"+packagePath+"entity/"+entityClassName+".java";
            //生成到文件
            //数据库表关联的包的路径
            try {
                FileUtil.str2file(str,saveFilePath,"utf-8");
            } catch (Exception e) {

                e.printStackTrace();
            }
            log.info("开始生成参数类......");

            gt = new GroupTemplate(fileResourceLoader, cfg);
            t = gt.getTemplate("dev/ParamTemplate.java");
            t.binding("basePackage",basePackage);
            t.binding("fullEntityClassName",fullEntityClassName);
            t.binding("entityClassName",entityClassName);
            str = "";
            try{
                str = t.render();
            }
            catch(Exception ex){
                ex.printStackTrace();
            }
            //log.info("生成的文件内容:"+str);
            //生成到文件
            //String destFilePath = "D:\\project\\openjweb-cloud\\openjweb-dev\\src\\main\\resources\\templates\\dev\\MyDemo.java";
            String paramFileName =  rootProjectPath+"/"+modulePath+"/"+"src/main/java/"+basePackage.replace(".","/")+"/module/params/"+entityClassName+"Param.java";
            try {
                FileUtil.str2file(str,paramFileName,"utf-8");
            } catch (Exception e) {
                e.printStackTrace();
            }
            log.info("生成Mapper类......");
            gt = new GroupTemplate(fileResourceLoader, cfg);
            t = gt.getTemplate("dev/MapperTemplate.java");
            t.binding("basePackage",basePackage);
            t.binding("fullEntityClassName",fullEntityClassName);
            t.binding("entityClassName",entityClassName);
            t.binding("tableName",tableName);
            str = null;
            try{
                str = t.render();
            }
            catch(Exception ex){
                ex.printStackTrace();
            }
            log.info("生成的文件内容:"+str);
            //生成到文件
            //String destFilePath = "D:\\project\\openjweb-cloud\\openjweb-dev\\src\\main\\resources\\templates\\dev\\MyDemo.java";
            paramFileName = rootProjectPath+"/"+modulePath+"/"+"src/main/java/"+basePackage.replace(".","/")+"/mapper/"+entityClassName+"Mapper.java";
            try {
                FileUtil.str2file(str,paramFileName,"utf-8");
            } catch (Exception e) {
                e.printStackTrace();
            }
            ////////////////////////
            log.info("生成Mapping.xml...........");

            gt = new GroupTemplate(fileResourceLoader, cfg);
            t = gt.getTemplate("dev/MapperTemplate.xml");

            //截取basePackage
            t.binding("basePackage",packageName.replace(".entity",""));
            t.binding("fullClassName",packageName+"."+entityClassName);
            t.binding("packageName",packageName);
            t.binding("tableDesc",tableDesc);
            t.binding("tableName",tableName);
            t.binding("entityClassName",entityClassName);
            t.binding("fieldList",colMapList);
            str = null;
            try{
                str = t.render();//模版中的中文昨天没乱码,怎么今天有乱码了?
            }
            catch(Exception ex){
                ex.printStackTrace();
            }
            paramFileName = rootProjectPath+"/"+modulePath+"/"+"src/main/java/"+basePackage.replace(".","/")+"/mapper/mapping/"+entityClassName+"Mapper.xml";

            try {
                FileUtil.str2file(str,paramFileName,"utf-8");
            } catch (Exception e) {
                e.printStackTrace();
            }
            log.info("开始生成Service类..............");
            gt = new GroupTemplate(fileResourceLoader, cfg);
            t = gt.getTemplate("dev/ServiceTemplate.java");
            //截取basePackage
            t.binding("basePackage",packageName.replace(".entity",""));
            t.binding("fullClassName",packageName+"."+entityClassName);
            t.binding("packageName",packageName);
            t.binding("classNameLower",entityClassName.substring(0,1).toLowerCase()+entityClassName.substring(1));
            t.binding("tableDesc",tableDesc);
            t.binding("tableName",tableName);
            t.binding("entityClassName",entityClassName);
            t.binding("fieldList",colMapList);
            str = null;
            try{
                str = t.render();//模版中的中文昨天没乱码,怎么今天有乱码了?
            }
            catch(Exception ex){
                ex.printStackTrace();
            }
            paramFileName = rootProjectPath+"/"+modulePath+"/"+"src/main/java/"+basePackage.replace(".","/")+"/service/"+entityClassName+"Service.java";
            try {
                FileUtil.str2file(str,paramFileName,"utf-8");

            } catch (Exception e) {
                e.printStackTrace();
            }
            log.info("生成控制层类...........");
            gt = new GroupTemplate(fileResourceLoader, cfg);
            t = gt.getTemplate("dev/ControllerTemplate.java");
            t.binding("basePackage",packageName.replace(".entity",""));
            t.binding("fullClassName",packageName+"."+entityClassName);
            t.binding("packageName",packageName);
            t.binding("classNameLower",entityClassName.substring(0,1).toLowerCase()+entityClassName.substring(1));
            t.binding("tableDesc",tableDesc);
            t.binding("tableName",tableName);
            t.binding("entityClassName",entityClassName);
            t.binding("fieldList",colMapList);
            str = null;
            try{
                str = t.render();//模版中的中文昨天没乱码,怎么今天有乱码了?
            }
            catch(Exception ex){
                ex.printStackTrace();

            }
            paramFileName = rootProjectPath+"/"+modulePath+"/"+"src/main/java/"+basePackage.replace(".","/")+"/api/"+entityClassName+"Api.java";
            try {
                FileUtil.str2file(str,paramFileName,"utf-8");

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
         
    }
}

        在上面的代码中,createJavaSource接收一个数据库表名作为参数,在方法内部,查询comm_table_def和comm_column_def中此表的字段定义信息,根据查询结构生成增删改查代码。

        然后我们在openjweb-sys的测试类路径下建一个测试类:

package org.openjweb.sys.testcase;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith; 
import org.openjweb.dev.util.DevUtilV2;
import org.openjweb.sys.OpenjwebSysApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = OpenjwebSysApplication.class)
public class TestDevUtil {
    @Resource
    private DevUtilV2 util;

    @Test
    public void createJavaSource(){
        //String tableName = "b2c_pro_info";//生成商品基本信息表
        log.info("TestDevUtil开始生成源码.........");
        String tableName = "cms_info";//生成cms_info相关增删改查代码
        util.createJavaSource(tableName);
        log.info("TestDevUtil开始生成源码.结束........");
    }
}

        运行测试类,生成的源码在IDEA工程里显示如下(褐色显示的文件名):

我们分别打开这些文件看下生成的效果:

实体类:

package org.openjweb.cms.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 功能说明:内容管理
 */
@Data
@TableName("cms_info")
public class CmsInfo   implements java.io.Serializable {
	
	@ApiModelProperty(value ="null" )
	
	private String actType;
	
	@ApiModelProperty(value ="null" )
	
	private String bannerPic;
	
	@ApiModelProperty(value ="null" )
	
	private String cateTreeCode;
	
	@ApiModelProperty(value ="null" )
	
	private String comId;
	
	@ApiModelProperty(value ="null" )
	@TableField(fill = FieldFill.INSERT)
	private String createDt;
	
	@ApiModelProperty(value ="null" )
	@TableField(fill = FieldFill.INSERT)
	private String createUid;
	
	@ApiModelProperty(value ="null" )
	
	private String dataFlg;
	
	@ApiModelProperty(value ="null" )
	
	private String dateNum;
	
	@ApiModelProperty(value ="null" )
	
	private String deptName;
	
	@ApiModelProperty(value ="null" )
	
	private String deptRowId;
	
	@ApiModelProperty(value ="null" )
	
	private String flowStatus;
	
	@ApiModelProperty(value ="null" )
	
	private String hasSmallImage;
	
	@ApiModelProperty(value ="null" )
	
	private String industName;
	
	@ApiModelProperty(value ="个别信息需要单独的页面样式" )
	
	private String infoJspPage;
	
	@ApiModelProperty(value ="信息作者" )
	
	private String infAuthor;
	
	@ApiModelProperty(value ="点击数" )
	
	private Long infClickCount;
	
	@ApiModelProperty(value ="信息正文" )
	
	private String infContent;
	
	@ApiModelProperty(value ="关键词" )
	
	private String infKeyword;
	
	@ApiModelProperty(value ="null" )
	
	private Long infPicCount;
	
	@ApiModelProperty(value ="信息来源" )
	
	private String infSource;
	
	@ApiModelProperty(value ="信息在首页显示的标题" )
	
	private String infTitle;
	
	@ApiModelProperty(value ="详细信息页面显示的标题" )
	
	private String infTitle2;
	
	@ApiModelProperty(value ="null" )
	
	private String infType;
	
	@ApiModelProperty(value ="URL连接" )
	
	private String infUrl;
	
	@ApiModelProperty(value ="null" )
	
	private String isAddScan;
	
	@ApiModelProperty(value ="是否允许回复或评论" )
	
	private String isAllowFeedback;
	
	@ApiModelProperty(value ="null" )
	
	private String isCateFirst;
	
	@ApiModelProperty(value ="null" )
	
	private String isCreateHtml;
	
	@ApiModelProperty(value ="null" )
	
	private String isEndVideo;
	
	@ApiModelProperty(value ="null" )
	
	private String isHot;
	
	@ApiModelProperty(value ="null" )
	
	private String isJp;
	
	@ApiModelProperty(value ="null" )
	
	private String isPic;
	
	@ApiModelProperty(value ="null" )
	
	private String isRecommend;
	
	@ApiModelProperty(value ="在所属栏目中置顶" )
	
	private String isTop;
	
	@ApiModelProperty(value ="null" )
	
	private String isTrain;
	
	@ApiModelProperty(value ="是否URL连接(URL连接不需要正文)" )
	
	private String isUrl;
	
	@ApiModelProperty(value ="null" )
	
	private String isVideo;
	
	@ApiModelProperty(value ="null" )
	
	private String largeImagePath;
	
	@ApiModelProperty(value ="最后一次同步服务器的时间" )
	
	private String lastSyncDt;
	
	@ApiModelProperty(value ="null" )
	
	private String m3u8Url;
	
	@ApiModelProperty(value ="null" )
	
	private String masterRowId;
	
	@ApiModelProperty(value ="null" )
	
	private String mediaExt;
	
	@ApiModelProperty(value ="null" )
	
	private String mediaId;
	
	@ApiModelProperty(value ="如baidu" )
	
	private String mediaProvider;
	
	@ApiModelProperty(value ="缩略图URL地址" )
	
	private String mediaThumb;
	
	@ApiModelProperty(value ="null" )
	
	private String middleImagePath;
	
	@ApiModelProperty(value ="null" )
	
	private Long mobileSortNo;
	
	@ApiModelProperty(value ="null" )
	
	private String monthNum;
	
	@ApiModelProperty(value ="null" )
	
	private String njContType;
	
	@ApiModelProperty(value ="null" )
	
	private String njExgType;
	
	@ApiModelProperty(value ="null" )
	
	private String njInfSource;
	
	@ApiModelProperty(value ="null" )
	
	private String njSubContType;
	
	@ApiModelProperty(value ="null" )
	
	private String njSubExgType;
	
	@ApiModelProperty(value ="null" )
	
	private String njYear;
	
	@ApiModelProperty(value ="未确定是否使用" )
	
	private String objName;
	
	@ApiModelProperty(value ="null" )
	
	private String otherProvince;
	
	@ApiModelProperty(value ="null" )
	
	private String pkId;
	
	@ApiModelProperty(value ="权重,越小越靠前" )
	
	private Long priorityValue;
	
	@ApiModelProperty(value ="有的信息是与省份关联的" )
	
	private String provinceId;
	
	@ApiModelProperty(value ="信息发布日期" )
	
	private String publishDt;
	
	@ApiModelProperty(value ="根据推广ID生成推广页,如0001" )
	
	private String pubId;
	
	@ApiModelProperty(value ="null" )
	
	private String pubUrl;
	
	@ApiModelProperty(value ="null" )
	
	private String relateRowId;
	@TableId(type = IdType.ASSIGN_UUID)
	@ApiModelProperty(value ="null" )
	
	private String rowId;
	
	@ApiModelProperty(value ="null" )
	
	private String slideImagePath;
	
	@ApiModelProperty(value ="null" )
	
	private String smallImagePath;
	
	@ApiModelProperty(value ="null" )
	
	private Long sortNo;
	
	@ApiModelProperty(value ="null" )
	
	private String sourceUrl;
	
	@ApiModelProperty(value ="null" )
	
	private String subTitle;
	
	@ApiModelProperty(value ="null" )
	
	private String subZtUrl;
	
	@ApiModelProperty(value ="null" )
	
	private String teacherDesc;
	
	@ApiModelProperty(value ="null" )
	
	private String teacherName;
	
	@ApiModelProperty(value ="null" )
	
	private String teacherPhoto;
	
	@ApiModelProperty(value ="null" )
	
	private String trainVideoType;
	
	@ApiModelProperty(value ="为集成商品搜索,为商品增加单价字段" )
	
	private Double unitPrice;
	
	@ApiModelProperty(value ="null" )
	@TableField(fill = FieldFill.INSERT_UPDATE)
	private String updateDt;
	
	@ApiModelProperty(value ="null" )
	@TableField(fill = FieldFill.INSERT_UPDATE)
	private String updateUid;
	
	@ApiModelProperty(value ="null" )
	
	private Long videoCount;
	
	@ApiModelProperty(value ="null" )
	
	private String videoSourcePath;
	
	@ApiModelProperty(value ="null" )
	
	private String videoUrl;
	
	@ApiModelProperty(value ="null" )
	
	private Long wordCount;
	
	@ApiModelProperty(value ="null" )
	
	private String zhuantiTree;
	
	@ApiModelProperty(value ="null" )
	
	private String ztPicTreeCode;

}

实体参数类:

package org.openjweb.cms.module.params;

import lombok.Data;
import org.openjweb.cms.entity.CmsInfo;

@Data
public class CmsInfoParam extends CmsInfo {
    private Integer page=1; //当前页
    private Integer pageSize=20;//每页行数

    public CmsInfoParam() {
        page = 1;
        pageSize = 20;
    }

}

Mapper类:

package org.openjweb.cms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.openjweb.core.entity.CommApiKey;
import org.openjweb.cms.entity.CmsInfo;
import org.openjweb.cms.module.params.CmsInfoParam;

import java.util.List;
@Mapper
public interface CmsInfoMapper extends BaseMapper<CmsInfo> {
    /**
     * 带分页的查询
     * @param page
     * @param param
     * @return
     */

    IPage<CmsInfo> findPage(Page<?> page, @Param("param") CmsInfo param );

    @Select("SELECT * FROM cms_info WHERE row_id = #{rowId}")
        CmsInfo queryByRowId(@Param("rowId") String rowId);

    /**
     * 不带分页的查询
     * @param param
     * @return
     */
    List<CmsInfo> queryList(@Param("param") CmsInfoParam param);


}

Mapper.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.openjweb.cms.mapper.CmsInfoMapper">
    <select id="queryList" resultType="org.openjweb.cms.entity.CmsInfo"  >
        select *  from cms_info
        <where>
            <if test="param.actType !=null ">
                and act_type = #{param.actType}
            </if>
            <if test="param.bannerPic !=null ">
                and banner_pic = #{param.bannerPic}
            </if>
            <if test="param.cateTreeCode !=null ">
                and cate_tree_code = #{param.cateTreeCode}
            </if>
            <if test="param.comId !=null ">
                and com_id = #{param.comId}
            </if>
            <if test="param.createDt !=null ">
                and create_dt = #{param.createDt}
            </if>
            <if test="param.createUid !=null ">
                and create_uid = #{param.createUid}
            </if>
            <if test="param.dataFlg !=null ">
                and data_flg = #{param.dataFlg}
            </if>
            <if test="param.dateNum !=null ">
                and date_num = #{param.dateNum}
            </if>
            <if test="param.deptName !=null ">
                and dept_name = #{param.deptName}
            </if>
            <if test="param.deptRowId !=null ">
                and dept_row_id = #{param.deptRowId}
            </if>
            <if test="param.flowStatus !=null ">
                and flow_status = #{param.flowStatus}
            </if>
            <if test="param.hasSmallImage !=null ">
                and has_small_image = #{param.hasSmallImage}
            </if>
            <if test="param.industName !=null ">
                and indust_name = #{param.industName}
            </if>
            <if test="param.infoJspPage !=null ">
                and info_jsp_page = #{param.infoJspPage}
            </if>
            <if test="param.infAuthor !=null ">
                and inf_author = #{param.infAuthor}
            </if>
            <if test="param.infClickCount !=null ">
                and inf_click_count = #{param.infClickCount}
            </if>
            <if test="param.infContent !=null ">
                and inf_content = #{param.infContent}
            </if>
            <if test="param.infKeyword !=null ">
                and inf_keyword = #{param.infKeyword}
            </if>
            <if test="param.infPicCount !=null ">
                and inf_pic_count = #{param.infPicCount}
            </if>
            <if test="param.infSource !=null ">
                and inf_source = #{param.infSource}
            </if>
            <if test="param.infTitle !=null ">
                and inf_title = #{param.infTitle}
            </if>
            <if test="param.infTitle2 !=null ">
                and inf_title2 = #{param.infTitle2}
            </if>
            <if test="param.infType !=null ">
                and inf_type = #{param.infType}
            </if>
            <if test="param.infUrl !=null ">
                and inf_url = #{param.infUrl}
            </if>
            <if test="param.isAddScan !=null ">
                and is_add_scan = #{param.isAddScan}
            </if>
            <if test="param.isAllowFeedback !=null ">
                and is_allow_feedback = #{param.isAllowFeedback}
            </if>
            <if test="param.isCateFirst !=null ">
                and is_cate_first = #{param.isCateFirst}
            </if>
            <if test="param.isCreateHtml !=null ">
                and is_create_html = #{param.isCreateHtml}
            </if>
            <if test="param.isEndVideo !=null ">
                and is_end_video = #{param.isEndVideo}
            </if>
            <if test="param.isHot !=null ">
                and is_hot = #{param.isHot}
            </if>
            <if test="param.isJp !=null ">
                and is_jp = #{param.isJp}
            </if>
            <if test="param.isPic !=null ">
                and is_pic = #{param.isPic}
            </if>
            <if test="param.isRecommend !=null ">
                and is_recommend = #{param.isRecommend}
            </if>
            <if test="param.isTop !=null ">
                and is_top = #{param.isTop}
            </if>
            <if test="param.isTrain !=null ">
                and is_train = #{param.isTrain}
            </if>
            <if test="param.isUrl !=null ">
                and is_url = #{param.isUrl}
            </if>
            <if test="param.isVideo !=null ">
                and is_video = #{param.isVideo}
            </if>
            <if test="param.largeImagePath !=null ">
                and large_image_path = #{param.largeImagePath}
            </if>
            <if test="param.lastSyncDt !=null ">
                and last_sync_dt = #{param.lastSyncDt}
            </if>
            <if test="param.m3u8Url !=null ">
                and m3u8_url = #{param.m3u8Url}
            </if>
            <if test="param.masterRowId !=null ">
                and master_row_id = #{param.masterRowId}
            </if>
            <if test="param.mediaExt !=null ">
                and media_ext = #{param.mediaExt}
            </if>
            <if test="param.mediaId !=null ">
                and media_id = #{param.mediaId}
            </if>
            <if test="param.mediaProvider !=null ">
                and media_provider = #{param.mediaProvider}
            </if>
            <if test="param.mediaThumb !=null ">
                and media_thumb = #{param.mediaThumb}
            </if>
            <if test="param.middleImagePath !=null ">
                and middle_image_path = #{param.middleImagePath}
            </if>
            <if test="param.mobileSortNo !=null ">
                and mobile_sort_no = #{param.mobileSortNo}
            </if>
            <if test="param.monthNum !=null ">
                and month_num = #{param.monthNum}
            </if>
            <if test="param.njContType !=null ">
                and nj_cont_type = #{param.njContType}
            </if>
            <if test="param.njExgType !=null ">
                and nj_exg_type = #{param.njExgType}
            </if>
            <if test="param.njInfSource !=null ">
                and nj_inf_source = #{param.njInfSource}
            </if>
            <if test="param.njSubContType !=null ">
                and nj_sub_cont_type = #{param.njSubContType}
            </if>
            <if test="param.njSubExgType !=null ">
                and nj_sub_exg_type = #{param.njSubExgType}
            </if>
            <if test="param.njYear !=null ">
                and nj_year = #{param.njYear}
            </if>
            <if test="param.objName !=null ">
                and obj_name = #{param.objName}
            </if>
            <if test="param.otherProvince !=null ">
                and other_province = #{param.otherProvince}
            </if>
            <if test="param.pkId !=null ">
                and pk_id = #{param.pkId}
            </if>
            <if test="param.priorityValue !=null ">
                and priority_value = #{param.priorityValue}
            </if>
            <if test="param.provinceId !=null ">
                and province_id = #{param.provinceId}
            </if>
            <if test="param.publishDt !=null ">
                and publish_dt = #{param.publishDt}
            </if>
            <if test="param.pubId !=null ">
                and pub_id = #{param.pubId}
            </if>
            <if test="param.pubUrl !=null ">
                and pub_url = #{param.pubUrl}
            </if>
            <if test="param.relateRowId !=null ">
                and relate_row_id = #{param.relateRowId}
            </if>
            <if test="param.rowId !=null ">
                and row_id = #{param.rowId}
            </if>
            <if test="param.slideImagePath !=null ">
                and slide_image_path = #{param.slideImagePath}
            </if>
            <if test="param.smallImagePath !=null ">
                and small_image_path = #{param.smallImagePath}
            </if>
            <if test="param.sortNo !=null ">
                and sort_no = #{param.sortNo}
            </if>
            <if test="param.sourceUrl !=null ">
                and source_url = #{param.sourceUrl}
            </if>
            <if test="param.subTitle !=null ">
                and sub_title = #{param.subTitle}
            </if>
            <if test="param.subZtUrl !=null ">
                and sub_zt_url = #{param.subZtUrl}
            </if>
            <if test="param.teacherDesc !=null ">
                and teacher_desc = #{param.teacherDesc}
            </if>
            <if test="param.teacherName !=null ">
                and teacher_name = #{param.teacherName}
            </if>
            <if test="param.teacherPhoto !=null ">
                and teacher_photo = #{param.teacherPhoto}
            </if>
            <if test="param.trainVideoType !=null ">
                and train_video_type = #{param.trainVideoType}
            </if>
            <if test="param.unitPrice !=null ">
                and unit_price = #{param.unitPrice}
            </if>
            <if test="param.updateDt !=null ">
                and update_dt = #{param.updateDt}
            </if>
            <if test="param.updateUid !=null ">
                and update_uid = #{param.updateUid}
            </if>
            <if test="param.videoCount !=null ">
                and video_count = #{param.videoCount}
            </if>
            <if test="param.videoSourcePath !=null ">
                and video_source_path = #{param.videoSourcePath}
            </if>
            <if test="param.videoUrl !=null ">
                and video_url = #{param.videoUrl}
            </if>
            <if test="param.wordCount !=null ">
                and word_count = #{param.wordCount}
            </if>
            <if test="param.zhuantiTree !=null ">
                and zhuanti_tree = #{param.zhuantiTree}
            </if>
            <if test="param.ztPicTreeCode !=null ">
                and zt_pic_tree_code = #{param.ztPicTreeCode}
            </if>


        </where>
    </select>


    <select id="findPage" resultType="org.openjweb.cms.entity.CmsInfo"  >
        select *  from cms_info
        <if test="param.actType !=null ">
            and act_type = #{param.actType}
        </if>
        <if test="param.bannerPic !=null ">
            and banner_pic = #{param.bannerPic}
        </if>
        <if test="param.cateTreeCode !=null ">
            and cate_tree_code = #{param.cateTreeCode}
        </if>
        <if test="param.comId !=null ">
            and com_id = #{param.comId}
        </if>
        <if test="param.createDt !=null ">
            and create_dt = #{param.createDt}
        </if>
        <if test="param.createUid !=null ">
            and create_uid = #{param.createUid}
        </if>
        <if test="param.dataFlg !=null ">
            and data_flg = #{param.dataFlg}
        </if>
        <if test="param.dateNum !=null ">
            and date_num = #{param.dateNum}
        </if>
        <if test="param.deptName !=null ">
            and dept_name = #{param.deptName}
        </if>
        <if test="param.deptRowId !=null ">
            and dept_row_id = #{param.deptRowId}
        </if>
        <if test="param.flowStatus !=null ">
            and flow_status = #{param.flowStatus}
        </if>
        <if test="param.hasSmallImage !=null ">
            and has_small_image = #{param.hasSmallImage}
        </if>
        <if test="param.industName !=null ">
            and indust_name = #{param.industName}
        </if>
        <if test="param.infoJspPage !=null ">
            and info_jsp_page = #{param.infoJspPage}
        </if>
        <if test="param.infAuthor !=null ">
            and inf_author = #{param.infAuthor}
        </if>
        <if test="param.infClickCount !=null ">
            and inf_click_count = #{param.infClickCount}
        </if>
        <if test="param.infContent !=null ">
            and inf_content = #{param.infContent}
        </if>
        <if test="param.infKeyword !=null ">
            and inf_keyword = #{param.infKeyword}
        </if>
        <if test="param.infPicCount !=null ">
            and inf_pic_count = #{param.infPicCount}
        </if>
        <if test="param.infSource !=null ">
            and inf_source = #{param.infSource}
        </if>
        <if test="param.infTitle !=null ">
            and inf_title = #{param.infTitle}
        </if>
        <if test="param.infTitle2 !=null ">
            and inf_title2 = #{param.infTitle2}
        </if>
        <if test="param.infType !=null ">
            and inf_type = #{param.infType}
        </if>
        <if test="param.infUrl !=null ">
            and inf_url = #{param.infUrl}
        </if>
        <if test="param.isAddScan !=null ">
            and is_add_scan = #{param.isAddScan}
        </if>
        <if test="param.isAllowFeedback !=null ">
            and is_allow_feedback = #{param.isAllowFeedback}
        </if>
        <if test="param.isCateFirst !=null ">
            and is_cate_first = #{param.isCateFirst}
        </if>
        <if test="param.isCreateHtml !=null ">
            and is_create_html = #{param.isCreateHtml}
        </if>
        <if test="param.isEndVideo !=null ">
            and is_end_video = #{param.isEndVideo}
        </if>
        <if test="param.isHot !=null ">
            and is_hot = #{param.isHot}
        </if>
        <if test="param.isJp !=null ">
            and is_jp = #{param.isJp}
        </if>
        <if test="param.isPic !=null ">
            and is_pic = #{param.isPic}
        </if>
        <if test="param.isRecommend !=null ">
            and is_recommend = #{param.isRecommend}
        </if>
        <if test="param.isTop !=null ">
            and is_top = #{param.isTop}
        </if>
        <if test="param.isTrain !=null ">
            and is_train = #{param.isTrain}
        </if>
        <if test="param.isUrl !=null ">
            and is_url = #{param.isUrl}
        </if>
        <if test="param.isVideo !=null ">
            and is_video = #{param.isVideo}
        </if>
        <if test="param.largeImagePath !=null ">
            and large_image_path = #{param.largeImagePath}
        </if>
        <if test="param.lastSyncDt !=null ">
            and last_sync_dt = #{param.lastSyncDt}
        </if>
        <if test="param.m3u8Url !=null ">
            and m3u8_url = #{param.m3u8Url}
        </if>
        <if test="param.masterRowId !=null ">
            and master_row_id = #{param.masterRowId}
        </if>
        <if test="param.mediaExt !=null ">
            and media_ext = #{param.mediaExt}
        </if>
        <if test="param.mediaId !=null ">
            and media_id = #{param.mediaId}
        </if>
        <if test="param.mediaProvider !=null ">
            and media_provider = #{param.mediaProvider}
        </if>
        <if test="param.mediaThumb !=null ">
            and media_thumb = #{param.mediaThumb}
        </if>
        <if test="param.middleImagePath !=null ">
            and middle_image_path = #{param.middleImagePath}
        </if>
        <if test="param.mobileSortNo !=null ">
            and mobile_sort_no = #{param.mobileSortNo}
        </if>
        <if test="param.monthNum !=null ">
            and month_num = #{param.monthNum}
        </if>
        <if test="param.njContType !=null ">
            and nj_cont_type = #{param.njContType}
        </if>
        <if test="param.njExgType !=null ">
            and nj_exg_type = #{param.njExgType}
        </if>
        <if test="param.njInfSource !=null ">
            and nj_inf_source = #{param.njInfSource}
        </if>
        <if test="param.njSubContType !=null ">
            and nj_sub_cont_type = #{param.njSubContType}
        </if>
        <if test="param.njSubExgType !=null ">
            and nj_sub_exg_type = #{param.njSubExgType}
        </if>
        <if test="param.njYear !=null ">
            and nj_year = #{param.njYear}
        </if>
        <if test="param.objName !=null ">
            and obj_name = #{param.objName}
        </if>
        <if test="param.otherProvince !=null ">
            and other_province = #{param.otherProvince}
        </if>
        <if test="param.pkId !=null ">
            and pk_id = #{param.pkId}
        </if>
        <if test="param.priorityValue !=null ">
            and priority_value = #{param.priorityValue}
        </if>
        <if test="param.provinceId !=null ">
            and province_id = #{param.provinceId}
        </if>
        <if test="param.publishDt !=null ">
            and publish_dt = #{param.publishDt}
        </if>
        <if test="param.pubId !=null ">
            and pub_id = #{param.pubId}
        </if>
        <if test="param.pubUrl !=null ">
            and pub_url = #{param.pubUrl}
        </if>
        <if test="param.relateRowId !=null ">
            and relate_row_id = #{param.relateRowId}
        </if>
        <if test="param.rowId !=null ">
            and row_id = #{param.rowId}
        </if>
        <if test="param.slideImagePath !=null ">
            and slide_image_path = #{param.slideImagePath}
        </if>
        <if test="param.smallImagePath !=null ">
            and small_image_path = #{param.smallImagePath}
        </if>
        <if test="param.sortNo !=null ">
            and sort_no = #{param.sortNo}
        </if>
        <if test="param.sourceUrl !=null ">
            and source_url = #{param.sourceUrl}
        </if>
        <if test="param.subTitle !=null ">
            and sub_title = #{param.subTitle}
        </if>
        <if test="param.subZtUrl !=null ">
            and sub_zt_url = #{param.subZtUrl}
        </if>
        <if test="param.teacherDesc !=null ">
            and teacher_desc = #{param.teacherDesc}
        </if>
        <if test="param.teacherName !=null ">
            and teacher_name = #{param.teacherName}
        </if>
        <if test="param.teacherPhoto !=null ">
            and teacher_photo = #{param.teacherPhoto}
        </if>
        <if test="param.trainVideoType !=null ">
            and train_video_type = #{param.trainVideoType}
        </if>
        <if test="param.unitPrice !=null ">
            and unit_price = #{param.unitPrice}
        </if>
        <if test="param.updateDt !=null ">
            and update_dt = #{param.updateDt}
        </if>
        <if test="param.updateUid !=null ">
            and update_uid = #{param.updateUid}
        </if>
        <if test="param.videoCount !=null ">
            and video_count = #{param.videoCount}
        </if>
        <if test="param.videoSourcePath !=null ">
            and video_source_path = #{param.videoSourcePath}
        </if>
        <if test="param.videoUrl !=null ">
            and video_url = #{param.videoUrl}
        </if>
        <if test="param.wordCount !=null ">
            and word_count = #{param.wordCount}
        </if>
        <if test="param.zhuantiTree !=null ">
            and zhuanti_tree = #{param.zhuantiTree}
        </if>
        <if test="param.ztPicTreeCode !=null ">
            and zt_pic_tree_code = #{param.ztPicTreeCode}
        </if>
    </select>

</mapper>

service类:

package org.openjweb.cms.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.openjweb.cms.entity.CmsInfo;
import org.openjweb.cms.mapper.CmsInfoMapper;
import org.openjweb.cms.module.params.CmsInfoParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
@Slf4j
public class CmsInfoService  extends ServiceImpl<CmsInfoMapper, CmsInfo> {
    @Autowired
    private CmsInfoMapper cmsInfoMapper;

    /**
     * 根据ROWID查询
     * @param rowId
     * @return
     */
    public CmsInfo queryByRowId(String rowId){
        return this.cmsInfoMapper.queryByRowId(rowId);
    }

    public List<CmsInfo> queryList(CmsInfoParam param){
        List list = this.cmsInfoMapper.queryList(param);
        return list;
    }


    /**
     * 分页查询
     * @param param
     * @return
     */

    public  IPage<CmsInfo> findPage(CmsInfoParam param){
        Page<CmsInfo> page = new Page<>(param.getPage(), param.getPageSize());

        IPage<CmsInfo> list = this.cmsInfoMapper.findPage(page,param);
        return list;
    }

    /**
     * 批量删除
     * @param selectedIds
     * @throws Exception
     */
    public void del(String selectedIds) throws  Exception {
        String[] ids = null;
        int delCount = 0;
        if(selectedIds!=null&&selectedIds.trim().length()>0){
            ids = selectedIds.split(",");
            //System.out.println(ids.length);
            List<String> parmList = Arrays.asList(ids);
            delCount = this.cmsInfoMapper.deleteBatchIds(parmList);
            //this.commApiKeyMapper.
        }
        if(delCount==0){
            throw new  Exception ("删除失败!");
        }
    }
}

Api接口类:


package org.openjweb.cms.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.openjweb.common.response.ResponseResult;
import org.openjweb.cms.entity.CmsInfo;
import org.openjweb.cms.module.params.CmsInfoParam;
import org.openjweb.cms.service.CmsInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 测试:
 */
@Api(tags = "内容管理")
@Slf4j
@RestController
@RequestMapping("/demo/api/cmsInfo")
public class CmsInfoApi {
    @Autowired
    private CmsInfoService cmsInfoService;

    /**
     * 新增记录

     */

    @ApiOperation("保存内容管理")
    @ApiImplicitParams({
           @ApiImplicitParam(name = "actType", value = "", paramType = "query"),
           @ApiImplicitParam(name = "bannerPic", value = "", paramType = "query"),
           @ApiImplicitParam(name = "cateTreeCode", value = "", paramType = "query"),
           @ApiImplicitParam(name = "comId", value = "", paramType = "query"),
           @ApiImplicitParam(name = "createDt", value = "", paramType = "query"),
           @ApiImplicitParam(name = "createUid", value = "", paramType = "query"),
           @ApiImplicitParam(name = "dataFlg", value = "", paramType = "query"),
           @ApiImplicitParam(name = "dateNum", value = "", paramType = "query"),
           @ApiImplicitParam(name = "deptName", value = "", paramType = "query"),
           @ApiImplicitParam(name = "deptRowId", value = "", paramType = "query"),
           @ApiImplicitParam(name = "flowStatus", value = "", paramType = "query"),
           @ApiImplicitParam(name = "hasSmallImage", value = "", paramType = "query"),
           @ApiImplicitParam(name = "industName", value = "", paramType = "query"),
           @ApiImplicitParam(name = "infoJspPage", value = "个别信息需要单独的页面样式", paramType = "query"),
           @ApiImplicitParam(name = "infAuthor", value = "信息作者", paramType = "query"),
           @ApiImplicitParam(name = "infClickCount", value = "点击数", paramType = "query"),
           @ApiImplicitParam(name = "infContent", value = "信息正文", paramType = "query"),
           @ApiImplicitParam(name = "infKeyword", value = "关键词", paramType = "query"),
           @ApiImplicitParam(name = "infPicCount", value = "", paramType = "query"),
           @ApiImplicitParam(name = "infSource", value = "信息来源", paramType = "query"),
           @ApiImplicitParam(name = "infTitle", value = "信息在首页显示的标题", paramType = "query"),
           @ApiImplicitParam(name = "infTitle2", value = "详细信息页面显示的标题", paramType = "query"),
           @ApiImplicitParam(name = "infType", value = "", paramType = "query"),
           @ApiImplicitParam(name = "infUrl", value = "URL连接", paramType = "query"),
           @ApiImplicitParam(name = "isAddScan", value = "", paramType = "query"),
           @ApiImplicitParam(name = "isAllowFeedback", value = "是否允许回复或评论", paramType = "query"),
           @ApiImplicitParam(name = "isCateFirst", value = "", paramType = "query"),
           @ApiImplicitParam(name = "isCreateHtml", value = "", paramType = "query"),
           @ApiImplicitParam(name = "isEndVideo", value = "", paramType = "query"),
           @ApiImplicitParam(name = "isHot", value = "", paramType = "query"),
           @ApiImplicitParam(name = "isJp", value = "", paramType = "query"),
           @ApiImplicitParam(name = "isPic", value = "", paramType = "query"),
           @ApiImplicitParam(name = "isRecommend", value = "", paramType = "query"),
           @ApiImplicitParam(name = "isTop", value = "在所属栏目中置顶", paramType = "query"),
           @ApiImplicitParam(name = "isTrain", value = "", paramType = "query"),
           @ApiImplicitParam(name = "isUrl", value = "是否URL连接(URL连接不需要正文)", paramType = "query"),
           @ApiImplicitParam(name = "isVideo", value = "", paramType = "query"),
           @ApiImplicitParam(name = "largeImagePath", value = "", paramType = "query"),
           @ApiImplicitParam(name = "lastSyncDt", value = "最后一次同步服务器的时间", paramType = "query"),
           @ApiImplicitParam(name = "m3u8Url", value = "", paramType = "query"),
           @ApiImplicitParam(name = "masterRowId", value = "", paramType = "query"),
           @ApiImplicitParam(name = "mediaExt", value = "", paramType = "query"),
           @ApiImplicitParam(name = "mediaId", value = "", paramType = "query"),
           @ApiImplicitParam(name = "mediaProvider", value = "如baidu", paramType = "query"),
           @ApiImplicitParam(name = "mediaThumb", value = "缩略图URL地址", paramType = "query"),
           @ApiImplicitParam(name = "middleImagePath", value = "", paramType = "query"),
           @ApiImplicitParam(name = "mobileSortNo", value = "", paramType = "query"),
           @ApiImplicitParam(name = "monthNum", value = "", paramType = "query"),
           @ApiImplicitParam(name = "njContType", value = "", paramType = "query"),
           @ApiImplicitParam(name = "njExgType", value = "", paramType = "query"),
           @ApiImplicitParam(name = "njInfSource", value = "", paramType = "query"),
           @ApiImplicitParam(name = "njSubContType", value = "", paramType = "query"),
           @ApiImplicitParam(name = "njSubExgType", value = "", paramType = "query"),
           @ApiImplicitParam(name = "njYear", value = "", paramType = "query"),
           @ApiImplicitParam(name = "objName", value = "未确定是否使用", paramType = "query"),
           @ApiImplicitParam(name = "otherProvince", value = "", paramType = "query"),
           @ApiImplicitParam(name = "pkId", value = "", paramType = "query"),
           @ApiImplicitParam(name = "priorityValue", value = "权重,越小越靠前", paramType = "query"),
           @ApiImplicitParam(name = "provinceId", value = "有的信息是与省份关联的", paramType = "query"),
           @ApiImplicitParam(name = "publishDt", value = "信息发布日期", paramType = "query"),
           @ApiImplicitParam(name = "pubId", value = "根据推广ID生成推广页,如0001", paramType = "query"),
           @ApiImplicitParam(name = "pubUrl", value = "", paramType = "query"),
           @ApiImplicitParam(name = "relateRowId", value = "", paramType = "query"),
           @ApiImplicitParam(name = "rowId", value = "", paramType = "query"),
           @ApiImplicitParam(name = "slideImagePath", value = "", paramType = "query"),
           @ApiImplicitParam(name = "smallImagePath", value = "", paramType = "query"),
           @ApiImplicitParam(name = "sortNo", value = "", paramType = "query"),
           @ApiImplicitParam(name = "sourceUrl", value = "", paramType = "query"),
           @ApiImplicitParam(name = "subTitle", value = "", paramType = "query"),
           @ApiImplicitParam(name = "subZtUrl", value = "", paramType = "query"),
           @ApiImplicitParam(name = "teacherDesc", value = "", paramType = "query"),
           @ApiImplicitParam(name = "teacherName", value = "", paramType = "query"),
           @ApiImplicitParam(name = "teacherPhoto", value = "", paramType = "query"),
           @ApiImplicitParam(name = "trainVideoType", value = "", paramType = "query"),
           @ApiImplicitParam(name = "unitPrice", value = "为集成商品搜索,为商品增加单价字段", paramType = "query"),
           @ApiImplicitParam(name = "updateDt", value = "", paramType = "query"),
           @ApiImplicitParam(name = "updateUid", value = "", paramType = "query"),
           @ApiImplicitParam(name = "videoCount", value = "", paramType = "query"),
           @ApiImplicitParam(name = "videoSourcePath", value = "", paramType = "query"),
           @ApiImplicitParam(name = "videoUrl", value = "", paramType = "query"),
           @ApiImplicitParam(name = "wordCount", value = "", paramType = "query"),
           @ApiImplicitParam(name = "zhuantiTree", value = "", paramType = "query"),
           @ApiImplicitParam(name = "ztPicTreeCode", value = "", paramType = "query"),
    })

    @RequestMapping("/save")
    public ResponseResult save( CmsInfoParam param){
        try {
            log.info("新增记录调用开始..........");


            this.cmsInfoService.save(param);
            log.info("新增记录调用结束..........");
            return ResponseResult.okResult(0,"新增成功!");
        }
        catch(Exception  ex){
            ex.printStackTrace();
            return ResponseResult.errorResult(-1,"新增失败!");
        }

    }

    /**
     * 新增或修改记录
     * @param param
     * @return
     */

    @RequestMapping("saveOrUpdate")
    public ResponseResult saveOrUpdate( CmsInfoParam param){
        if(param==null){
            return ResponseResult.errorResult(-1,"未传入参数.....");
        }
        try {
            String rowId = param.getRowId();
            log.info("根据rowId查询实体开始..........");
            CmsInfo ent = this.cmsInfoService.queryByRowId(param.getRowId());
            if(ent!=null) {
                //复制修改的参数

                ent.setActType(param.getActType());
                ent.setBannerPic(param.getBannerPic());
                ent.setCateTreeCode(param.getCateTreeCode());
                ent.setComId(param.getComId());
                ent.setCreateDt(param.getCreateDt());
                ent.setCreateUid(param.getCreateUid());
                ent.setDataFlg(param.getDataFlg());
                ent.setDateNum(param.getDateNum());
                ent.setDeptName(param.getDeptName());
                ent.setDeptRowId(param.getDeptRowId());
                ent.setFlowStatus(param.getFlowStatus());
                ent.setHasSmallImage(param.getHasSmallImage());
                ent.setIndustName(param.getIndustName());
                ent.setInfoJspPage(param.getInfoJspPage());
                ent.setInfAuthor(param.getInfAuthor());
                ent.setInfClickCount(param.getInfClickCount());
                ent.setInfContent(param.getInfContent());
                ent.setInfKeyword(param.getInfKeyword());
                ent.setInfPicCount(param.getInfPicCount());
                ent.setInfSource(param.getInfSource());
                ent.setInfTitle(param.getInfTitle());
                ent.setInfTitle2(param.getInfTitle2());
                ent.setInfType(param.getInfType());
                ent.setInfUrl(param.getInfUrl());
                ent.setIsAddScan(param.getIsAddScan());
                ent.setIsAllowFeedback(param.getIsAllowFeedback());
                ent.setIsCateFirst(param.getIsCateFirst());
                ent.setIsCreateHtml(param.getIsCreateHtml());
                ent.setIsEndVideo(param.getIsEndVideo());
                ent.setIsHot(param.getIsHot());
                ent.setIsJp(param.getIsJp());
                ent.setIsPic(param.getIsPic());
                ent.setIsRecommend(param.getIsRecommend());
                ent.setIsTop(param.getIsTop());
                ent.setIsTrain(param.getIsTrain());
                ent.setIsUrl(param.getIsUrl());
                ent.setIsVideo(param.getIsVideo());
                ent.setLargeImagePath(param.getLargeImagePath());
                ent.setLastSyncDt(param.getLastSyncDt());
                ent.setM3u8Url(param.getM3u8Url());
                ent.setMasterRowId(param.getMasterRowId());
                ent.setMediaExt(param.getMediaExt());
                ent.setMediaId(param.getMediaId());
                ent.setMediaProvider(param.getMediaProvider());
                ent.setMediaThumb(param.getMediaThumb());
                ent.setMiddleImagePath(param.getMiddleImagePath());
                ent.setMobileSortNo(param.getMobileSortNo());
                ent.setMonthNum(param.getMonthNum());
                ent.setNjContType(param.getNjContType());
                ent.setNjExgType(param.getNjExgType());
                ent.setNjInfSource(param.getNjInfSource());
                ent.setNjSubContType(param.getNjSubContType());
                ent.setNjSubExgType(param.getNjSubExgType());
                ent.setNjYear(param.getNjYear());
                ent.setObjName(param.getObjName());
                ent.setOtherProvince(param.getOtherProvince());
                ent.setPkId(param.getPkId());
                ent.setPriorityValue(param.getPriorityValue());
                ent.setProvinceId(param.getProvinceId());
                ent.setPublishDt(param.getPublishDt());
                ent.setPubId(param.getPubId());
                ent.setPubUrl(param.getPubUrl());
                ent.setRelateRowId(param.getRelateRowId());
                ent.setRowId(param.getRowId());
                ent.setSlideImagePath(param.getSlideImagePath());
                ent.setSmallImagePath(param.getSmallImagePath());
                ent.setSortNo(param.getSortNo());
                ent.setSourceUrl(param.getSourceUrl());
                ent.setSubTitle(param.getSubTitle());
                ent.setSubZtUrl(param.getSubZtUrl());
                ent.setTeacherDesc(param.getTeacherDesc());
                ent.setTeacherName(param.getTeacherName());
                ent.setTeacherPhoto(param.getTeacherPhoto());
                ent.setTrainVideoType(param.getTrainVideoType());
                ent.setUnitPrice(param.getUnitPrice());
                ent.setUpdateDt(param.getUpdateDt());
                ent.setUpdateUid(param.getUpdateUid());
                ent.setVideoCount(param.getVideoCount());
                ent.setVideoSourcePath(param.getVideoSourcePath());
                ent.setVideoUrl(param.getVideoUrl());
                ent.setWordCount(param.getWordCount());
                ent.setZhuantiTree(param.getZhuantiTree());
                ent.setZtPicTreeCode(param.getZtPicTreeCode());
                this.cmsInfoService.updateById(ent);
            }
            else{
                log.info("没找到实体类..,新增...");

                this.cmsInfoService.save(param);
            }
            log.info("保存完毕..........");
        }
        catch(Exception  ex){
            ex.printStackTrace();
            return ResponseResult.errorResult(-1,"新增失败!");
        }
        return ResponseResult.okResult(0,"success");



    }

    /**
     * 查询列表不分页
     * @param param
     * @return
     */

    @RequestMapping("query")
    public ResponseResult queryList(CmsInfoParam param ){


        List<CmsInfo> list = null;
        try{
            list = this.cmsInfoService.queryList(param);
        }
        catch(Exception ex){
            log.error("异常::::"+ex.toString());
            return ResponseResult.errorResult(-1,ex.toString());
        }

        return ResponseResult.okResult(list);

    }



    /**
     * 查询单条记录
     * @param rowId
     * @return
     */
    @RequestMapping("edit")

    public ResponseResult edit(String rowId){
        CmsInfo ent = this.cmsInfoService.queryByRowId(rowId);
        return ResponseResult.okResult(ent);

    }

    /**
     * 分页查询
     * @param param
     * @return
     */

    @RequestMapping("findPage")

    public ResponseResult findPage(CmsInfoParam param){
        IPage<CmsInfo> page = this.cmsInfoService.findPage(param);
        return ResponseResult.okResult(page);

    }

}

        API接口类演示了自带Swagger注解。我们启动工程后可以看到swagger可以显示我们生成的接口文档(http://localhost:8001/login登录后访问http://localhost:8001/doc.html):

完整代码示例见github:

https://github.com/openjweb/cloud/tree/mastericon-default.png?t=O83Ahttps://github.com/openjweb/cloud/tree/master

Logo

这里是“一人公司”的成长家园。我们提供从产品曝光、技术变现到法律财税的全栈内容,并连接云服务、办公空间等稀缺资源,助你专注创造,无忧运营。

更多推荐