帮助您快速搭建基于YMP框架的各种Java工程结构的Maven扩展工具集合,主要包括项目模板和Maven插件命令两部分。
项目模板
Maven插件命令
YMP框架项目地址:https://gitee.com/suninformation/ymate-platform-v2
目前提供以下4种项目模板:
ymate-archetype-quickstart (quickstart):标准Java工程,已集成YMP依赖;
ymate-archetype-quickstart (quickstart)
ymate-archetype-webapp (webapp):JavaWeb工程,已集成WebMVC框架相关依赖和完整的参数配置;
ymate-archetype-webapp (webapp)
ymate-archetype-module (module):YMP模块工程,提供Demo示例及JUint测试代码;
ymate-archetype-module (module)
ymate-archetype-serv (serv):YMP服务工程,分别提供TCP、UDP客户端和服务端示例程序及相关配置;
ymate-archetype-serv (serv)
查看使用文档:通过项目模板自动生成Java工程
在pom.xml文件中添加插件配置( 必须 ):
pom.xml
net.ymate.maven.plugins ymate-maven-plugin 1.0-SNAPSHOT
执行命令格式:
mvn ymate: -D= -D=
注:请在pom.xml文件所在路径下执行;
2.1.1 module:模块代码生成器
module
用于生成基于IModule接口的模块代码实现(完全替代ymate-archetype-module (module)模板);
IModule
创建名称为Demo的模块;
Demo
执行命令:
mvn ymate:module -Dname=Demo
控制台输出:
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ympDemo 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:module (default-cli) @ ympDemo --- [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/module/IDemo.java [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/module/Demo.java [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/module/IDemoModuleCfg.java [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/module/impl/DefaultModuleCfg.java [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.504s [INFO] Finished at: Tue Oct 31 17:12:56 CST 2017 [INFO] Final Memory: 9M/245M [INFO] ------------------------------------------------------------------------
2.1.2 controller:控制器类生成器
controller
用于生成适用于WebMVC模块的控制器类代码;
创建名称为DemoAction的控制器类,内容如下:
DemoAction
@Controller @RequestMapping(value = "/user/info", method = {Type.HttpMethod.POST, Type.HttpMethod.GET} ) public class DemoAction { @RequestMapping("/") public IView __index() throws Exception { return View.textView("Hello YMPer!"); } }
mvn ymate:controller -Dname=Demo -Dsuffix=Action -Dmapping=/user/info -Dmapping.method=post,get
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ympDemo 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:controller (default-cli) @ ympDemo --- [INFO] properties: [INFO] |--controllerName:DemoAction [INFO] |--packageName:net.ymate.demo.controller [INFO] |--singleton:true [INFO] |--transaction:false [INFO] |--mapping:/user/info [INFO] |--method:POST [INFO] |--method:GET [WARNING] Skip existing file /Users/.../ympDemo/src/main/java/net/ymate/demo/controller/DemoAction.java [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.377s [INFO] Finished at: Tue Oct 31 17:48:20 CST 2017 [INFO] Final Memory: 8M/245M [INFO] ------------------------------------------------------------------------
2.1.3 mapping:控制器请求方法生成器
mapping
用于为指定的控制器类追加请求方法代码片段;
为名称为DemoAction的控制器类添加__sayHi请求方法并添加username和age方法参数,其中age参数通过@Pathvariable注解获取,内容如下:
__sayHi
username
age
@Pathvariable
@RequestMapping(value = "/sayHi/{age}" ) public IView __sayHi(@RequestParam String username, @PathVariable String age) throws Exception { return View.textView("mapping: /sayHi/{age}"); }
mvn ymate:mapping -Dname=Demo -Dsuffix=Action -Dmapping=/sayHi/{age} -Dmethod=sayHi -Dmethod.param=username,path:age
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ympDemo 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:mapping (default-cli) @ ympDemo --- [INFO] properties: [INFO] |--controllerName:DemoAction [INFO] |--fileUpload:false [INFO] |--transaction:false [INFO] |--method:__sayHi [INFO] |--param:username [INFO] |--param:path:age [INFO] |--mapping:/sayHi/{age} [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/controller/DemoAction.java [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.482s [INFO] Finished at: Wed Nov 01 22:27:58 CST 2017 [INFO] Final Memory: 11M/309M [INFO] ------------------------------------------------------------------------
2.1.4 interceptor:拦截器类生成器
interceptor
用于生成拦截器类代码;
创建名称为DemoInterceptor的拦截器,内容如下:
DemoInterceptor
public class DemoInterceptor extends AbstractInterceptor { @Override protected Object __before(InterceptContext context) throws Exception { return null; } @Override protected Object __after(InterceptContext context) throws Exception { return null; } }
mvn ymate:interceptor -Dname=Demo
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ympDemo 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:interceptor (default-cli) @ ympDemo --- [INFO] properties: [INFO] |--interceptorName:DemoInterceptor [INFO] |--packageName:net.ymate.demo.intercept [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/intercept/DemoInterceptor.java [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.421s [INFO] Finished at: Wed Nov 01 22:41:23 CST 2017 [INFO] Final Memory: 9M/245M [INFO] ------------------------------------------------------------------------
2.1.5 validator:验证器类生成器
validator
用于生成验证器注解及类代码;
创建名称为VDemo和DemoValidator的验证器注解和验证器类,内容如下:
VDemo
DemoValidator
@Target({ElementType.FIELD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface VDemo { /** * @return 自定义验证消息 */ String msg() default ""; } @Validator(VDemo.class) @CleanProxy public class DemoValidator extends AbstractValidator { @Override public ValidateResult validate(ValidateContext context) { Object _paramValue = context.getParamValue(); if (_paramValue != null) { boolean _matched = false; VDemo _anno = (VDemo) context.getAnnotation(); // TODO Code here. if (_matched) { String _pName = StringUtils.defaultIfBlank(context.getParamLabel(), context.getParamName()); _pName = __doGetI18nFormatMessage(context, _pName, _pName); String _msg = StringUtils.trimToNull(_anno.msg()); if (_msg != null) { _msg = __doGetI18nFormatMessage(context, _msg, _msg, _pName); } return new ValidateResult(context.getParamName(), _msg); } } return null; } }
mvn ymate:validator -Dname=Demo
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ympDemo 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:validator (default-cli) @ ympDemo --- [INFO] properties: [INFO] |--validatorName:DemoValidator [INFO] |--packageName:net.ymate.demo.validation [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/validation/VDemo.java [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/validation/DemoValidator.java [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.438s [INFO] Finished at: Wed Nov 01 22:48:42 CST 2017 [INFO] Final Memory: 9M/245M [INFO] ------------------------------------------------------------------------
2.1.6 repository:存储器类生成器
repository
用于生成存储器类代码;
创建名称为DemoRepository的存储器并启用配置对象和接口模式,内容如下:
DemoRepository
public interface IDemoRepository { IResultSet execSql(String hash, IResultSet results) throws Exception; List execQuery(String hash, IResultSet... results) throws Exception; } @Repository @Transaction public class DemoRepository implements IDemoRepository, IRepository { @Inject private DemoRepositoryConfig __config; @Override public IConfiguration getConfig() { return __config; } /** * 自定义SQL */ @Repository("select * from table1 where hash = ${hash}") public IResultSet execSql(String hash, IResultSet results) throws Exception { return results; } /** * 读取配置文件中的SQL */ @Repository(item = "demo_query") public List execQuery(String hash, IResultSet... results) throws Exception { return results[0].getResultData(); } }
mvn ymate:repository -Dname=Demo -Dtransaction=true -Dconfig=true -Dinterface=true
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ympDemo 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:repository (default-cli) @ ympDemo --- [INFO] properties: [INFO] |--repositoryName:DemoRepository [INFO] |--packageName:net.ymate.demo.repository [INFO] |--transaction:true [INFO] |--withConfig:true [INFO] |--withInterface:true [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/repository/IDemoRepository.java [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/repository/impl/DemoRepository.java [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.438s [INFO] Finished at: Wed Nov 01 23:36:27 CST 2017 [INFO] Final Memory: 9M/245M [INFO] ------------------------------------------------------------------------
2.1.7 service:服务层类生成器
service
用于生成服务层类代码;
创建名称为DemoService的服务类及接口,内容如下:
DemoService
public interface IDemoService { } @Bean public class DemoService implements IDemoService { }
mvn ymate:service -Dname=Demo
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ympDemo 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:service (default-cli) @ ympDemo --- [INFO] properties: [INFO] |--serviceName:DemoService [INFO] |--packageName:net.ymate.demo.service [INFO] |--transaction:false [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/service/IDemoService.java [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/service/impl/DemoService.java [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.425s [INFO] Finished at: Wed Nov 01 23:44:13 CST 2017 [INFO] Final Memory: 10M/309M [INFO] ------------------------------------------------------------------------
2.1.8 config:配置类生成器
config
用于生成基于YMP框架配置体系结构的配置类代码及相关配置文件;
创建名称为DemoConfig的配置类、接口和配置文件,内容如下:
DemoConfig
public interface IDemoConfig { } @Configuration("cfgs/demo.cfg.xml") public class DemoConfig extends DefaultConfiguration implements IDemoConfig { } // --- cfgs/demo.cfg.xml iphone ipad imac itouch red 120g small 2015
mvn ymate:config -Dname=Demo -Dinterface=true
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ympDemo 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:config (default-cli) @ ympDemo --- [INFO] properties: [INFO] |--type:jar [INFO] |--configHome:/src/main/resources [INFO] |--configName:DemoConfig [INFO] |--packageName:net.ymate.demo.config [INFO] |--fileName:cfgs/demo.cfg.xml [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/config/IDemoConfig.java [INFO] Output file: /Users/.../ympDemo/src/main/java/net/ymate/demo/config/impl/DemoConfig.java [INFO] Output file: /Users/.../ympDemo/src/main/resources/cfgs/demo.cfg.xml [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.434s [INFO] Finished at: Thu Nov 02 00:05:02 CST 2017 [INFO] Final Memory: 9M/245M [INFO] ------------------------------------------------------------------------
2.1.9 enpasswd:字符串加密
enpasswd
基于IPasswordProcessor密码处理器接口的默认DES实现,对数据库等登录密码进行加密操作;
IPasswordProcessor
DES
对字符串abc12345678进行加密:
abc12345678
mvn ymate:enpasswd -Dpasswd=abc12345678
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ympDemo 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:enpasswd (default-cli) @ ympDemo --- [INFO] Encrypt password: D3ytOQrD63BlKGDMJnaYsQ== [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.515s [INFO] Finished at: Thu Nov 02 09:00:35 CST 2017 [INFO] Final Memory: 11M/245M [INFO] ------------------------------------------------------------------------
2.1.10 depasswd:字符串解密
depasswd
基于IPasswordProcessor密码处理器接口的默认DES实现,对数据库等登录密码进行解密操作;
对已加密字符串D3ytOQrD63BlKGDMJnaYsQ==进行解密:
D3ytOQrD63BlKGDMJnaYsQ==
mvn ymate:depasswd -Dpasswd=D3ytOQrD63BlKGDMJnaYsQ==
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ympDemo 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:depasswd (default-cli) @ ympDemo --- [INFO] Decrypt password: abc12345678 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.459s [INFO] Finished at: Thu Nov 02 09:03:51 CST 2017 [INFO] Final Memory: 11M/245M [INFO] ------------------------------------------------------------------------
2.1.11 tomcat:Tomcat服务配置生成器
tomcat
生成基于Tomcat的获立JVM服务目录结构及配置文件,目前支持Tomcat版本:6、7、8;
6
7
8
基于Tomcat7.x创建名称为DemoServer的服务:
Tomcat7.x
DemoServer
mvn ymate:tomcat -DserviceName=DemoServer -DcatalinaHome=/Users/.../apache-tomcat-7.0.54 -DcatalinaBase=/Users/.../Temp
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ympDemo 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:tomcat (default-cli) @ ympDemo --- [INFO] Tomcat Service:DemoServer [INFO] |--CatalinaHome:/Users/.../apache-tomcat-7.0.54 [INFO] |--CatalinaBase:/Users/.../Temp [INFO] |--HostName:localhost [INFO] |--HostAlias: [INFO] |--TomcatVersion:7 [INFO] |--ServerPort:8005 [INFO] |--ConnectorPort:8080 [INFO] |--RedirectPort:8443 [INFO] |--Ajp:false [INFO] Output file: /Users/.../Temp/DemoServer/conf/server.xml [INFO] Output file: /Users/.../Temp/DemoServer/vhost.conf [INFO] Output file: /Users/.../Temp/DemoServer/bin/install.bat [INFO] Output file: /Users/.../Temp/DemoServer/bin/manager.bat [INFO] Output file: /Users/.../Temp/DemoServer/bin/shutdown.bat [INFO] Output file: /Users/.../Temp/DemoServer/bin/startup.bat [INFO] Output file: /Users/.../Temp/DemoServer/bin/uninstall.bat [INFO] Output file: /Users/.../Temp/DemoServer/bin/manager.sh [INFO] Output file: /Users/.../Temp/DemoServer/webapps/ROOT/index.jsp [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.498s [INFO] Finished at: Thu Nov 02 10:05:47 CST 2017 [INFO] Final Memory: 11M/309M [INFO] ------------------------------------------------------------------------
生成的文件说明:
Linux下服务的启动和停止:
Linux
* 需要为`manager.sh`添加执行权限:
chmod +x manager.sh * 启动服务:
./manager.sh start
Using CATALINA_BASE: /Users/.../Temp/DemoServer Using CATALINA_HOME: /Users/.../apache-tomcat-7.0.54 Using CATALINA_TMPDIR: /Users/.../Temp/DemoServer/temp Using JRE_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home Using CLASSPATH: /Users/.../apache-tomcat-7.0.54/bin/bootstrap.jar:/Users/.../apache-tomcat-7.0.54/bin/tomcat-juli.jar Using CATALINA_PID: /Users/.../Temp/DemoServer/logs/catalina.pid Tomcat started. * 停止服务:
./manager.sh stop
Using CATALINA_BASE: /Users/.../Temp/DemoServer Using CATALINA_HOME: /Users/.../apache-tomcat-7.0.54 Using CATALINA_TMPDIR: /Users/.../Temp/DemoServer/temp Using JRE_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home Using CLASSPATH: /Users/.../apache-tomcat-7.0.54/bin/bootstrap.jar:/Users/.../apache-tomcat-7.0.54/bin/tomcat-juli.jar Using CATALINA_PID: /Users/.../Temp/DemoServer/logs/catalina.pid Tomcat stopped.
2.1.12 entity:数据实体代码生成器
entity
通过已有数据库表结构生成对应的数据实体类,支持表和视图,支持ConsoleTable和markdown格式输出表结构;
ConsoleTable
markdown
在生成数据实体之前,需要先将默认数据源和实体生成规则配置好,请根据实际需求配置并确认ymp-conf.properties以下内容:
ymp-conf.properties
#------------------------------------- # JDBC持久化模块初始化参数 #------------------------------------- # 是否显示执行的SQL语句,默认为false ymp.configs.persistence.jdbc.ds.default.show_sql=true # 数据库表前缀名称,默认为空 ymp.configs.persistence.jdbc.ds.default.table_prefix=ym_ # 数据库连接字符串,必填参数 ymp.configs.persistence.jdbc.ds.default.connection_url=jdbc:mysql://localhost:3306/ymate_demo # 数据库访问用户名称,必填参数 ymp.configs.persistence.jdbc.ds.default.username=root # 数据库访问密码,可选参数 ymp.configs.persistence.jdbc.ds.default.password= #------------------------------------- # JDBC数据实体代码生成器配置参数 #------------------------------------- # 是否生成新的BaseEntity类,默认为false(即表示使用框架提供的BaseEntity类) ymp.params.jdbc.use_base_entity= # 是否使用类名后缀,不使用和使用的区别如: User-->UserModel,默认为false ymp.params.jdbc.use_class_suffix= # 是否采用链式调用模式,默认为false ymp.params.jdbc.use_chain_mode= # 是否添加类成员属性值状态变化注解,默认为false ymp.params.jdbc.use_state_support= # 实体及属性命名过滤器接口实现类,默认为空 ymp.params.jdbc.named_filter_class= # 数据库名称(仅针对特定的数据库使用,如Oracle),默认为空 ymp.params.jdbc.db_name= # 数据库用户名称(仅针对特定的数据库使用,如Oracle),默认为空 ymp.params.jdbc.db_username= # 数据库表名称前缀,多个用'|'分隔,默认为空 ymp.params.jdbc.table_prefix= # 否剔除生成的实体映射表名前缀,默认为false ymp.params.jdbc.remove_table_prefix= # 预生成实体的数据表名称列表,多个用'|'分隔,默认为空表示全部生成 ymp.params.jdbc.table_list= # 排除的数据表名称列表,在此列表内的数据表将不被生成实体,多个用'|'分隔,默认为空 ymp.params.jdbc.table_exclude_list= # 需要添加@Readonly注解声明的字段名称列表,多个用'|'分隔,默认为空 ymp.params.jdbc.readonly_field_list= # 生成的代码文件输出路径,默认为${root} ymp.params.jdbc.output_path= # 生成的代码所属包名称,默认为: packages ymp.params.jdbc.package_name=
mvn ymate:entity
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building carfriend-core 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:entity (default-cli) @ carfriend-core --- 十一月 02, 2017 11:41:09 上午 net.ymate.platform.core.YMP init 信息: __ ____ __ ____ ____ \ \ / / \/ | _ \ __ _|___ \ \ V /| |\/| | |_) | \ \ / / __) | | | | | | | __/ \ V / / __/ |_| |_| |_|_| \_/ |_____| Website: http://www.ymate.net/ 十一月 02, 2017 11:41:09 上午 net.ymate.platform.core.YMP init 信息: Initializing ymate-platform-core-2.0.2-Release build-20171030-0108 - debug:true 十一月 02, 2017 11:41:09 上午 net.ymate.platform.persistence.jdbc.JDBC init 信息: Initializing ymate-platform-persistence-jdbc-2.0.2-Release build-20171030-0108 十一月 02, 2017 11:41:09 上午 net.ymate.platform.core.YMP init 信息: Initialization completed, Total time: 191ms 十一月 02, 2017 11:41:09 上午 net.ymate.platform.persistence.jdbc.base.AbstractOperator execute 信息: [show full tables where Table_type='BASE TABLE'][][1][31ms] Output file /Users/.../src/main/java/net/ymate/model/CategoryAttribute.java TABLE_NAME: ym_category_attribute MODEL_NAME: CategoryAttribute +-------------+-------------------+-------------+----------------+--------+-----------+-------+----------+---------+---------+ | COLUMN_NAME | COLUMN_CLASS_NAME | PRIMARY_KEY | AUTO_INCREMENT | SIGNED | PRECISION | SCALE | NULLABLE | DEFAULT | REMARKS | +-------------+-------------------+-------------+----------------+--------+-----------+-------+----------+---------+---------+ | id | java.lang.String | TRUE | FALSE | FALSE | 32 | 0 | FALSE | NULL | | +-------------+-------------------+-------------+----------------+--------+-----------+-------+----------+---------+---------+ | catetory_id | java.lang.String | FALSE | FALSE | FALSE | 32 | 0 | FALSE | NULL | | +-------------+-------------------+-------------+----------------+--------+-----------+-------+----------+---------+---------+ | attr_key | java.lang.String | FALSE | FALSE | FALSE | 255 | 0 | FALSE | NULL | | +-------------+-------------------+-------------+----------------+--------+-----------+-------+----------+---------+---------+ | attr_value | java.lang.String | FALSE | FALSE | FALSE | 16383 | 0 | TRUE | NULL | | +-------------+-------------------+-------------+----------------+--------+-----------+-------+----------+---------+---------+ | type | java.lang.Integer | FALSE | FALSE | FALSE | 2 | 0 | TRUE | 0 | | +-------------+-------------------+-------------+----------------+--------+-----------+-------+----------+---------+---------+ | owner | java.lang.String | FALSE | FALSE | FALSE | 32 | 0 | TRUE | NULL | | +-------------+-------------------+-------------+----------------+--------+-----------+-------+----------+---------+---------+ [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.013s [INFO] Finished at: Thu Nov 02 11:41:10 CST 2017 [INFO] Final Memory: 12M/208M [INFO] ------------------------------------------------------------------------
通过插件生成的代码默认放置在src/main/java路径,当数据库表发生变化时,直接执行插件命令就可以快速更新数据实体对象; 如果使用的JDBC驱动是mysql-connector- java-6.x及以上版本时,需要配置db_name和db_username参数,否则会产生异常;
通过插件生成的代码默认放置在src/main/java路径,当数据库表发生变化时,直接执行插件命令就可以快速更新数据实体对象;
src/main/java
如果使用的JDBC驱动是mysql-connector- java-6.x及以上版本时,需要配置db_name和db_username参数,否则会产生异常;
mysql-connector- java-6.x
db_name
db_username
2.1.13 crud:CRUD代码生成器
crud
通过规则配置文件自动生成控制器(Controller)、存储器(Repository)等类代码,包括拦截器、参数验证、权限控制、文件上传、组件条件查询等;
Controller
Repository
生成默认CRUD规则配置文件:
mvn ymate:crud
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ympDemo 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- ymate-maven-plugin:1.0-SNAPSHOT:crud (default-cli) @ ympDemo --- [INFO] Output file: /Users/.../Temp/ympDemo/misc/crud.json [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.424s [INFO] Finished at: Thu Nov 02 12:12:17 CST 2017 [INFO] Final Memory: 9M/245M [INFO] ------------------------------------------------------------------------
若使用-DfromDb=true方式通过数据库表结构生成规则配置文件,需要在ymp-conf.properties文件中配置好默认数据源; 以上命令在执行时,若crud.json配置文件存在则直接生成代码,否则将生成默认配置文件,内容如下:
若使用-DfromDb=true方式通过数据库表结构生成规则配置文件,需要在ymp-conf.properties文件中配置好默认数据源;
-DfromDb=true
以上命令在执行时,若crud.json配置文件存在则直接生成代码,否则将生成默认配置文件,内容如下:
crud.json
规则配置文件说明:
{ "application": { // ————基本信息 "name": "ympDemo", // 名称 "version": "1.0-SNAPSHOT", // 当前配置版本 "package": "net.ymate.demo", // 代码基准包名 "author": "ymatescaffold", // 作者信息 "createTime": "2017/11/02 12:12", // 配置文件创建时间 "locked": false // 是否锁定,锁定状态下不会生成任何文件 }, "security": { // ————权限安全相关配置 "enabled": false, // 是否开启权限配置 "name": "", // 权限组名称 "prefix": "", // 权限名称前缀 "roles": { // 基本角色配置 "admin": false, // 是否管理员角色 "operator": false, // 是否操作员角色 "user": false // 是否普通用户角色 }, "permissions": [] // 全局权限列表,如:["USER_ADD", "USER_DETAIL"] }, "intercept": { // ————拦截器相关配置 "before": [], // 前置拦截器类名集合,如:["net.ymate.demo.intercept.UserInterceptor"] "after": [], // 后置拦截器类名集合 "around": [], // 环绕(前、后置)拦截器类名集合 "params": {} // 拦截器参数,如:{"p1": "p1_value"} }, "apis": [ // ————接口对象相关配置 { "name": "", // 当前接口对象名称,如:”user“ "mapping": "", // 当前控制器类基准URL路径,如:"/v1/user" "type": "model", // 生成类型,取值范围:model,query "model": "", // 数据实体类名,当type="model"时必填,如:"net.ymate.model.User" "query": "", // SQL查询语句,当type="query"时必填 "description": "", // 文档描述 "locked": false, // 是否锁定,锁定状态下忽略当前配置的代码生成 "timestamp": false, // 是否使用create_time和last_modify_time字段 "status": [ // ————自定义数据状态处理相关配置 { "enabled": false, // 是否生成此状态配置代码 "name": "delete", // 名称(用于生成方法名称) "column": "is_deleted", // 对应的数据表字段名称 "type": "integer", // 数据类型,常用string,integer,long等对象类型 "value": "1", // 本次操作将变更字段的值 "reason": false, // 是否必须提交操作原因说明参数 "description": "" // 文档描述 } ], "primary": { // ——主键参数 "name": "", // 参数名称 "label": "", // 参数标签名称(用于显示) "column": "", // 参数对应的数据表字段名称 "type": "string", // 数据类型,常用string,integer,long等对象类型 "validation": { // ————参数验证相关配置 "max": 0, // 参数最大长度 "min": 0, // 参数最小长度 "regex": "", // 正则表达式 "numeric": false // 是否必须为数值 }, "description": "" // 参数文档描述 }, "params": [ // ————参数集合 { "name": "", // 参数名称 "label": "", // 参数标签名称(用于显示) "column": "", // 参数对应的数据表字段名称 "type": "string", // 数据类型,常用string,integer,long等对象类型 "required": false, // 是否必须 "defaultValue": "", // 参数默认值 "validation": { // ————参数验证相关配置 "max": 0, // 参数最大长度 "min": 0, // 参数最小长度 "regex": "", // 正则表达式 "mobile": false, // 是否必须为手机号码格式 "email": false, // 是否必须为邮箱地址格式 "numeric": false, // 是否必须为数值 "datetime": false // 是否必须为日期时间戳 }, "filter": { // ————查询相关配置 "enabled": false, // 是否作为查询条件 "like": false, // 是否采用like进行查询(自动为参数值两端添加"%") "region": false // 是否采用between进行范围查询(一般用于数值和时间参数) }, "upload": { // ————文件上传相关配置 "enabled": false, // 是否接收上传文件 "contentTypes": [] // 上传文件类型,如:["image/png", "image/jpeg"] }, "description": "" // 参数文档描述 } ] } ] }
YMP不仅提供便捷的Web及其它Java项目的快速开发体验,也将不断提供更多丰富的项目实践经验。
感兴趣的小伙伴儿们可以加入 官方QQ群480374360,一起交流学习,帮助YMP成长!
了解更多有关YMP框架的内容,请访问官网:http://www.ymate.net/