完成之后的前台页面展示:
测试地址 :dota2info.cn/index
1.配置pom.xml
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
com.baomidou
mybatisplus-spring-boot-starter
1.0.4
org.springframework.boot
spring-boot-starter-thymeleaf
org.mybatis.spring.boot
mybatis-spring-boot-starter
${mybatis.spring.boot.version}
mysql
mysql-connector-java
${mysql.version}
com.alibaba
druid
${druid.version}
commons-lang
commons-lang
${commons.lang.version}
commons-io
commons-io
${commons.io.version}
commons-configuration
commons-configuration
${commons.configuration.version}
com.alibaba
fastjson
${fastjson.version}
velocity
org.apache.velocity
2.0
com.baomidou
mybatis-plus
2.1.7
org.springframework.boot
spring-boot-starter-thymeleaf
net.sourceforge.nekohtml
nekohtml
1.9.22
org.apache.velocity
velocity-engine-core
2.0
com.gameley
gameley-common
1.0
org.dom4j
dom4j
2.0.0
org.springframework
spring-test
4.3.13.RELEASE
org.springframework.boot
spring-boot-test
1.5.5.RELEASE
org.springframework.boot
spring-boot-test
数据库使用mysql,使用mybatis-plus作为连接数据库工具
2.配置application.yml# Tomcat
server:
tomcat:
max-threads: 10
min-spare-threads: 10
port: 7777
# mysql
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/ag_admin?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: 123456
jackson:
time-zone: GMT+8
date-format: yyyy-MM-dd HH:mm:ss
thymeleaf:
mode: LEGACYHTML5
cache: false
# Mybatis配置
mybatis:
mapperLocations: classpath:mapper/*.xml
#mybatis
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: com.gameley.generator.entity
global-config:
#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
id-type: 0
#字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
field-strategy: 2
#驼峰下划线转换
db-column-underline: true
#刷新mapper 调试神器
refresh-mapper: true
#数据库大写下划线转换
#capital-mode: true
#序列接口实现类配置
#key-generator: cn.jeefast.xxx
#逻辑删除配置
logic-delete-value: 0
logic-not-delete-value: 1
#自定义填充策略接口实现
#meta-object-handler: cn.jeefast.xxx
#自定义SQL注入器
#sql-injector: cn.jeefast.xxx
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
3.编写主要的生成工具类:
package com.gameley.generator.utils;
import com.baomidou.mybatisplus.plugins.Page;
import com.gameley.generator.entity.ColumnEntity;
import com.gameley.generator.entity.TableEntity;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.WordUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* 代码生成器 工具类
*
* @author chenshun
* @email [email protected]
* @date 2016年12月19日 下午11:40:24
*/
public class GeneratorUtils {
public static List getTemplates() {
List templates = new ArrayList();
templates.add("template/index.vue.vm");
templates.add("template/mapper.xml.vm");
templates.add("template/entity.java.vm");
templates.add("template/mapper.java.vm");
templates.add("template/controller.java.vm");
templates.add("template/service.java.vm");
templates.add("template/serviceImpl.java.vm");
return templates;
}
/**
* 生成代码
*/
public static void generatorCode(Map table,
List
其余部分及生成模板详见:https://gitee.com/lwydyby/springcloud-adplatform
---- 2018-01-10------
增加springcloud-bus,以实现自动配置
1.在两个工程的pom.xml中引入
org.springframework.cloud
spring-cloud-starter-bus-amqp
org.springframework.boot
spring-boot-starter-actuator
2.在config的配置中加入
rabbitmq:
host: rabbitmq # 登录 Rabbitmq 后台管理页面地址为:http://localhost:15672
port: 5672
username: guest # 默认账户
password: guest # 默认密码
3.在generator增加config配置类 (这里只做了对数据库的动态配置)
package com.gameley.generator.config;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import com.alibaba.druid.pool.DruidDataSource;
import lombok.extern.slf4j.Slf4j;
/**
*
* 配置数据库
* @author wwmxd
* @version 1.2.0
*/
@Slf4j
@Configuration
@RefreshScope
public class DruidConfiguration {
@Value("${spring.datasource.url}")
private String dbUrl;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Bean //声明其为Bean实例
@Primary //在同样的DataSource中,首先使用被标注的DataSource
@RefreshScope
public DataSource dataSource(){
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
return datasource;
}
}
4.配置github或者码云上的项目管理,增加WebHooks,来主动推送更新
增加的url,例如:
http://{ip}:8888/bus/refresh
如需设置密码,则在config中增加配置
encrypt:
key: 123456