Commit f53b4cfe by 钟明宏

测试一下提交

parent cd9bbd32
......@@ -27,16 +27,18 @@
<orderEntry type="library" name="Maven: stax:stax-api:1.0.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml:3.17" level="project" />
<orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.04" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: com.monitorjbl:xlsx-streamer:1.2.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:ooxml-schemas:1.3" level="project" />
<orderEntry type="library" name="Maven: xerces:xercesImpl:2.11.0" level="project" />
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.12" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.8" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.8" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: mysql:mysql-connector-java:5.1.28" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.25" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: mysql:mysql-connector-java:8.0.15" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.google.protobuf:protobuf-java:3.6.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.projectlombok:lombok:1.18.12" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -56,6 +56,7 @@
</repositories>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
......@@ -111,7 +112,14 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.28</version>
<version>8.0.15</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>test</scope>
</dependency>
</dependencies>
......
......@@ -16,101 +16,101 @@ import cn.yunmaozj.tools.excel.utils.StringUtils;
*/
public class ValidationUitls {
public static void validation(String paranName,String TypeName,Object paramValue,Colum colum){
public static void validation(String paramName,String TypeName,Object paramValue,Colum colum){
if(TypeName.equals(String.class.getTypeName()) || paramValue instanceof String){
validationString(paranName,(String)paramValue,colum);
validationString(paramName,(String)paramValue,colum);
}else if(TypeName.equals(Integer.class.getTypeName()) || paramValue instanceof Integer){
validationInteger(paranName,(Integer)paramValue,colum);
validationInteger(paramName,(Integer)paramValue,colum);
}else if(TypeName.equals(Double.class.getTypeName()) || paramValue instanceof Double){
validationDouble(paranName,(Double)paramValue, colum);
validationDouble(paramName,(Double)paramValue, colum);
}else if(TypeName.equals(Float.class.getTypeName()) || paramValue instanceof Float){
validationFloat(paranName, (Float)paramValue, colum);
validationFloat(paramName, (Float)paramValue, colum);
}else if(TypeName.equals(Character.class.getTypeName()) || paramValue instanceof Character){
validationCharacter(paranName, (Character)paramValue, colum);
validationCharacter(paramName, (Character)paramValue, colum);
}else if(TypeName.equals(Short.class.getTypeName()) || paramValue instanceof Short){
validationSort(paranName, (Short)paramValue, colum);
validationSort(paramName, (Short)paramValue, colum);
}else if(TypeName.equals(Long.class.getTypeName()) || paramValue instanceof Long){
validationLong(paranName, (Long)paramValue, colum);
validationLong(paramName, (Long)paramValue, colum);
}else if(paramValue instanceof Collection<?>){
validationCollection(paranName, (Collection<?>)paramValue, colum);
validationCollection(paramName, (Collection<?>)paramValue, colum);
}
}
public static void validationString(String paranName,String paramValue,Colum colum){
public static void validationString(String paramName,String paramValue,Colum colum){
if(colum.NotEmpty() && StringUtils.isEmpty(paramValue)){
throwException(String.format("%s must not null", paranName), colum);
throwException(String.format("%s must not null", paramName), colum);
}
if(paramValue != null && paramValue.length() > colum.maxLength()){
throwException(String.format("The length of %s cannot be greater than %d",paranName,colum.maxLength()), colum);
throwException(String.format("The length of %s cannot be greater than %d",paramName,colum.maxLength()), colum);
}
if(colum.regex().length > 0){
validationRegex(paranName, paramValue, colum);
validationRegex(paramName, paramValue, colum);
}
}
public static void validationInteger(String paranName,Integer paramValue,Colum colum){
public static void validationInteger(String paramName,Integer paramValue,Colum colum){
if(colum.NotNull() && paramValue == null){
throwException(String.format("%s must not null", paranName), colum);
throwException(String.format("%s must not null", paramName), colum);
}
if(paramValue != null && (paramValue > colum.max() && paramValue < colum.min())){
throwException(String.format("The value of this %s cannot be greater than %d is less than %d",paranName,colum.max(),colum.min()), colum);
throwException(String.format("The value of this %s cannot be greater than %d is less than %d",paramName,colum.max(),colum.min()), colum);
}
}
public static void validationDouble(String paranName,Double paramValue,Colum colum){
public static void validationDouble(String paramName,Double paramValue,Colum colum){
if(colum.NotNull() && paramValue == null){
throwException(String.format("%s must not null", paranName),colum);
throwException(String.format("%s must not null", paramName),colum);
}
if(paramValue != null && (paramValue < colum.minDouble() || paramValue > colum.maxDouble())){
throwException(String.format("The value of this %s cannot be greater than %f is less than %f",paranName,colum.maxDouble(),colum.minDouble()), colum);
throwException(String.format("The value of this %s cannot be greater than %f is less than %f",paramName,colum.maxDouble(),colum.minDouble()), colum);
}
}
@Deprecated
public static void validationFloat(String paranName,Float paramValue,Colum colum){
public static void validationFloat(String paramName,Float paramValue,Colum colum){
}
public static void validationRegex(String paranName,String paramValue,Colum colum){
public static void validationRegex(String paramName,String paramValue,Colum colum){
for(String pattern : colum.regex()){
if(!Pattern.matches(pattern, paramValue)){
throwException(String.format("This %s has a value format error",paranName),colum);
throwException(String.format("This %s has a value format error",paramName),colum);
}
}
}
public static void validationSort(String paranName,Short paramValue,Colum colum){
public static void validationSort(String paramName,Short paramValue,Colum colum){
if(colum.NotNull() && paramValue == null){
throwException(String.format("%s must not null", paranName),colum);
throwException(String.format("%s must not null", paramName),colum);
}
if(paramValue != null && (paramValue < colum.minShort() || paramValue > colum.maxShort())){
throwException(String.format("The value of this %s cannot be greater than %d is less than %d",paranName,colum.maxShort(),colum.minShort()), colum);
throwException(String.format("The value of this %s cannot be greater than %d is less than %d",paramName,colum.maxShort(),colum.minShort()), colum);
}
}
@Deprecated
public static void validationCharacter(String paranName,Character paramValue,Colum colum){
public static void validationCharacter(String paramName,Character paramValue,Colum colum){
}
public static void validationLong(String paranName,Long paramValue,Colum colum){
public static void validationLong(String paramName,Long paramValue,Colum colum){
if(colum.NotNull() && paramValue == null){
throwException(String.format("%s must not null", paranName),colum);
throwException(String.format("%s must not null", paramName),colum);
}
if(paramValue != null && (paramValue < colum.minLong() || paramValue > colum.maxLong())){
throwException(String.format("The value of this %s cannot be greater than %d is less than %d",paranName,colum.maxLong(),colum.minLong()), colum);
throwException(String.format("The value of this %s cannot be greater than %d is less than %d",paramName,colum.maxLong(),colum.minLong()), colum);
}
}
public static void validationCollection(String paranName,Collection<?> paramValue,Colum colum){
public static void validationCollection(String paramName,Collection<?> paramValue,Colum colum){
if(colum.NotNull() && paramValue == null){
throwException(String.format("%s must not null", paranName),colum);
throwException(String.format("%s must not null", paramName),colum);
}
if(paramValue != null && paramValue.size() < colum.minLength()){
throwException(String.format("The length of %s cannot be greater than %d",paranName,colum.maxLength()),colum);
throwException(String.format("The length of %s cannot be greater than %d",paramName,colum.maxLength()),colum);
}
}
......
package cn.yunmaozj.tools.excel.model.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 这个注解用来标注实体类的字段 和 excel 的表头
*
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2020-06-24 14:43
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ExcelField {
String value();
/**
* 是否必填
*
* @return
*/
boolean require() default false;
/**
* 排序字段
*
* @return
*/
int sort() default 0;
/**
* 允许输入的值
*
* @return
*/
String[] allowableValues() default {};
}
......@@ -16,14 +16,14 @@ public class PropertyUtils {
private Class<?> clazz;
private Map<String,Method> cachemap;
private Map<String,Method> cacheMap;
private PropertyDescriptor propertyDescriptor;
public PropertyUtils(Class<?> clazz) {
super();
this.clazz = clazz;
cachemap = new HashMap<String,Method>();
cacheMap = new HashMap<String,Method>();
}
public static PropertyDescriptor getPropertyDescriptor(Class<?> cla,String propertyName){
......@@ -137,7 +137,7 @@ public class PropertyUtils {
public synchronized void setCacheProperty(Object object,String propertyName,Object value){
Method setMethod;
if(cachemap.get(propertyName) == null){
if(cacheMap.get(propertyName) == null){
try {
initPropertyDescriptor(propertyName);//初始化set方法对象
} catch (NoSuchFieldException e) {
......@@ -151,7 +151,7 @@ public class PropertyUtils {
}
setMethod = propertyDescriptor.getWriteMethod();//从属性描述其中获取set方法
}else{
setMethod = cachemap.get(propertyName);
setMethod = cacheMap.get(propertyName);
}
try{
setMethod.invoke(object,new Object[]{value});//调用set方法将的value值保存属性中
......@@ -162,7 +162,7 @@ public class PropertyUtils {
public Object getCacheProperty(Object obj, String propertyName){
Method getMethod;
if(cachemap.get(propertyName) == null){
if(cacheMap.get(propertyName) == null){
try {
initPropertyDescriptor(propertyName); //初始化set方法
} catch (NoSuchFieldException e) {
......@@ -176,7 +176,7 @@ public class PropertyUtils {
}
getMethod = propertyDescriptor.getReadMethod();//从属性描述器中获取 get 方法
}else{
getMethod = cachemap.get(propertyName);
getMethod = cacheMap.get(propertyName);
}
Object value =null ;
......
package cn.yunmaozj.tools.excel.model;
import cn.yunmaozj.tools.excel.core.Excel;
import cn.yunmaozj.tools.excel.model.annotations.ExcelField;
import lombok.Getter;
import lombok.Setter;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2020-06-24 13:34
*/
@Getter
@Setter
public class OpusImportModel {
@ExcelField("标题")
private String title;
@ExcelField("内容")
private String content;
@ExcelField("手机号")
private String mobile;
@ExcelField("资源")
private String resource;
@ExcelField("作品类型")
private String opusType;
@ExcelField("话题")
private String topics;
}
package cn.yunmaozj.tools.excel.sql;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.sql.*;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2020-04-19 20:25
*/
public class MysqlTest {
private String url = "jdbc:mysql://120.25.127.156:3306/mysql?useUnicode=yes&characterEncoding=UTF-8&useInformationSchema=true&useSSL=false&serverTimezone=UTC";
private String user = "root";
private String password = "hgL0oT%koZZw";
private String driver = "com.mysql.cj.jdbc.Driver";
private Connection connection;
@Test
public void demo() throws SQLException {
PreparedStatement statement = connection.prepareStatement("SELECT * FROM `COLUMNS` WHERE TABLE_SCHEMA = 'user'");
ResultSet resultSet = statement.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
for(int i=1;i<=metaData.getColumnCount();i++){
System.out.println(metaData.getColumnName(i));
}
while (resultSet.next()){
for(int i=1;i<=metaData.getColumnCount();i++){
System.out.println(metaData.getColumnName(i)+" Value -> "+resultSet.getObject(i));
}
}
}
@Before
public void init() throws SQLException, ClassNotFoundException {
Class.forName(driver);
connection = DriverManager.getConnection(url, user, password);
}
@After
public void close() throws SQLException {
if (!connection.isClosed()) {
connection.close();
}
}
}
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 sign in to comment