浏览框触发文件复制-一对多

dev
IT-xiaoXiong 2021-12-22 19:26:10 +08:00
parent e603fd7ad2
commit 96f1607dcd
22 changed files with 401 additions and 195 deletions

2
.gitignore vendored
View File

@ -23,6 +23,8 @@ log
/target /target
/lib/classbean /lib/classbean
.idea/ .idea/
src/main/java/.gitignore
src/main/java/README.md
!/src/main/resources/WEB-INF/prop/prop2map/*.properties !/src/main/resources/WEB-INF/prop/prop2map/*.properties
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` # Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
# should NOT be excluded as they contain compiler settings and other important # should NOT be excluded as they contain compiler settings and other important

View File

@ -1,74 +0,0 @@
package aiyh.utils;
import aiyh.utils.zwl.common.ToolUtil;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
/**
* @author EBU7-dev1-ayh
* @date 2021/8/25 0025 10:53
*
*/
public class HotDeployToolUtil extends ClassLoader {
ToolUtil toolUtil = new ToolUtil();
private final String classpath;
private final String className;
public HotDeployToolUtil(String classpath, String className) {
this.classpath = classpath;
this.className = className;
}
@Override
public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
Class<?> loadedClass = findLoadedClass(name);
// 需要我自己去加载
if (loadedClass == null) {
loadedClass = findClass(name);
if (loadedClass != null) {
return loadedClass;
}
}
return super.loadClass(name, resolve);
}
@Override
public Class<?> findClass(String name) throws ClassNotFoundException {
if (name.startsWith("java.")) {
return getSystemClassLoader().loadClass(name);
}
byte[] data;
String classPath = name.replace(".", System.getProperties().getProperty("file.separator")) + ".class";
try {
data = this.loadClassData(classPath);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return this.defineClass(name, data, 0, data.length);
}
public byte[] loadClassData(String name) throws Exception {
FileInputStream inputStream;
try {
toolUtil.writeDebuggerLog(classpath + name);
inputStream = new FileInputStream(classpath + name);
// 定义字节数组输出流
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int b = 0;
while ((b = inputStream.read()) != -1) {
baos.write(b);
}
inputStream.close();
return baos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
throw new ClassNotFoundException();
}
}
}

View File

@ -5,6 +5,7 @@ import aiyh.utils.entity.*;
import aiyh.utils.fileUtil.ProperUtil; import aiyh.utils.fileUtil.ProperUtil;
import aiyh.utils.mapUtil.UtilHashMap; import aiyh.utils.mapUtil.UtilHashMap;
import aiyh.utils.mapUtil.UtilLinkedHashMap; import aiyh.utils.mapUtil.UtilLinkedHashMap;
import aiyh.utils.recordset.RecordsetUtil;
import aiyh.utils.service.UtilService; import aiyh.utils.service.UtilService;
import aiyh.utils.sqlUtil.builderSql.impl.BuilderSqlImpl; import aiyh.utils.sqlUtil.builderSql.impl.BuilderSqlImpl;
import aiyh.utils.sqlUtil.whereUtil.Where; import aiyh.utils.sqlUtil.whereUtil.Where;
@ -55,6 +56,7 @@ public class Util extends weaver.general.Util {
static ToolUtil toolUtil = new ToolUtil(); static ToolUtil toolUtil = new ToolUtil();
private static final UtilService utilService = new UtilService(); private static final UtilService utilService = new UtilService();
private static final RecordSet rs = new RecordSet(); private static final RecordSet rs = new RecordSet();
private static RecordsetUtil recordsetUtil = new RecordsetUtil();;
/** /**
@ -144,6 +146,12 @@ public class Util extends weaver.general.Util {
return str; return str;
} }
/**
*
* @param sqlBuilder StringBuilder
* @param removeSeparator
* @return
*/
public static String removeSeparator(StringBuilder sqlBuilder, String removeSeparator) { public static String removeSeparator(StringBuilder sqlBuilder, String removeSeparator) {
String str = sqlBuilder.toString().trim(); String str = sqlBuilder.toString().trim();
if (str.endsWith(removeSeparator)) { if (str.endsWith(removeSeparator)) {
@ -156,6 +164,25 @@ public class Util extends weaver.general.Util {
return str; return str;
} }
/**
*
* @param string
* @param removeSeparator
* @return
*/
public static String removeSeparator(String string, String removeSeparator) {
StringBuilder sqlBuilder = new StringBuilder(string);
String str = sqlBuilder.toString().trim();
if (str.endsWith(removeSeparator)) {
// 如果以分割号结尾,则去除分割号
str = str.substring(0, str.length() - 1);
}
if (str.trim().startsWith(removeSeparator)) {
str = str.substring(1);
}
return str;
}
/** /**
* RecordSetmap * RecordSetmap
* *
@ -1777,4 +1804,14 @@ public class Util extends weaver.general.Util {
}); });
return stringWriter.getBuffer().toString(); return stringWriter.getBuffer().toString();
} }
/**
* RecordSetUtilSQL
* @param t
* @param <T>
* @return
*/
public static <T> T getMapper(Class<T> t) {
return recordsetUtil.getMapper(t);
}
} }

View File

@ -12,5 +12,6 @@ import java.lang.annotation.*;
@Documented @Documented
public @interface Delete { public @interface Delete {
String value() default ""; String value() default "";
// sql是否是在参数中
boolean custom() default false; boolean custom() default false;
} }

View File

@ -11,6 +11,7 @@ import java.lang.annotation.*;
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Documented @Documented
public @interface Insert { public @interface Insert {
String value() default "" ; String value() default "";
// sql是否是在参数中
boolean custom() default false; boolean custom() default false;
} }

View File

@ -11,8 +11,7 @@ import java.lang.annotation.*;
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Documented @Documented
public @interface Select { public @interface Select {
// sql
String value() default ""; String value() default "";
// sql是否是在参数中 // sql是否是在参数中
boolean custom() default false; boolean custom() default false;
} }

View File

@ -12,5 +12,6 @@ import java.lang.annotation.*;
@Documented @Documented
public @interface Update { public @interface Update {
String value() default ""; String value() default "";
// sql是否是在参数中
boolean custom() default false; boolean custom() default false;
} }

View File

@ -2,6 +2,8 @@ package aiyh.utils.recordset;
import weaver.conn.RecordSet; import weaver.conn.RecordSet;
import java.lang.reflect.Field;
/** /**
* @author EBU7-dev1-ayh * @author EBU7-dev1-ayh
* create 2021/12/21 0021 13:34 * create 2021/12/21 0021 13:34
@ -10,12 +12,12 @@ import weaver.conn.RecordSet;
public class BooleanTypeHandler implements TypeHandler{ public class BooleanTypeHandler implements TypeHandler{
@Override @Override
public Object getValue(RecordSet rs, String fieldName) { public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
return rs.getBoolean(fieldName); return rs.getBoolean(fieldName);
} }
@Override @Override
public Object getValue(RecordSet rs, int index) { public Object getValue(RecordSet rs, int index,Field declaredField) {
return rs.getBoolean(index); return rs.getBoolean(index);
} }
} }

View File

@ -1,7 +1,12 @@
package aiyh.utils.recordset; package aiyh.utils.recordset;
import aiyh.utils.annotation.DateFormatAn;
import aiyh.utils.excention.TypeNonsupportException;
import com.ibm.icu.text.SimpleDateFormat;
import weaver.conn.RecordSet; import weaver.conn.RecordSet;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.util.Date; import java.util.Date;
/** /**
@ -10,18 +15,42 @@ import java.util.Date;
*/ */
public class DataTypeHandler implements TypeHandler{ public class DataTypeHandler implements TypeHandler {
@Override @Override
public Object getValue(RecordSet rs, String fieldName) { public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
String dataString = rs.getString(fieldName); if (declaredField == null) {
Date date = new Date(dataString); throw new TypeNonsupportException("An error occurred while trying to convert the query result field to type Date!");
}
DateFormatAn annotation = declaredField.getAnnotation(DateFormatAn.class);
Date date = null;
if (annotation != null) {
String value = annotation.value();
try {
date = new SimpleDateFormat(value).parse(rs.getString(fieldName));
} catch (ParseException e) {
e.printStackTrace();
throw new TypeNonsupportException("Failed to convert [" + rs.getString(fieldName) + "] to a Date object as [" + value + "]!!");
}
}
return date; return date;
} }
@Override @Override
public Object getValue(RecordSet rs, int index) { public Object getValue(RecordSet rs, int index, Field declaredField) {
String dataString = rs.getString(index); if (declaredField == null) {
Date date = new Date(dataString); throw new TypeNonsupportException("An error occurred while trying to convert the query result field to type Date!");
}
DateFormatAn annotation = declaredField.getAnnotation(DateFormatAn.class);
Date date = null;
if (annotation != null) {
String value = annotation.value();
try {
date = new SimpleDateFormat(value).parse(rs.getString(index));
} catch (ParseException e) {
e.printStackTrace();
throw new TypeNonsupportException("Failed to convert [" + rs.getString(index) + "] to a Date object as [" + value + "]!!");
}
}
return date; return date;
} }
} }

View File

@ -2,6 +2,8 @@ package aiyh.utils.recordset;
import weaver.conn.RecordSet; import weaver.conn.RecordSet;
import java.lang.reflect.Field;
/** /**
* @author EBU7-dev1-ayh * @author EBU7-dev1-ayh
* create 2021/12/21 0021 13:10 * create 2021/12/21 0021 13:10
@ -10,12 +12,12 @@ import weaver.conn.RecordSet;
public class IntegerTypeHandler implements TypeHandler{ public class IntegerTypeHandler implements TypeHandler{
@Override @Override
public Object getValue(RecordSet rs, String fieldName) { public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
return rs.getInt(fieldName); return rs.getInt(fieldName);
} }
@Override @Override
public Object getValue(RecordSet rs, int index) { public Object getValue(RecordSet rs, int index,Field declaredField) {
return rs.getInt(index); return rs.getInt(index);
} }
} }

View File

@ -44,6 +44,7 @@ public class RecordsetUtil implements InvocationHandler {
String sql = select.value(); String sql = select.value();
boolean custom = select.custom(); boolean custom = select.custom();
PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args); PrepSqlResultImpl handler = sqlHandler.handler(sql, custom, method, args);
System.out.println(handler);
if (handler.getArgs().isEmpty()) { if (handler.getArgs().isEmpty()) {
rs.executeQuery(handler.getSqlStr()); rs.executeQuery(handler.getSqlStr());
} else { } else {

View File

@ -32,7 +32,7 @@ public class ResultMapper {
typeHandler.put(Long.class, integerTypeHandler); typeHandler.put(Long.class, integerTypeHandler);
typeHandler.put(Boolean.class, new BooleanTypeHandler()); typeHandler.put(Boolean.class, new BooleanTypeHandler());
typeHandler.put(boolean.class, new BooleanTypeHandler()); typeHandler.put(boolean.class, new BooleanTypeHandler());
typeHandler.put(Date.class, new StringTypeHandler()); typeHandler.put(Date.class, new DataTypeHandler());
} }
public <T> T mapperResult(RecordSet rs, Method method, Class<T> tClass) { public <T> T mapperResult(RecordSet rs, Method method, Class<T> tClass) {
@ -48,7 +48,7 @@ public class ResultMapper {
} }
if (ResultMapper.typeHandler.containsKey(tClass)) { if (ResultMapper.typeHandler.containsKey(tClass)) {
rs.next(); rs.next();
return (T) ResultMapper.typeHandler.get(tClass).getValue(rs, 1); return (T) ResultMapper.typeHandler.get(tClass).getValue(rs, 1,null);
} }
T t = tClass.newInstance(); T t = tClass.newInstance();
if (t instanceof Collection) { if (t instanceof Collection) {
@ -82,15 +82,18 @@ public class ResultMapper {
if (o instanceof Map || o instanceof Collection) { if (o instanceof Map || o instanceof Collection) {
throw new TypeNonsupportException("An unsupported return type!"); throw new TypeNonsupportException("An unsupported return type!");
} }
rs.next(); if(rs.next()){
return (T) getObject(rs, t,method); return (T) getObject(rs, t,method);
}
return null;
} }
if (t.getClass().isArray()) { if (t.getClass().isArray()) {
throw new TypeNonsupportException("An unsupported return type!"); throw new TypeNonsupportException("An unsupported return type!");
} }
return (T) getObject(rs, t,method); if(rs.next()){
return (T) getObject(rs, t,method);
}
return null;
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -133,6 +136,7 @@ public class ResultMapper {
} }
if(enable){ if(enable){
((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1)); ((Map<? super Object, ? super Object>) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1));
continue;
} }
((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getString(i + 1)); ((Map<? super Object, ? super Object>) o).put(columnName[i], rs.getString(i + 1));
continue; continue;
@ -163,15 +167,18 @@ public class ResultMapper {
if (o instanceof Boolean) { if (o instanceof Boolean) {
return rs.getBoolean(i + 1); return rs.getBoolean(i + 1);
} }
BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass(), Object.class); BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass(), Object.class);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
Class<?> propertyType = propertyDescriptor.getPropertyType(); Class<?> propertyType = propertyDescriptor.getPropertyType();
Object value = null; Object value = null;
String fieldName = propertyDescriptor.getName();
Field declaredField = o.getClass().getDeclaredField(fieldName);
if(enable){ if(enable){
value = ResultMapper.typeHandler.get(propertyType).getValue(rs, Util.toUnderlineCase(propertyDescriptor.getName())); value = ResultMapper.typeHandler.get(propertyType) == null ? null : ResultMapper.typeHandler.get(propertyType).getValue(rs, Util.toUnderlineCase(fieldName),declaredField);
}else { }else {
value = ResultMapper.typeHandler.get(propertyType).getValue(rs, propertyDescriptor.getName()); value = ResultMapper.typeHandler.get(propertyType) == null ? null : ResultMapper.typeHandler.get(propertyType).getValue(rs, fieldName,declaredField);
} }
propertyDescriptor.getWriteMethod().invoke(o, value); propertyDescriptor.getWriteMethod().invoke(o, value);
} }

View File

@ -31,21 +31,13 @@ public class SqlHandler {
// 处理基本类型以及包装类 // 处理基本类型以及包装类
String parse; String parse;
if (methodArgNameMap.size() == 0) { if (methodArgNameMap.size() == 0) {
return new PrepSqlResultImpl(sql, sqlArgs); return new PrepSqlResultImpl(findSql, sqlArgs);
} }
if (methodArgNameMap.size() == 1) { if (methodArgNameMap.size() == 1) {
if (!custom) {
Optional<Object> first = methodArgNameMap.values().stream().findFirst(); Optional<Object> first = methodArgNameMap.values().stream().findFirst();
parse = parse(findSql, first.get()); parse = parse(findSql, first.get());
} else {
return new PrepSqlResultImpl(sql, sqlArgs);
}
} else if (methodArgNameMap.size() == 2 && custom) {
int index = findArg(method);
parse = parse(findSql, args[index]);
} else { } else {
parse = parse(findSql, methodArgNameMap); parse = parse(findSql, methodArgNameMap);
} }
return new PrepSqlResultImpl(parse, sqlArgs); return new PrepSqlResultImpl(parse, sqlArgs);
} }
@ -183,7 +175,7 @@ public class SqlHandler {
} }
if (arg.getClass().isArray()) { if (arg.getClass().isArray()) {
// throw new TypeNonsupportException("A value is expected, but a set is received"); // throw new TypeNonsupportException("A value is expected, but a set is received");
return StringUtils.join(Collections.singletonList(arg), ","); return StringUtils.join((Object[]) arg, ",");
} }
// 判断参数类型 // 判断参数类型
if (arg instanceof Collection) { if (arg instanceof Collection) {

View File

@ -2,6 +2,8 @@ package aiyh.utils.recordset;
import weaver.conn.RecordSet; import weaver.conn.RecordSet;
import java.lang.reflect.Field;
/** /**
* @author EBU7-dev1-ayh * @author EBU7-dev1-ayh
* create 2021/12/21 0021 13:06 * create 2021/12/21 0021 13:06
@ -10,12 +12,12 @@ import weaver.conn.RecordSet;
public class StringTypeHandler implements TypeHandler{ public class StringTypeHandler implements TypeHandler{
@Override @Override
public Object getValue(RecordSet rs, String fieldName) { public Object getValue(RecordSet rs, String fieldName, Field declaredField) {
return rs.getString(fieldName); return rs.getString(fieldName);
} }
@Override @Override
public Object getValue(RecordSet rs, int index) { public Object getValue(RecordSet rs, int index,Field declaredField) {
return rs.getString(index); return rs.getString(index);
} }
} }

View File

@ -2,12 +2,14 @@ package aiyh.utils.recordset;
import weaver.conn.RecordSet; import weaver.conn.RecordSet;
import java.lang.reflect.Field;
/** /**
* @author @author EBU7-dev1-ay * @author @author EBU7-dev1-ay
* create 2021/12/21 0021 13:05 * create 2021/12/21 0021 13:05
*/ */
public interface TypeHandler { public interface TypeHandler {
Object getValue(RecordSet rs,String fieldName); Object getValue(RecordSet rs, String fieldName, Field declaredField);
Object getValue(RecordSet rs,int index); Object getValue(RecordSet rs,int index,Field declaredField);
} }

View File

@ -64,6 +64,13 @@ public class BuilderSqlImpl implements BuilderSql {
return new PrepSqlResultImpl(sqlBuilder.toString(), args); return new PrepSqlResultImpl(sqlBuilder.toString(), args);
} }
/**
* SQL
* @param tableName
* @param t
* @param <T>
* @return SQL
*/
public <T> PrepSqlResultImpl insertSqlByEntity(String tableName, T t){ public <T> PrepSqlResultImpl insertSqlByEntity(String tableName, T t){
List<Object> args = new ArrayList<>(); List<Object> args = new ArrayList<>();
StringBuilder sqlBuilder = new StringBuilder("insert into "); StringBuilder sqlBuilder = new StringBuilder("insert into ");
@ -136,6 +143,13 @@ public class BuilderSqlImpl implements BuilderSql {
return new BatchSqlResultImpl(sqlBuilder.toString(), args); return new BatchSqlResultImpl(sqlBuilder.toString(), args);
} }
/**
* SQL
* @param tableName
* @param list
* @param <T>
* @return SQL
*/
public <T> BatchSqlResultImpl insertBatchSqlByEntity(String tableName, List<T> list) { public <T> BatchSqlResultImpl insertBatchSqlByEntity(String tableName, List<T> list) {
StringBuilder sqlBuilder = new StringBuilder("insert into "); StringBuilder sqlBuilder = new StringBuilder("insert into ");
sqlBuilder.append(tableName); sqlBuilder.append(tableName);
@ -209,6 +223,14 @@ public class BuilderSqlImpl implements BuilderSql {
return new PrepSqlResultImpl(sqlBuilder.toString(), args); return new PrepSqlResultImpl(sqlBuilder.toString(), args);
} }
/**
* SQL
* @param tableName
* @param t
* @param where
* @param <T>
* @return SQL
*/
public <T> PrepSqlResultImpl updateSqlByEntity(String tableName, T t, Where where){ public <T> PrepSqlResultImpl updateSqlByEntity(String tableName, T t, Where where){
this.verifyWhere(where); this.verifyWhere(where);
StringBuilder sqlBuilder = new StringBuilder("update "); StringBuilder sqlBuilder = new StringBuilder("update ");
@ -284,6 +306,14 @@ public class BuilderSqlImpl implements BuilderSql {
return new BatchSqlResultImpl(sqlBuilder.toString(), args); return new BatchSqlResultImpl(sqlBuilder.toString(), args);
} }
/**
* SQL
* @param tableName
* @param list
* @param whereList
* @param <T>
* @return SQL
*/
public <T> BatchSqlResultImpl updateBatchSqlByEntity(String tableName, List<T> list, List<Where> whereList) { public <T> BatchSqlResultImpl updateBatchSqlByEntity(String tableName, List<T> list, List<Where> whereList) {
this.verifyWhereList(whereList); this.verifyWhereList(whereList);
if (list.size() != whereList.size()) { if (list.size() != whereList.size()) {

View File

@ -15,7 +15,7 @@ public class BaseTest {
@Before @Before
public void before() { public void before() {
weaver.general.GCONST.setServerName("ecology"); weaver.general.GCONST.setServerName("ecology");
weaver.general.GCONST.setRootPath("H:\\ecology-9-dev\\src\\main\\resources"); weaver.general.GCONST.setRootPath("H:\\ecology-9-dev\\src\\main\\resources\\");
} }
@Test @Test

View File

@ -1,7 +1,10 @@
package entity; package entity;
import aiyh.utils.annotation.DateFormatAn;
import lombok.Data; import lombok.Data;
import java.util.Date;
/** /**
* @author EBU7-dev1-ayh * @author EBU7-dev1-ayh
* create 2021/12/21 0021 15:12 * create 2021/12/21 0021 15:12
@ -11,8 +14,10 @@ import lombok.Data;
public class ImageInfo { public class ImageInfo {
private Integer id; private Integer id;
private Integer docId; private Integer docId;
private String operateDate; @DateFormatAn("yyyy-MM-dd")
private String operateTime; private Date operateDate;
@DateFormatAn("HH:mm:ss")
private Date operateTime;
private Integer imageFileId; private Integer imageFileId;
private String imageFileName; private String imageFileName;

View File

@ -0,0 +1,36 @@
package mybatisTest.mapper;
import aiyh.utils.annotation.recordset.ParamMapper;
import aiyh.utils.annotation.recordset.Select;
import aiyh.utils.annotation.recordset.SqlMapper;
import mybatisTest.entity.License;
import java.util.Map;
/**
* @author @author EBU7-dev1-ay
* create 2021/12/21 0021 21:52
*/
//添加注解标明需要对该类进行sql执行代理
@SqlMapper
public interface IMapperTest {
// 添加注解表示改方法属于查询方法并且返回一个map对象
@Select("select * from table")
public Map<String,Object> selectOne();
@Select("select * from table where id = #{id}")
public Map<String,Object> selectOneById(int id);
// 使用多个参数需要使用@ParamMapper指定别名
@Select("select * from table where id = #{id} and name = #{name}")
public Map<String,Object> selectOneByIdAndName(@ParamMapper("id") int id,
@ParamMapper("name") String name);
// 使用多个参数需要使用@ParamMapper指定别名
@Select("select * from table where license = #{license} and companyName = #{companyName}")
public Map<String,Object> selectOneByLicens(License license);
}

View File

@ -0,0 +1,40 @@
package pcn.copy;
import com.alibaba.fastjson.JSON;
import com.api.aiyh_pcn.multipleCopy.pojo.CopyMultipleMain;
import com.api.aiyh_pcn.multipleCopy.services.MultipleCopyService;
import com.api.aiyh_pcn.multipleCopy.vo.MultipleCopyConfigVO;
import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.Test;
/**
* @author EBU7-dev1-ayh
* create 2021/12/22 0022 17:27
*/
public class TestCopy {
@Before
public void before() {
weaver.general.GCONST.setServerName("ecology");
weaver.general.GCONST.setRootPath("H:\\ecology-9-dev\\src\\main\\resources\\");
}
@Test
public void test(){
MultipleCopyService multipleCopyService = new MultipleCopyService();
MultipleCopyConfigVO configInfo = multipleCopyService.getConfigInfo("48");
System.out.println(JSON.toJSONString(configInfo));
}
@Test
public void testUtil(){
String str = "1,2";
String join = StringUtils.join(str.split(","), ",");
System.out.println(join);
}
}

View File

@ -19,7 +19,7 @@ public interface ITestMapper {
@ParamMapper("map") Map<String,Object> map); @ParamMapper("map") Map<String,Object> map);
@Select(custom = true) @Select(custom = true)
void selectOne(@SqlString String sql,String name); License selectOne(@SqlString String sql);
@Select("select * from lj where id = #{id} and name like #{nameLike} and age > #{age}") @Select("select * from lj where id = #{id} and name like #{nameLike} and age > #{age}")
Object selectOne(@ParamMapper("id") String id, Object selectOne(@ParamMapper("id") String id,
@ -28,18 +28,20 @@ public interface ITestMapper {
@Select("select * from table where id = #{id} and name like #{nameLike} and age > ${age}" + @Select("select * from table where id = #{id} and name like #{nameLike} and age > ${age}" +
" and account = #{user.account} or userid = {user.uID}") " and account = #{user.account} or userid = {user.uID}")
@CaseConversion(false)
Object selectOne(Map<String,Object> map); Object selectOne(Map<String,Object> map);
@Select("select companyname company_name,license,expiredate expire_date,CVERSION c_version from license;") @Select("select companyname company_name,license,expiredate expire_date,CVERSION c_version from license;")
License selectOne(); License selectOne();
@Select("select imagefileid image_file_id,imagefilename image_file_name," + @Select(value = "select imagefileid image_file_id,imagefilename image_file_name," +
"docid doc_id,id,operatedate operate_date,operatetime operate_time" + "docid doc_id,id,operatedate operate_date,operatetime operate_time" +
" from docimagefile where docid in (${list})") " from docimagefile where docid in (${list})",custom = true)
List<Map<String, Object>> selectList(List<Integer> list); List<ImageInfo> selectList(@SqlString String sql, List<Integer> list);
@Update("update hrmresource set email = #{email} where id > #{min} and id < #{max}") @Update("update hrmresource set email = #{email} where id > #{min} and id < #{max}")
void updateEmail(@ParamMapper("email") String email, void updateEmail(@ParamMapper("email") String email,
@ParamMapper("min") int min, @ParamMapper("min") int min,
@ParamMapper("max") int max); @ParamMapper("max") int max);

View File

@ -1,13 +1,19 @@
package utilTest; package utilTest;
import aiyh.utils.recordset.RecordsetUtil; import aiyh.utils.Util;
import aiyh.utils.httpUtil.ResponeVo;
import aiyh.utils.httpUtil.util.HttpUtils;
import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl;
import aiyh.utils.sqlUtil.whereUtil.Where;
import com.alibaba.fastjson.JSON;
import entity.ImageInfo; import entity.ImageInfo;
import mybatisTest.entity.License; import mybatisTest.mapper.IMapperTest;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import weaver.hrm.User; import weaver.conn.RecordSet;
import java.io.IOException;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -21,79 +27,6 @@ import java.util.regex.Pattern;
public class UtilTest { public class UtilTest {
@Before
public void before() {
weaver.general.GCONST.setServerName("ecology");
weaver.general.GCONST.setRootPath("H:\\ecology-9-dev\\src\\main\\resources\\");
}
@Test
public void test() {
int i = 0;
testInstanceOfType(i);
Integer j = 10;
testInstanceOfType(j);
}
public void testInstanceOfType(Object obj) {
System.out.println(obj.getClass().isPrimitive());
System.out.println(obj instanceof Number);
}
@Test
public void testRecordsetUtil() {
RecordsetUtil recordsetUtil = new RecordsetUtil();
ITestMapper mapper = recordsetUtil.getMapper(ITestMapper.class);
// User user = new User();
// user.setUid(1002);
// user.setAccount("aiyh");
// Map<String, Object> map = new HashMap<String, Object>() {
// {
// put("id", 10);
// put("nameLike", "%不知道%");
// put("age", 20);
// put("user", user);
// }
// };
// Object o = mapper.selectOne(map);
// o = mapper.selectOne();
// o = mapper.selectOne("234", "%好的吧%", 30);
// System.out.println(o);
// License stringObjectMap = mapper.selectOne();
// System.out.println(stringObjectMap);
// List<Map<String, Object>> imageInfos = mapper.selectList(new ArrayList<Integer>(){{
// add(1);
// add(2);
// add(3);
// add(4);
// }});
// System.out.println(imageInfos);
mapper.updateEmail("1234567@qq.com",20,40);
}
@Test
public void testTypeMethod() throws NoSuchMethodException, InstantiationException, IllegalAccessException {
Method getList = this.getClass().getMethod("getList");
Class<?> returnType = getList.getReturnType();
System.out.println(returnType.equals(void.class));
//获取返回值的类型
Type genericReturnType = getList.getGenericReturnType();
//获取返回值的泛型参数
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
Class<?> rawType = getRawType(actualTypeArgument);
if(rawType.equals(Map.class)){
rawType = HashMap.class;
}
Object o = rawType.newInstance();
System.out.println(rawType);
System.out.println( o);
// Class<Map> type = (Class<Map>) actualTypeArgument.getClass().newInstance();
// System.out.println(type);
}
public static Class<?> getRawType(Type type) { public static Class<?> getRawType(Type type) {
if (type instanceof Class) { if (type instanceof Class) {
return (Class) type; return (Class) type;
@ -114,6 +47,83 @@ public class UtilTest {
} }
} }
@Before
public void before() {
weaver.general.GCONST.setServerName("ecology");
weaver.general.GCONST.setRootPath("H:\\ecology-9-dev\\src\\main\\resources\\");
}
@Test
public void test() {
int i = 0;
testInstanceOfType(i);
Integer j = 10;
testInstanceOfType(j);
}
public void testInstanceOfType(Object obj) {
System.out.println(obj.getClass().isPrimitive());
System.out.println(obj instanceof Number);
}
@Test
public void testRecordsetUtil() {
// RecordsetUtil recordsetUtil = new RecordsetUtil();
// ITestMapper mapper = recordsetUtil.getMapper(ITestMapper.class);
// User user = new User();
// user.setUid(1002);
// user.setAccount("aiyh");
// Map<String, Object> map = new HashMap<String, Object>() {
// {
// put("id", 10);
// put("nameLike", "%不知道%");
// put("age", 20);
// put("user", user);
// }
// };
// Object o = mapper.selectOne(map);
// o = mapper.selectOne();
// o = mapper.selectOne("234", "%好的吧%", 30);
// System.out.println(o);
// License stringObjectMap = mapper.selectOne();
// System.out.println(stringObjectMap);
ITestMapper mapper = Util.getMapper(ITestMapper.class);
// License license = mapper.selectOne("select companyname company_name,license,expiredate expire_date,CVERSION c_version from license");
// System.out.println(license);
List<ImageInfo> imageInfos = mapper.selectList("select imagefileid image_file_id,imagefilename image_file_name," +
"docid doc_id,id,operatedate operate_date,operatetime operate_time" +
" from docimagefile where docid in (${list})", new ArrayList<Integer>() {
{
add(1);
add(2);
add(3);
add(4);
}
});
System.out.println(imageInfos);
// mapper.updateEmail("1234567@qq.com",20,40);
}
@Test
public void testTypeMethod() throws NoSuchMethodException, InstantiationException, IllegalAccessException {
Method getList = this.getClass().getMethod("getList");
Class<?> returnType = getList.getReturnType();
System.out.println(returnType.equals(void.class));
//获取返回值的类型
Type genericReturnType = getList.getGenericReturnType();
//获取返回值的泛型参数
Type actualTypeArgument = ((ParameterizedType) genericReturnType).getActualTypeArguments()[0];
Class<?> rawType = getRawType(actualTypeArgument);
if (rawType.equals(Map.class)) {
rawType = HashMap.class;
}
Object o = rawType.newInstance();
System.out.println(rawType);
System.out.println(o);
// Class<Map> type = (Class<Map>) actualTypeArgument.getClass().newInstance();
// System.out.println(type);
}
public void getList() { public void getList() {
return; return;
@ -155,7 +165,7 @@ public class UtilTest {
add(3); add(3);
add(4); add(4);
}}; }};
System.out.println(StringUtils.join(integers,",")); System.out.println(StringUtils.join(integers, ","));
String parse = "id.public.test.omg"; String parse = "id.public.test.omg";
String pattern = "(?<field>\\w+)\\.*(?<other>(\\S+)*)"; String pattern = "(?<field>\\w+)\\.*(?<other>(\\S+)*)";
Pattern compile = Pattern.compile(pattern); Pattern compile = Pattern.compile(pattern);
@ -167,5 +177,84 @@ public class UtilTest {
} }
@Test
public void builderSelect(){
// 将以下数据插入到数据库中,比如 inset into name ,email values('update_name','update_email')
Map<String,Object> map = new HashMap<>();
map.put("name","update_name");
map.put("email","update_email");
map.put("phone","update_phone");
// 构建SQL
PrepSqlResultImpl sqlResult = Util.createSqlBuilder().insertSql(
"tableName", map);
// 获取完整的SQL对象
System.out.println(sqlResult);
RecordSet rs = new RecordSet();
// 执行SQL
rs.executeUpdate(sqlResult.getSqlStr(),sqlResult.getArgs());
}
@Test
public void getRsValue(){
String sql = "select * from table";
RecordSet rs = new RecordSet();
rs.executeQuery(sql);
// 将rs结果转化为Map并不进行下划线转驼峰
// List<Map<String, Object>> result = Util.recordSet2MapList(rs,false);
// 将rs结果转化为Map将下划线转为驼峰命名
List<Map<String, Object>> result = Util.recordSet2MapList(rs);
System.out.println(result);
// 将执行结果转为javaBean对象
sql = "select * from fileImage";
rs.executeQuery(sql);
// 不进行驼峰转换
// List<ImageInfo> imageInfos = Util.recordeSet2Array(rs, ImageInfo.class,false);
List<ImageInfo> imageInfos = Util.recordeSet2Array(rs, ImageInfo.class);
System.out.println(imageInfos);
}
@Test
public void testSqlUtil(){
// 获取代理对象
IMapperTest mapper = Util.getMapper(IMapperTest.class);
// 调用方法并获取返回值
Map<String, Object> result = mapper.selectOne();
System.out.println(result);
}
@Test
public void testRequest(){
// 构建工具实体
HttpUtils httpUtils = new HttpUtils();
// 获取该对象内的全局 请求头可以对put来添加请求头信息
Map<String, String> header = httpUtils.getGlobalCache().header;
// 全局请求参数
Map<String, Object> paramMap = httpUtils.getGlobalCache().paramMap;
// 调用方法
try {
HashMap<String, Object> requestParams = new HashMap<>();
HashMap<String, String> requestHeader = new HashMap<>();
ResponeVo responeVo = httpUtils.apiPost("url", requestParams, requestHeader);
// 获取相应结果String类型的
String entityString = responeVo.getEntityString();
// 获取响应结果并转为Map对象
Map<String, Object> entityMap = responeVo.getEntityMap();
// 获取相应状态码
int code = responeVo.getCode();
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void testReadProp(){
Map<String, Object> patentWall = Util.readProperties2Map("PatentWall", "aiyh.patentWall.search");
System.out.println(JSON.toJSONString(patentWall));
}
} }