javaweb代码生成器,专注于javaweb项通用目的代码生成器

该项目为javaWEB项目通用代码生成器,根据数据库表和自定义代码模板生成相应的jsp,js,java文件,生成到指定路径下,javaweb项目开发利器;

项目开源地址:https://gitee.com/okrs.cn/CodeGenerator

代码生成器:
该项目为代码生成器 基于Apache Velocity的 Java模板引擎
base_build文件夹为最原始代码
为整理后的版本
执行:
com.mmk.BaseApplication.java或生成jar包:run Maven intall


访问路径:http://localhost:10001/codeUI/index.html


不可用ip 访问

登录界面输入的是作者 




 

模板加载地址:

resources/static/template.json


添加模板地址:
src/main/resources/


 


com.mmk.code.common.PropertyNameTools.java 设置表初始加载的时候数据库字段类型对应的实体字段类型








#foreach($field in $fieldList)
 #if($!{velocityCount}==$!{fieldList.size()})//当循环到最后一个时
 " s.${field.columnName}"+
#else
 " s.${field.columnName},"+
#end 
   #end;
   
   $fieldList 字段列表
    ${field.comment} 字段描述
${field.columnName}数据库字段名称
${field.inputType} 数据库类型
${field.validate}
${field.field} 实体字段名称
${field.fieldUp} 实体字段名称大写
${field.type} 实体字段类型

$field.findBy) 启用特殊方法findBy


以上对应字段值设置
\resources\static\codeUI\app\store
${field.inputType}=="input"
#if($field.validate=="mobile")lay-verify="phone"#elseif(!$field.nullable)lay-verify="required"#end
#if( $field.type == "Date")



${model.packageName}.${model.modulePackage}
${model.model}大写 实体名字
${model.modelL}首字母小写 实体名字
${model.comment}


*@author ${model.author} ${date}


${model.tableName} 数据库名字


表单验证:
 <input type="text"  name="${field.field}" placeholder="请输入${field.comment}" autocomplete="off"  data-rule="${field.comment};required;#if(${field.validate})${field.validate};" data-msg="不符合规则" #else " #end value="${${model.modelL}.${field.field}}"/>

生成:
 <input type="text"  name="type" placeholder="请输入违规类型,0-一般,1-严重" autocomplete="off"  data-rule="违规类型,0-一般,1-严重;required;number;" data-msg="不符合规则"  value="${cbViolateNotice.type}"/>
                       
   


sql拼接
#if($field.type=="String")
#if($field.matchType == 'any')
        sql.append(" and s.name like '%").append(search_name).append("%'");
#elseif($field.matchType == 'eq')
        if(StringUtils.isNotBlank(condition.get${field.fieldUp}())){
            sb.append(" and ${field.columnName} = ?$!{velocityCount} ");
            params.put($!{velocityCount},condition.get${field.fieldUp}());
        }
#elseif($field.matchType == 'left')
        if(StringUtils.isNotBlank(condition.get${field.fieldUp}())){
            sb.append(" and ${field.columnName} like ?$!{velocityCount} ");
            params.put($!{velocityCount},condition.get${field.fieldUp}()+"%");
        }
#elseif($field.matchType == 'right')
        if(StringUtils.isNotBlank(condition.get${field.fieldUp}())){
            sb.append(" and ${field.columnName} like ?$!{velocityCount} ");
            params.put($!{velocityCount},"%"+condition.get${field.fieldUp}());
        }
#elseif($field.matchType == 'dateRange')
        if(condition.get${field.fieldUp}Begin()!=null){
            sb.append(" and ${field.columnName} >= ?$!{velocityCount} ");
            params.put($!{velocityCount},condition.get${field.fieldUp}Begin());
        }
        if(condition.get${field.fieldUp}End()!=null){
            sb.append(" and ${field.columnName} >= ?$!{velocityCount} ");
            params.put($!{velocityCount},condition.get${field.fieldUp}End());
        }
#end
#else
#if($field.matchType != 'none')
        if(condition.get${field.fieldUp}()!=null){
            sb.append(" and ${field.columnName} = ?$!{velocityCount} ");
            params.put($!{velocityCount},condition.get${field.fieldUp}());
        }
#end
#end


模拟文件结构不能更改,删除其中的文件会报错




注意:
1、生成代码的时候会直接覆盖
2、maven 生成的jar包 会存在乱码问题:解决方式:命令行中执行  java -Dfile.encoding=utf-8 -jar APA_BUILD-1.0.0.jar


-------------------------------------------------------------------
 


1、生成代码的时候会直接覆盖
2、必须设计表的时候
字段填写注释
表上填写注释
3、数据库中设计必须有:id(自增),code(uuid,标识),create_time,create_code,update_code,update_time,del_flag(逻辑删除,1)




 -------------------------------------------------------------

猜你喜欢

转载自okrs.iteye.com/blog/2413303