Commit f17889aa by 朱瑞泽

init

parents
# maven ignore
target/
*.jar
!.mvn/wrapper/*
*.war
*.zip
*.tar
*.tar.gz
.flattened-pom.xml
# eclipse ignore
.settings/
.project
.classpath
# idea ignore
.idea/
*.ipr
*.iml
*.iws
# temp ignore
*.log
*.cache
*.diff
*.patch
*.tmp
dubbo.cache*
# system ignore
.DS_Store
Thumbs.db
*.orig
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.gic</groupId>
<artifactId>gic-demo-pom</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>gic-demo-base-api</artifactId>
<version>${libraryVersion}</version>
<name>${project.artifactId}</name>
<url>http://www.demogic.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<libraryVersion>1.0-SNAPSHOT</libraryVersion>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-base-api</artifactId>
<version>${gic-base-api}</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.gic.demo.base.api.common;
public class Constant {
/**
* EMPTY
*/
public final static String EMPTY = "";
/**
* 空格
*/
public final static String BLANK = " ";
/**
* 点
*/
public final static String DOT = ".";
/**
* / 斜杠
*/
public final static String SLASH = "/";
/**
* 数字0
*/
public final static int NUMBER_0 = 0;
/**
* 数字1
*/
public final static int NUMBER_1 = 1;
/**
* 数字2
*/
public final static int NUMBER_2 = 2;
/**
* 数字3
*/
public final static int NUMBER_3 = 3;
/**
* 数字4
*/
public final static int NUMBER_4 = 4;
/**
* 数字5
*/
public final static int NUMBER_5 = 5;
/**
* 数字6
*/
public final static int NUMBER_6 = 6;
/**
* 数字7
*/
public final static int NUMBER_7 = 7;
/**
* 数字8
*/
public final static int NUMBER_8 = 8;
/**
* 数字9
*/
public final static int NUMBER_9 = 9;
/**
* 数字10
*/
public final static int NUMBER_10 = 10;
/**
* 数字11
*/
public final static int NUMBER_11 = 11;
/**
* 数字12
*/
public final static int NUMBER_12 = 12;
/**
* 数字13
*/
public final static int NUMBER_13 = 13;
/**
* 数字14
*/
public final static int NUMBER_14 = 14;
/**
* 数字15
*/
public final static int NUMBER_15 = 15;
/**
* 字符 :0 [48 ]
*/
public final static String STRING_0 = "0";
/**
* 字符 :1 [49 ]
*/
public final static String STRING_1 = "1";
/**
* 字符 :2 [50 ]
*/
public final static String STRING_2 = "2";
/**
* 字符 :3 [51 ]
*/
public final static String STRING_3 = "3";
/**
* 字符 :4 [52 ]
*/
public final static String STRING_4 = "4";
/**
* 字符 :5 [53 ]
*/
public final static String STRING_5 = "5";
/**
* 字符 :6 [54 ]
*/
public final static String STRING_6 = "6";
/**
* 字符 :7 [55 ]
*/
public final static String STRING_7 = "7";
/**
* 字符 :8 [56 ]
*/
public final static String STRING_8 = "8";
/**
* 字符 :9 [57 ]
*/
public final static String STRING_9 = "9";
/**
* 日期年 格式
*/
public static final String YEAR_FORMAT = "yyyy";
/**
* 日期年月 格式
*/
public static final String YEAR_MONTH_FORMAT = "yyyy-MM";
/**
* 日期 格式
*/
public static final String DATE_FORMAT = "yyyy-MM-dd";
/**
* 日期 格式
*/
public static final String DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
/**
* 状态-无效
*/
public static final int STATE_INVALID = 0;
/**
* 状态-有效
*/
public static final int STATE_EFFECTIVE = 1;
/**
* 默认分页显示条数 20
*/
public final static int DEFAULT_PAGESIZE = 20;
/**
* 默认分页最多显示条数 200
*/
public final static int DEFAULT_MAX_PAGESIZE = 200;
}
package com.gic.demo.base.api.common;
import java.io.Serializable;
/**
* 服务响应
*
* @param <T> 返回类型
* @author zhurz
*/
public class ServiceResponse<T> implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 是否走完正常业务逻辑流程
*/
private boolean success;
/**
* 响应代码
*/
private int code;
/**
* 响应信息(可为null,不一定和code说明信息一致)
*/
private String message;
/**
* 响应结果
*/
private T result;
public ServiceResponse() {
}
public ServiceResponse(boolean success, int code, T result) {
this(success, code, null, result);
}
public ServiceResponse(boolean success, int code, String message, T result) {
this.success = success;
this.code = code;
this.message = message;
this.result = result;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getResult() {
return result;
}
public void setResult(T result) {
this.result = result;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.gic</groupId>
<artifactId>gic-demo-pom</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>gic-demo-common</artifactId>
<version>${libraryVersion}</version>
<name>${project.artifactId}</name>
<url>http://www.demogic.com</url>
<distributionManagement>
<repository>
<!-- 和 Maven setting 保持一致 -->
<id>nexus-snapshots</id>
<name>nexus distribution snapshot repository</name>
<!-- 这里使用 /content/repositories/snapshots/ -->
<url>http://182.254.134.223:8081/nexus/content/repositories/snapshots/</url>
<!--<url>http://stream.banli.mobi:8081/content/repositories/snapshots/</url>-->
</repository>
<snapshotRepository>
<!-- 和 Maven setting 保持一致 -->
<id>nexus-snapshots</id>
<name>nexus distribution snapshot repository</name>
<!-- 这里使用 /content/repositories/snapshots/ -->
<url>http://182.254.134.223:8081/nexus/content/repositories/Snapshots-1/</url>
<!--<url>http://stream.banli.mobi:8081/content/repositories/snapshots/</url>-->
</snapshotRepository>
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<libraryVersion>1.0-SNAPSHOT</libraryVersion>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-commons</artifactId>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-dubbo-extension</artifactId>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-mq-sdk</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-redis-data</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
</dependency>
<dependency>
<!-- 桥接:告诉Slf4j使用Log4j2 -->
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
<dependency>
<!-- 桥接:告诉commons logging使用Log4j2 -->
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-demo-base-api</artifactId>
</dependency>
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.gic.demo.common.init;
import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* Created 2019/1/9.
*
* @author hua
*/
public class SpringContextHolder implements ApplicationContextAware {
private static ApplicationContext applicationContext = null;
private static Logger logger = LoggerFactory.getLogger(SpringContextHolder.class);
/**
* 取得存储在静态变量中的ApplicationContext.
*/
public static ApplicationContext getApplicationContext() {
assertContextInjected();
return applicationContext;
}
/**
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
*/
@SuppressWarnings("unchecked")
public static <T> T getBean(String name) {
assertContextInjected();
return (T) applicationContext.getBean(name);
}
/**
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
*/
public static <T> T getBean(Class<T> requiredType) {
assertContextInjected();
return applicationContext.getBean(requiredType);
}
/**
* 清除SpringContextHolder中的ApplicationContext为Null.
*/
public static void clearHolder() {
logger.debug("清除SpringContextHolder中的ApplicationContext:"
+ applicationContext);
applicationContext = null;
}
/**
* 实现ApplicationContextAware接口, 注入Context到静态变量中.
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
if (SpringContextHolder.applicationContext != null) {
logger.warn("SpringContextHolder中的ApplicationContext被覆盖, 原有ApplicationContext为:" + SpringContextHolder.applicationContext);
}
SpringContextHolder.applicationContext = applicationContext; // NOSONAR
}
/**
* 检查ApplicationContext不为空.
*/
private static void assertContextInjected() {
Validate.validState(applicationContext != null, "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");
}
}
\ No newline at end of file
package com.gic.demo.common.interceptor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 跨域拦截器
*
* @author zhurz
*/
public class CORSInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if(RequestMethod.OPTIONS.name().equals(request.getMethod())) {
response.setStatus(HttpStatus.OK.value());
return false;
}
return true;
}
}
package com.gic.demo.common.utils;
import com.alibaba.fastjson.JSON;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import java.util.List;
public class EntityUtils {
public static <T> T changeEntityByJSON(Class<T> target, Object baseTO) {
return JSON.parseObject(JSON.toJSONString(baseTO), target);
}
public static <T> List<T> changeEntityListByJSON(Class<T> target, Object baseTO) {
return JSON.parseArray(JSON.toJSONString(baseTO), target);
}
private static final MapperFacade MAPPER;
static {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
MAPPER = mapperFactory.getMapperFacade();
}
public static <T> T changeEntityByOrika(Class<T> target, Object baseTO) {
return MAPPER.map(baseTO, target);
}
public static <D, S> List<D> changeEntityListByOrika(Class<D> target, Iterable<S> baseTO) {
return MAPPER.mapAsList(baseTO, target);
}
}
package com.gic.demo.common.utils;
import java.io.Serializable;
/**
* rest接口响应
*
* @author zhurz
*/
public class GicDemoResponse implements Serializable {
private static final long serialVersionUID = 1L;
private int errorCode;
private String message;
private Object result;
private String detailError;
public GicDemoResponse() {
}
public GicDemoResponse(int errorCode, String message) {
this.errorCode = errorCode;
this.message = message;
}
public String getDetailError() {
return detailError;
}
public void setDetailError(String detailError) {
this.detailError = detailError;
}
public int getErrorCode() {
return errorCode;
}
public void setErrorCode(int errorCode) {
this.errorCode = errorCode;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getResult() {
return result;
}
public void setResult(Object result) {
this.result = result;
}
}
package com.gic.demo.common.utils;
import java.util.*;
/**
* MAP工具类
*
* @author zhurz
*/
public class MapUtil {
public interface Handler<T, R> {
R apply(T input);
}
/**
* 转换MAP
*
* @param list
* @param handler
* @param <K>
* @param <V>
* @return
*/
public static <K, V> Map<K, V> convertMap(List<V> list, Handler<V, K> handler) {
Map<K, V> map = new HashMap<>();
if (list == null || handler == null) {
return map;
}
for (V v : list) {
map.put(handler.apply(v), v);
}
return map;
}
/**
* 转换SET
*
* @param list
* @param handler
* @param <K>
* @param <V>
* @return
*/
public static <K, V> Set<K> convertSet(List<V> list, Handler<V, K> handler) {
Set<K> set = new HashSet<>();
if (list == null || handler == null) {
return set;
}
for (V v : list) {
set.add(handler.apply(v));
}
return set;
}
}
package com.gic.demo.common.utils;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
/**
* 密码工具
*
* @author zhurz
*/
public final class PasswordUtil {
/**
* 编码密码( base64(sha1(password)) )
*
* @param password 明文密码
* @return
*/
public static String encodePassword(String password) {
return Base64.encodeBase64String(DigestUtils.sha1(password == null ? "" : password));
}
/**
* 检查密码是否匹配
*
* @param encodePassword 编码过的密码
* @param password 明文密码
* @return
*/
public static boolean checkPassword(String encodePassword, String password) {
return (encodePassword == null ? "" : encodePassword).equals(encodePassword(password));
}
}
package com.gic.demo.common.utils;
import com.gic.redis.RedisFactory;
import org.redisson.api.RAtomicLong;
import org.redisson.api.RedissonClient;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
public class UniqueIdUtils {
private static class SnowFlake {
private static final SnowFlake SNOW_FLAKE = new SnowFlake();
private static final long START_TIMESTAMP = 1557489395327L; //起始的时间戳
private static final long SEQUENCE_BIT = 12; //序列号占用位数
private static final long MACHINE_BIT = 10; //机器标识占用位数
private static final long TIMESTAMP_LEFT = SEQUENCE_BIT + MACHINE_BIT; //时间戳位移位数
private static final long MAX_SEQUENCE = ~(-1L << SEQUENCE_BIT); //最大序列号
private static final long MAX_MACHINE_ID = ~(-1L << MACHINE_BIT); //最大机器编号
private long machineIdPart; //生成id机器标识部分
private long sequence = 0L; //序列号
private long lastStamp = -1L; //上一次时间戳
private SnowFlake() {
RedissonClient client = RedisFactory.getDefault();
RAtomicLong atomicLong = client.getAtomicLong("SnowFlake:MachineId");
machineIdPart = (atomicLong.addAndGet(1L) & MAX_MACHINE_ID) << SEQUENCE_BIT;
}
public synchronized long nextId() {
long currentStamp = System.currentTimeMillis();
while (currentStamp < lastStamp) { //避免机器时钟回拨
currentStamp = System.currentTimeMillis();
}
if (currentStamp == lastStamp) {
sequence++; //相同毫秒内,序列号自增
if (sequence > MAX_SEQUENCE) { //同一毫秒的序列数已经达到最大
currentStamp = getNextMill();
sequence = 0L;
}
} else {
sequence = 0L; //不同毫秒内,序列号置0
}
lastStamp = currentStamp;
return (currentStamp - START_TIMESTAMP) << TIMESTAMP_LEFT | machineIdPart | sequence; //时间戳部分+机器标识部分+序列号部分
}
private long getNextMill() {
long mill = System.currentTimeMillis();
while (mill <= lastStamp) {
mill = System.currentTimeMillis();
}
return mill;
}
}
public static long uniqueLong() {
return SnowFlake.SNOW_FLAKE.nextId();
}
public static String uniqueLongHex() {
return String.format("%016x", uniqueLong());
}
public static void main(String[] args) {
long start = System.currentTimeMillis();
final CountDownLatch latch = new CountDownLatch(100);
final Map<Long, Integer> map = new ConcurrentHashMap<Long, Integer>();
for (int i = 0; i < 100; i++) {
new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 20000; i++) {
Integer put = map.put(UniqueIdUtils.uniqueLong(), 1);
if (put != null) {
throw new RuntimeException("主键重复");
}
}
latch.countDown();
}
}).start();
}
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(System.currentTimeMillis() - start);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.gic</groupId>
<artifactId>gic-demo-pom</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>gic-demo-config</artifactId>
<name>${project.artifactId}</name>
<version>${libraryVersion}</version>
<url>http://www.demogic.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<libraryVersion>1.0-SNAPSHOT</libraryVersion>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-platform-config</artifactId>
</dependency>
<dependency>
<groupId>com.gic</groupId>
<artifactId>gic-demo-common</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
dubbo.spring.config=classpath*\:applicationContext-conf.xml
dubbo.protocol.dubbo.payload=41557050
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:apollo="http://www.ctrip.com/schema/apollo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.ctrip.com/schema/apollo
http://www.ctrip.com/schema/apollo.xsd">
<apollo:config namespaces="COMMON.gic-properties"/>
<bean class="com.gic.demo.common.init.SpringContextHolder"/>
<bean id="proConfig" class="com.gic.commons.init.CustomizedPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:dubbo-project.properties</value>
</list>
</property>
</bean>
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="terminal" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="TRACE"/>
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p [%c:%L] %m%n"/>
</layout>
</appender>
<logger name="com.gic">
<level value="DEBUG"/>
</logger>
<logger name="org.hibernate.SQL">
<level value="DEBUG"/>
</logger>
<!-- <logger name="org.springframework">-->
<!-- <level value="INFO"/>-->
<!-- </logger>-->
<logger name="Sharding-JDBC-SQL">
<level value="INFO"/>
</logger>
<logger name="org.hibernate.type.descriptor.sql.BasicBinder">
<level value="DEBUG" />
</logger>
<root>
<!-- <level value="DEBUG"/>-->
<level value="WARN"/>
<appender-ref ref="terminal"/>
<!--<appender-ref ref="logfile"/>-->
</root>
</log4j:configuration>
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="error" packages="com.gic.commons.log">
<appenders>
<!--这个输出控制台的配置-->
<Console name="Console" target="SYSTEM_OUT">
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY" />
<!--这个都知道是输出日志的格式-->
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c:%L] [%traceId] %m%n" />
</Console>
<!--这个会打印出所有的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<!-- <RollingFile name="RollingFile" fileName="${backupFilePatch}${fileName}"
filePattern="${backupFilePatch}$${date:yyyy-MM}/app-%d{yyyyMMddHHmmssSSS}.log.gz">
<PatternLayout
pattern="%d{yyyy.MM.dd 'at' HH:mm:ss.SSS z} %-5level %class{36} %L %M - %msg%xEx%n" />
<SizeBasedTriggeringPolicy size="20MB" />
<DefaultRolloverStrategy max="20"/>
</RollingFile> -->
</appenders>
<loggers>
<!--建立一个默认的root的logger-->
<Logger name="com.gic" level="DEBUG"/>
<!-- <Logger name="org.springframework" level="INFO"/>-->
<logger name="Sharding-JDBC-SQL" level="INFO"/>
<logger name="org.hibernate.SQL" level="DEBUG"/>
<logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="DEBUG"/>
<Root level="WARN">
<!-- <Root level="DEBUG">-->
<AppenderRef ref="Console" />
<!-- <AppenderRef ref="RollingFile" />-->
</Root>
</loggers>
</configuration>
package com.gic;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* Unit test for simple App.
*/
public class AppTest
{
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.gic</groupId>
<artifactId>gic-demo-pom</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>gic-demo-helper</artifactId>
<version>${libraryVersion}</version>
<name>${project.artifactId}</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<libraryVersion>1.0-SNAPSHOT</libraryVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.gic.demo.helper.generator;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class GeneratorStartUp {
public static void main(String[] args) {
try {
List<String> warnings = new ArrayList<>();
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is = classloader.getResourceAsStream("generatorConfig_test.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(is);
DefaultShellCallback callback = new DefaultShellCallback(true);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
package com.gic.demo.helper.generator;
import org.mybatis.generator.api.CommentGenerator;
import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.config.PropertyRegistry;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.Set;
import static org.mybatis.generator.internal.util.StringUtility.isTrue;
public class MyCommentGenerator implements CommentGenerator {
private Properties properties;
private Properties systemPro;
private boolean suppressDate;
private boolean suppressAllComments;
private String currentDateStr;
public MyCommentGenerator() {
super();
properties = new Properties();
systemPro = System.getProperties();
suppressDate = false;
suppressAllComments = false;
currentDateStr = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date());
}
public void addJavaFileComment(CompilationUnit compilationUnit) {
}
public void addComment(XmlElement xmlElement) {
}
public void addRootComment(XmlElement rootElement) {
}
@Override
public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable, Set<FullyQualifiedJavaType> imports) {
}
@Override
public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> imports) {
}
@Override
public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable, Set<FullyQualifiedJavaType> imports) {
}
@Override
public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> imports) {
}
@Override
public void addClassAnnotation(InnerClass innerClass, IntrospectedTable introspectedTable, Set<FullyQualifiedJavaType> imports) {
}
public void addConfigurationProperties(Properties properties) {
this.properties.putAll(properties);
suppressDate = isTrue(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_DATE));
suppressAllComments = isTrue(properties.getProperty(PropertyRegistry.COMMENT_GENERATOR_SUPPRESS_ALL_COMMENTS));
}
private String getDateString() {
String result = null;
if (!suppressDate) {
result = currentDateStr;
}
return result;
}
public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
if (suppressAllComments) {
return;
}
StringBuilder sb = new StringBuilder();
innerClass.addJavaDocLine("/**");
sb.append(" * ");
sb.append(introspectedTable.getFullyQualifiedTable());
sb.append(" ");
sb.append(getDateString());
innerClass.addJavaDocLine(sb.toString().replace("\n", " "));
innerClass.addJavaDocLine(" */");
}
public void addEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) {
if (suppressAllComments) {
return;
}
StringBuilder sb = new StringBuilder();
innerEnum.addJavaDocLine("/**");
sb.append(" * ");
sb.append(introspectedTable.getFullyQualifiedTable());
innerEnum.addJavaDocLine(sb.toString().replace("\n", " "));
innerEnum.addJavaDocLine(" */");
}
public void addFieldComment(Field field, IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
if (suppressAllComments) {
return;
}
StringBuilder sb = new StringBuilder();
field.addJavaDocLine("/**");
sb.append(" * ");
sb.append(introspectedColumn.getRemarks());
field.addJavaDocLine(sb.toString().replace("\n", " "));
field.addJavaDocLine(" */");
}
public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
if (suppressAllComments) {
return;
}
StringBuilder sb = new StringBuilder();
field.addJavaDocLine("/**");
sb.append(" * ");
sb.append(introspectedTable.getFullyQualifiedTable());
field.addJavaDocLine(sb.toString().replace("\n", " "));
field.addJavaDocLine(" */");
}
@Override
public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
topLevelClass.addJavaDocLine("/**");
String sb = " * " + introspectedTable.getFullyQualifiedTable();
topLevelClass.addJavaDocLine(sb.replace("\n", " "));
topLevelClass.addJavaDocLine(" */");
}
public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
}
public void addGetterComment(Method method, IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
}
public void addSetterComment(Method method, IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
}
public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
if (suppressAllComments) {
return;
}
innerClass.addJavaDocLine("/**");
String sb = " * " + introspectedTable.getFullyQualifiedTable();
innerClass.addJavaDocLine(sb.replace("\n", " "));
innerClass.addJavaDocLine(" */");
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="testTables" targetRuntime="MyBatis3">
<!-- 这里的type里写的是你的实现类的类全路径 -->
<commentGenerator type="com.gic.demo.helper.generator.MyCommentGenerator">
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<!--<property name="suppressAllComments" value="true"/>-->
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://56cbb9f62fac6.sh.cdb.myqcloud.com:6634/test?characterEncoding=utf-8"
userId="cdb_outerroot"
password="@09ui%sbc09">
</jdbcConnection>
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- dto class -->
<javaModelGenerator targetPackage="com.gic.demo.project.service.entity" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaModelGenerator>
<!-- mybatis xml file -->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- mapper class -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.gic.demo.project.service.dao.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 指定数据库表 -->
<table tableName="tab_gic_demo_enterprise" enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false"/>
<table tableName="tab_gic_demo_store" enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false"/>
<!-- 有些表的字段需要指定java类型 -->
<!-- <table schema="" tableName="">-->
<!-- <columnOverride column="" javaType="" />-->
<!-- </table>-->
</context>
</generatorConfiguration>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gic</groupId>
<artifactId>gic-demo-base</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<modules>
<module>gic-demo-base-api</module>
<module>gic-demo-config</module>
<module>gic-demo-common</module>
<module>gic-demo-helper</module>
</modules>
<distributionManagement>
<repository>
<!-- 和 Maven setting 保持一致 -->
<id>nexus-snapshots</id>
<name>nexus distribution snapshot repository</name>
<!-- 这里使用 /content/repositories/snapshots/ -->
<url>http://182.254.134.223:8081/nexus/content/repositories/snapshots/</url>
<!--<url>http://stream.banli.mobi:8081/content/repositories/snapshots/</url>-->
</repository>
<snapshotRepository>
<!-- 和 Maven setting 保持一致 -->
<id>nexus-snapshots</id>
<name>nexus distribution snapshot repository</name>
<!-- 这里使用 /content/repositories/snapshots/ -->
<url>http://182.254.134.223:8081/nexus/content/repositories/Snapshots-1/</url>
<!--<url>http://stream.banli.mobi:8081/content/repositories/snapshots/</url>-->
</snapshotRepository>
</distributionManagement>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment