16 Star 4 Fork 2

stana/ApplicationPower

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
Loading...
README
Apache-2.0

ApplicationPower 是一个基于数据库单表Crud操作的项目生成器,生成的web项目自动集成spring,spring mvc,mybatis框架,最终生成基于maven构建的可 运行web工程,生成完后只需要将生成的项目导入到eclipse、idea或者及其他开发工具部署至tomcat即可运行,当然生成的项目基于maven环境集成了 jetty web容器,eclipse使用jetty:run命令即可运行,idea的用户只需点击maven projects下的plugins中找到jetty run即可启动项目。
ApplicationPower是基于beetl模板来生成源代码的,因此可以灵活的修改模板来生成代码定义自己的开发接口规范。ApplicationPower相对 mybatis generator来说配置更少、代码灵活性和可控性更高。
重点: ApplicationPower目前已经完全支持生成Springboot+Mybatis框架的Springboot项目,推荐使用生成springboot,后期项目对springmvc生成维护会减少。

结构说明

  1. apidoc是一个未来将使用原生doc注释来生成markdown api文档的项目,目前不可用
  2. common-util是开发中常用的一些工具类,目前文档比较详细,也是application-power所依赖的模块,在使用application-power前需要将它安装到你的本地。
  3. application-power是整个项目的核心,专门用于生成Springboot微服务架构项目和Spring mvc+mybatis架构项目的脚手架,
  4. datasource-aspect是spring web应用下多数据源动态切换的通用模块
  5. mybatis-template是用于重写SqlSessionTemplate来支持分布式事务环境下的动态数据源切换

版本说明

1. v1.0版本的CommonResult依赖于boco-health-common模块
2. v1.1版本的CommonResult改为依赖独立模块Common-util
3. v1.2版本升级spring到4.3.6,Controller层生成的代码使用@GetMapping和@PostMapping代替@RequestMapping注解。
4. v1.3版本升级mybatis和druid的版本,项目框架摒弃log4j,全面将日志升级到log4j2框架,mysql驱动升级到6.x,支持创建springboot项目。
5. v1.4版本升级实现生成方法可自由控制(ps:参考generator.properties中配置),基础方法增加一个返回List<Map<String,Object>>的方法。
6. v1.4.1版本升级springboot和其他依赖的版本,修改springboot测试模板错误,springboot项目增加springloaded热部署插件。
7. v1.4.2版本优化生成代码时对数据库的连接次数,restful接口单元测试生成中add和update方法增加自动添加参数和赋予随机值的功能
8. v1.5版本增加springboot项目基于assembly的服务化打包功能,完备的服务脚本使得在window或linux系统启动和运维项目更轻松
9. v1.6版本增加配置来支持springmvc和springboot多数据源动态切换和atomikos分布式事务支持,快随构建一个数据一致性架构的项目.
   demo:https://gitee.com/sunyurepository/multiple-datasource

功能

  1. 根据连接的数据生成dao,model,service,controller,mapper,controllerTest,serviceTest代码
  2. 项目的maven web基础骨架
  3. 生成基于spring,spring mvc,mybatis框架结构项目所需的基础配置文件
  4. 生成web.xml配置文件
  5. 可以修改模板生成自己喜欢风格或者说修改修改来生成自己习惯的方法名
  6. 基于SL4J面向接口的标注化日志输出

使用说明

1.使用注意事项 在已经进行后,请勿将ApplicationPower的输出目录指定到当前工程,否则会出现代码覆盖,因此建议项目开发启动后将代码生成到别的地方拷贝到自己工 程下,后续会提供不覆盖配置,但是也有可能忘记修改配置,所以还是要小心。 2.根据自己实际需求,修改generator.properties中的配置

 #是否生成注释
 generator.comment=true
 
 #代码输出目录
 generator.outDir=E:\\Test
 
 #基包名
 generator.basePackage=com.boco.demo
 
 #数据库表前缀,例如表t_user则需要去除前缀生成正确的实体
 generator.table.prefix=t_
 
 #指定需要用哪张数据表生成代码,不指定则生成全部表的代码
 generator.table.name=
 
 #生成项目的名称
 generator.applicationName=bootstrap-tree
 
 #需要生成的代码层
 #可生成的代码层dao,model,service,controller,mapper,controllerTest,serviceTest
 generator.layers=dao,model,service,controller,mapper,controllerTest
 
 #需要生成的方法,方法间用英文逗号隔开,写错将无法生成基础方法
 #可生成的方法包括add,update,delete,query,page,queryToListMap。
 # query方法查询单条数据,page生成分页,queryToListMap是查询结果以List<Map<Stirng,Object>>返回
 generator.methods=add,update,delete,query,page,queryToListMap
 
 #mybatis自动转驼峰映射,默认开启
 generator.mapUnderscoreToCamelCase=true
 #是否开启mybatis缓存,只能填写true或者false
 generator.enableCache=true
 
 #是否需要生成mybatis mapper配置文件的ResultMap
 #默认不生成result
 generator.resultMap=false

 # @since 1.5
 # 打包springboot时是否采用assembly
 # 如果采用则将生成一系列的相关配置和一系列的部署脚本
 generator.package.assembly=false

 #@since 1.6
 # 多数据源多个数据数据源用逗号隔开,不需要多数据源环境则空出来
 # 对于多数据源会集成分布式事务
 generator.multiple.datasource=one,two

 # @since 1.6
 # jta-atomikos分布式事务支持
 generator.jta=true

