Commit 33e7d7ee authored by 李丛阳's avatar 李丛阳

education init

parents
*.idea
*.iml
target/
\ No newline at end of file
This diff is collapsed.
# lombok 简介
@NonNull : 注解在参数上, 如果该类参数为 null , 就会报出异常, throw new NullPointException(参数名)
@Cleanup : 注释在引用变量前, 自动回收资源 默认调用 close() 方法
@Getter/@Setter : 注解在类上, 为类提供读写属性
@Getter(lazy=true) :
@ToString : 注解在类上, 为类提供 toString() 方法
@EqualsAndHashCode : 注解在类上, 为类提供 equals() 和 hashCode() 方法
@NoArgsConstructor, @RequiredArgsConstructor, @AllArgsConstructor : 注解在类上, 为类提供无参,有指定必须参数, 全参构造函数
@Data : 注解在类上, 为类提供读写属性, 此外还提供了 equals()、hashCode()、toString() 方法
@Value :
@Builder : 注解在类上, 为类提供一个内部的 Builder
@SneakThrows :
@Synchronized : 注解在方法上, 为方法提供同步锁
@Log :
@Log4j : 注解在类上, 为类提供一个属性名为 log 的 log4j 的日志对象
@Slf4j : 注解在类上, 为类提供一个属性名为 log 的 log4j 的日志对象
package org.rcisoft.core.anno;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Created by lcy on 17/11/16.
*/
@Target({FIELD})
@Retention(RUNTIME)
public @interface OperateFlagAnno {
/**
* jdbcType
* @return
*/
public String jdbcTypeName() default "";
}
package org.rcisoft.core.base;
import org.rcisoft.core.mapper.LogicalDeleteMapper;
import tk.mybatis.mapper.common.Mapper;
/**
* base mapper
* @param <T>
*/
public interface BaseMapper<T> extends Mapper<T>,LogicalDeleteMapper<T> {
}
package org.rcisoft.core.constant;
/**
* Created with family.
* author: cy
* Date: 16/6/23
* Time: 下午2:06
* description:
*/
public enum DelStatus {
//正常0 逻辑删除1
NORMAL("0"),DELETED("1");
private String status;
public String getStatus(){
return status;
}
private DelStatus(String status){
this.status = status;
}
}
package org.rcisoft.core.constant;
/**
* Created by lcy on 17/11/16.
*/
public class FamilyMapperCons {
public static class JdbcType{
//时间戳
public static final String TIMESTAMP = "TIMESTAMP";
}
}
package org.rcisoft.core.constant;
/**
* Created with family.
* author: cy
* Date: 16/6/23
* Time: 下午2:06
* description:
*/
public enum FlagStatus {
//启用1 停用0
NORMAL("1"),ABNORMAL("0");
private String status;
public String getStatus(){
return status;
}
private FlagStatus(String status){
this.status = status;
}
}
package org.rcisoft.core.mapper;
import org.apache.ibatis.annotations.UpdateProvider;
import org.rcisoft.core.mapper.impl.LogicalDeleteMapperImpl;
/**
* Created by lcy on 17/11/16.
*/
public interface LogicalDeleteMapper<T> {
/**
* 逻辑删除
* @param record
* @return
*/
@UpdateProvider(type = LogicalDeleteMapperImpl.class, method = "dynamicSQL")
int logicalDelete(T record);
}
package org.rcisoft.core.mapper.impl;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.mapping.MappedStatement;
import org.rcisoft.core.anno.OperateFlagAnno;
import org.rcisoft.core.constant.FamilyMapperCons;
import tk.mybatis.mapper.entity.EntityColumn;
import tk.mybatis.mapper.entity.EntityTable;
import tk.mybatis.mapper.mapperhelper.EntityHelper;
import tk.mybatis.mapper.mapperhelper.MapperHelper;
import tk.mybatis.mapper.mapperhelper.MapperTemplate;
import tk.mybatis.mapper.mapperhelper.SqlHelper;
import java.lang.reflect.Field;
import java.util.*;
import static tk.mybatis.mapper.mapperhelper.EntityHelper.getEntityTable;
/**
* Created by lcy on 17/11/16.
*
* 逻辑删除 mapper
*/
public class LogicalDeleteMapperImpl extends MapperTemplate {
public LogicalDeleteMapperImpl(Class<?> mapperClass, MapperHelper mapperHelper) {
super(mapperClass, mapperHelper);
}
/**
* 逻辑删除
* @param record
* @return
*/
public String logicalDelete(MappedStatement record){
//WebappClassLoader 加载, 使用 cacheConstructor ,未加载属性,所以需要实例化,再获取class
Class<?> entityClass = getEntityClass(record);
//获取表的各项属性
EntityTable table = getEntityTable(entityClass);
Set<EntityColumn> cols = table.getEntityClassColumns();
//获取表的各项属性 数组
List<Field> fields = new ArrayList<Field>();
Object t = null;
Class tClass = null;
try {
t = Class.forName(entityClass.getName()).newInstance();
tClass = t.getClass();
while(Object.class != tClass){
fields.addAll(Arrays.asList(tClass.getDeclaredFields()));
tClass = tClass.getSuperclass();
}
} catch (Exception e) {
e.printStackTrace();
}
//开始拼sql
StringBuilder sql = new StringBuilder();
//sql.append(" <script> "); //不支持script
sql.append(SqlHelper.updateTable(entityClass, this.tableName(entityClass)));
sql.append(" <trim prefix=\"SET\" suffixOverrides=\",\"> ");
Set<EntityColumn> columnList = EntityHelper.getColumns(entityClass);
Iterator var6 = columnList.iterator();
//遍历
while(var6.hasNext()) {
EntityColumn column = (EntityColumn)var6.next();
for (int i = 0; i < fields.size(); i++) {
if(!column.getProperty().equals(fields.get(i).getName()))
continue;
OperateFlagAnno meta = fields.get(i).getAnnotation(OperateFlagAnno.class);
/*逻辑操作字段*/
if(meta != null){
String jdbcType = meta.jdbcTypeName();
/*时间戳*/
if(StringUtils.isNotBlank(jdbcType) &&
FamilyMapperCons.JdbcType.TIMESTAMP.equals(jdbcType))
sql.append("<if test=\"" + column.getProperty() + " !=null \" > "
+ column.getColumn()
+ " = #{" + column.getProperty() + "} , </if>");
else
sql.append("<if test=\"" + column.getProperty() + " !=null and " +
column.getProperty() + " !='' \" > " + column.getColumn()
+ " = #{" + column.getProperty() + "} , </if>");
}
break;
}
}
sql.append(" </trim> ");
sql.append(SqlHelper.wherePKColumns(entityClass));
//sql.append(" </script> ");
return sql.toString();
}
}
package org.rcisoft.education;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* Created by lcy on 17/8/9.
*/
@SpringBootApplication
@EnableTransactionManagement
@EnableAspectJAutoProxy
@EnableSwagger2
@EnableScheduling
@MapperScan(basePackages = "org.rcisoft.**.dao")//扫描dao 不需要@repository
public class EducationApplication {
public static void main(String[] args) {
SpringApplication.run(EducationApplication.class, args);
}
}
server:
port: 8081
context-path: / #ContextPath must start with '/' and not end with '/'
tomcat:
max-threads: 300
#uri-encoding: UTF-8
logging:
level:
root: INFO
org.springframework.web: DEBUG
druid:
url: jdbc:mysql://127.0.0.1:3306/boot?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
username: root
password: cy
initial-size: 1
min-idle: 1
max-active: 20
test-on-borrow: true
mybatis:
mapper-locations: classpath:mapper/*.xml
mapper:
mappers:
- org.rcisoft.core.base.BaseMapper
not-empty: false
identity: MYSQL
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
spring:
jackson:
default-property-inclusion: non_null
#http:
# encoding:
# force: true
# charset: UTF-8
# enabled: true
multipart:
max-file-size: 100Mb
max-request-size: 1000Mb
mvc:
throw-exception-if-no-handler-found: true
resources:
add-mappings: false
springfox:
documentation:
swagger:
v2:
path: /api-docs
#jwtAuth:
# header: Authorization
# token_header: CyBear
# secret_key: base64EncodedSecretKey
jwt:
header: Authorization
secret: mySecret
expiration: 604800
tokenHead: "Bearer "
route:
authentication:
path: "/login"
refresh: "/refresh"
register: "/register"
\ No newline at end of file
server:
port: 8081
context-path: / #ContextPath must start with '/' and not end with '/'
tomcat:
max-threads: 300
logging:
level:
root: INFO
org.springframework.web: DEBUG
druid:
url: jdbc:mysql://127.0.0.1:3306/boot?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
username: root
password: cy
initial-size: 1
min-idle: 1
max-active: 20
test-on-borrow: true
mybatis:
mapper-locations: classpath:mapper/*.xml
mapper:
mappers:
- org.yxyqcy.sys.base.BaseMapper
not-empty: false
identity: MYSQL
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
spring:
jackson:
default-property-inclusion: non_null
http:
multipart:
max-file-size: 100Mb
max-request-size: 1000Mb
mvc:
throw-exception-if-no-handler-found: true
resources:
add-mappings: false
jwt:
header: Authorization
secret: mySecret
expiration: 604800
tokenHead: "Bearer "
route:
authentication:
path: auth
refresh: refresh
register: "auth/register"
\ No newline at end of file
spring:
profiles:
active: dev
\ No newline at end of file
山不在高,有仙则名。水不在深,有龙则灵。
斯是陋室,惟吾德馨。
苔痕上阶绿,草色入帘青。谈笑有鸿儒,往来无白丁。
可以调素琴,阅金经。无丝竹之乱耳,无案牍之劳形。
南阳诸葛庐,西蜀子云亭。孔子云:何陋之有?
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>
%d - %msg%n
</pattern>
</layout>
</appender>
<appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>DENY</onMatch>
<onMismatch>ACCEPT</onMismatch>
</filter>
<encoder>
<pattern>
%date %-5level [%thread] %logger{43}\(%L\) : %msg
</pattern>
</encoder>
<!--滚动策略-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--路径-->
<fileNamePattern>/working/test/info.%d.log</fileNamePattern>
</rollingPolicy>
</appender>
<!--https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx50601fe1a9207d84&redirect_uri=http://gwf.natapp4.cc/sell/weixin/auth&response_type=code&scope=snsapi_userinfo&state=gwf#wechat_redirect-->
<appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--
临界值过滤器,过滤掉低于指定临界值的日志。当日志级别等于或高于临界值时,过滤器返回NEUTRAL;当日志级别低于临界值时,日志会被拒绝
-->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<encoder>
<pattern>
%date %-5level [%thread] %logger{43}\(%L\) : %msg
</pattern>
</encoder>
<!--滚动策略-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--路径-->
<fileNamePattern>/working/test/error.%d.log</fileNamePattern>
</rollingPolicy>
</appender>
<!--
指定对应包名
-->
<logger name="com.minlia" level="DEBUG"/>
<logger name="org.springframework.data.mybatis" level="DEBUG"/>
<logger name="org.springframework.aop.aspectj" level="ERROR"/>
<springProfile name="dev">
<root level="info">
<appender-ref ref="consoleLog" />
<appender-ref ref="fileInfoLog" />
<appender-ref ref="fileErrorLog" />
</root>
</springProfile>
<springProfile name="prod">
<root level="info">
<appender-ref ref="consoleLog" />
<appender-ref ref="fileInfoLog" />
<appender-ref ref="fileErrorLog" />
</root>
</springProfile>
</configuration>
\ 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