3.修改数据库配置jdbc.properties

  jdbc.driver=com.mysql.jdbc.Driver
  jdbc.username=root
  jdbc.password=root
  jdbc.url=jdbc\:mysql\://localhost:3306/cookbook?useUnicode=true&characterEncoding=UTF-8

4.运行Test下的GenerateCodeTest生成项目

//生成普通SSM框架的maven工程
new CodeWriter().execute();
//生成Springboot+Mybatis的工程
new CodeWriter().executeSpringBoot();

5.将生成的项目导入编辑器

使用模板介绍

1.model层模板

package ${basePackage}.model;

import java.io.Serializable;
${modelImports}

/**
 *
 * @author ${authorName}
 * @date ${createTime}
 *
 */
public class ${entitySimpleName} implements Serializable{

  private static final long serialVersionUID = ${SerialVersionUID}L;

 ${fields}
/** getters and setters */
 ${gettersAndSetters}
}

2.dao层模板

package ${basePackage}.dao;

import java.util.List;
import java.util.Map;

import ${basePackage}.model.${entitySimpleName};

/**
 *
 * @author ${authorName}
 * @date ${createTime}
 *
 *
 */

public interface ${entitySimpleName}Dao{

    /**
     * 保存数据
     * @param entity
     * @return
     */
    int save(${entitySimpleName} entity);
    
    /**
     * 更新数据
     * @param entity
     * @return
     */
    int update(${entitySimpleName} entity);
    
    /**
     * 删除数据
     * @param id
     * @return
     */
    int delete(int id);
    
    /**
     * 根据id查询数据
     * @param id
     * @return
     */
    ${entitySimpleName} queryById(int id);
    
    /**
     * 查询所有数据
     * @return
     */
    List<${entitySimpleName}> queryAll();
    
    /**
     * query result to list of map
     * @param params Map查询参数
     * @return
     */
    List<Map<String,Object>> queryToListMap(Map<String,Object> params);
}

3.service层模板

package ${basePackage}.service;

import java.util.List;
import java.util.Map;
import com.boco.common.model.CommonResult;
import ${basePackage}.model.${entitySimpleName};

/**
 *
 * @author ${authorName}
 * @date ${createTime}
 *
 */

public interface ${entitySimpleName}Service{

    /**
     * 保存数据
     * @param entity
     * @return
     */
    CommonResult save(${entitySimpleName} entity);
    
    /**
     * 修改数据
     * @param entity
     * @return
     */
    CommonResult update(${entitySimpleName} entity);
    
    /**
     * 删除数据
     * @param id
     * @return
     */
    CommonResult delete(int id);
    
    /**
     * 根据id查询数据
     * @param id
     * @return
     */
    CommonResult queryById(int id);
    
    /**
     * 查询所有数据
     * @return
     */
    List<${entitySimpleName}> queryAll();
    
    /**
     * query result to list of map
     * @param params Map查询参数
     * @return
     */
    List<Map<String,Object>> queryToListMap(Map<String,Object> params);
}

4.service实现层模板

package ${basePackage}.service.impl;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.boco.common.model.CommonResult;
import ${basePackage}.model.${entitySimpleName};
import ${basePackage}.dao.${entitySimpleName}Dao;
import ${basePackage}.service.${entitySimpleName}Service;

/**
 * Created by ApplicationPower.
 * @author ${authorName} on ${createTime}.
 */
@Service("${firstLowerName}Service")
public class ${entitySimpleName}ServiceImpl  implements ${entitySimpleName}Service{

    /**
     * 日志
     */
    private static Logger logger = LoggerFactory.getLogger(${entitySimpleName}Service.class);

    @Resource
    private ${entitySimpleName}Dao ${firstLowerName}Dao;

    @Override
    public CommonResult save(${entitySimpleName} entity) {
        CommonResult result = new CommonResult();
        try {
        	${firstLowerName}Dao.save(entity);
        	result.setSuccess(true);
        } catch (Exception e) {
        	result.setMessage("添加数据失败");
        	logger.error("${entitySimpleName}Service添加数据异常:",e);
        }
        return result;
    }

    @Override
    public CommonResult update(${entitySimpleName} entity) {
        CommonResult result = new CommonResult();
        try {
            ${firstLowerName}Dao.update(entity);
            result.setSuccess(true);
        } catch (Exception e) {
            result.setMessage("修改数据失败");
            logger.error("${entitySimpleName}Service修改数据异常:",e);
        }
        return result;
    }

    @Override
    public CommonResult delete(int id) {
        CommonResult result = new CommonResult();
        try {
            ${firstLowerName}Dao.delete(id);
            result.setSuccess(true);
        } catch (Exception e) {
            result.setMessage("删除数据失败");
            logger.error("${entitySimpleName}Service删除数据异常:",e);
        }
        return result;
    }

    @Override
    public CommonResult queryById(int id) {
        CommonResult result = new CommonResult();
        ${entitySimpleName} entity = ${firstLowerName}Dao.queryById(id);
        if (null != entity) {
            //成功返回数据
            result.setData(entity);
            result.setSuccess(true);
        } else {
            result.setMessage("没有找到匹配数据");
            logger.info("${entitySimpleName}Service未查询到数据,编号:{}",id);
        }
        return result;
    }

    @Override
    public PageInfo queryPage(int offset, int limit) {
        PageHelper.offsetPage(offset,limit);
        List<${entitySimpleName}> list = ${firstLowerName}Dao.queryPage();
        return new PageInfo(list);
    }

    @Override
    public List<Map<String,Object>> queryToListMap(Map<String,Object> params){
        return ${firstLowerName}Dao.queryToListMap(params);
    }
}

5.controller层模板

package ${basePackage}.controller;

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

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.pagehelper.PageInfo;
import com.boco.common.model.CommonResult;
import ${basePackage}.model.${entitySimpleName};
import ${basePackage}.service.${entitySimpleName}Service;

/**
 * Created by ApplicationPower.
 * @author ${authorName} on ${createTime}.
 */
@Controller
@RequestMapping("${firstLowerName}")
public class ${entitySimpleName}Controller {
    /**
     * 日志
     */
    private static Logger logger = LoggerFactory.getLogger(${entitySimpleName}Controller.class);

    @Resource
    private ${entitySimpleName}Service ${firstLowerName}Service;

    @ResponseBody
    @PostMapping(value = "/add")
    public CommonResult save(${entitySimpleName} entity) {
        return ${firstLowerName}Service.save(entity);
    }

    @ResponseBody
    @PostMapping(value = "/update")
    public CommonResult update(${entitySimpleName} entity) {
        return ${firstLowerName}Service.update(entity);
    }

    @ResponseBody
    @GetMapping(value = "/delete/{id}")
    public CommonResult delete(@PathVariable int id) {
        return ${firstLowerName}Service.delete(id);
    }

    @ResponseBody
    @GetMapping(value = "/query/{id}")
    public CommonResult queryById(@PathVariable int id) {
        return ${firstLowerName}Service.queryById(id);
    }

    @ResponseBody
    @GetMapping(value = "/page/{offset}/{limit}")
    public PageInfo queryPage(@PathVariable int offset,@PathVariable int limit) {
        return ${firstLowerName}Service.queryPage(offset,limit);
    }

    @ResponseBody
    @GetMapping(value = "/listMap")
    public List<Map<String,Object>> queryToListMap(@RequestParam Map<String,Object> params) {
        return ${firstLowerName}Service.queryToListMap(params);
    }
}
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2016 stana Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

暂无描述 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者 (3)

全部

近期动态

7年前推送了新的提交到 dev 分支,169b024...1eb40f3
7年前推送了新的提交到 dev 分支,c1c1b6e...169b024
7年多前推送了新的提交到 master 分支,1edbaea...b936732
加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/stana/ApplicationPower.git
git@gitee.com:stana/ApplicationPower.git
stana
ApplicationPower
ApplicationPower
master

搜索帮助