86 lines
3.7 KiB
Java
86 lines
3.7 KiB
Java
|
package customization.test;
|
||
|
|
||
|
import aiyh.utils.Util;
|
||
|
import org.junit.Test;
|
||
|
|
||
|
import java.beans.BeanInfo;
|
||
|
import java.beans.IntrospectionException;
|
||
|
import java.beans.Introspector;
|
||
|
import java.beans.PropertyDescriptor;
|
||
|
import java.io.IOException;
|
||
|
import java.util.Collection;
|
||
|
|
||
|
/**
|
||
|
* @author EBU7-dev1-ayh
|
||
|
* @create 2021/9/6 0006 20:03
|
||
|
* 工具类测试
|
||
|
*/
|
||
|
|
||
|
|
||
|
public class UtilTest extends BaseTest {
|
||
|
|
||
|
@Test
|
||
|
public void createJava() throws IOException {
|
||
|
/* Util.creatJavaFileBySql("select upw.workflow,upw.water_type,upw.water_point,upw.font_size, " +
|
||
|
"upw.water_content,upw.font_style,upw.font_color,upw.water_fields, " +
|
||
|
"wftv.fieldname as water_field,upw.save_source,wftv1.fieldname as source_field," +
|
||
|
"upw.water_text,upw.add_time,upw.water_alpha from uf_pic_watermark as upw " +
|
||
|
"left join workflow_field_table_view as wftv on wftv.id = upw.water_field " +
|
||
|
"left join workflow_field_table_view as wftv1 on wftv1.id = upw.source_field",
|
||
|
"config","com.api.aiyh_guijiu.pojo");*/
|
||
|
/* Util.creatJavaFileBySql("select dt.id,main.enable,wf.tablename,wf.fieldname as start_date_field, " +
|
||
|
"wf1.fieldname as start_time_field,wf2.fieldname as end_date_field, " +
|
||
|
"wf3.fieldname as end_time_field from uf_workflow_conflic_dt1 as dt " +
|
||
|
"left join workflow_field_table_view as wf on wf.id = dt.start_date_field " +
|
||
|
"left join workflow_field_table_view as wf1 on wf1.id = dt.start_time_field " +
|
||
|
"left join workflow_field_table_view as wf2 on wf2.id = dt.end_date_field " +
|
||
|
"left join workflow_field_table_view as wf3 on wf3.id = dt.end_time_field " +
|
||
|
"left join uf_workflow_conflic as main on dt.mainid = main.id",
|
||
|
"workflowConfig","com.api.aiyh_guijiu.pojo");*/
|
||
|
Util.creatJavaFileBySql("select id,name,meetingtype,begindate,begintime,endtime,enddate,desc_n,creater,hrmmembers from meeting where id = 8",
|
||
|
"meetingInfo", "com.customization.quanshimeting.entity");
|
||
|
// Util.creatJavaFileByTable("uf_workflow_conflic_dt1","com.api.aiyh_guijiu.pojo");
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
@Test
|
||
|
public void testIntrospector() throws IntrospectionException {
|
||
|
// 不内省父类的信息,第二个参数stopClass代表从stopClass开始往上的父类不再内省
|
||
|
BeanInfo beanInfo = Introspector.getBeanInfo(TestVo.class, Object.class);
|
||
|
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
||
|
for (PropertyDescriptor p : propertyDescriptors) {
|
||
|
System.out.println(p.getName());
|
||
|
System.out.println(p.getPropertyType());
|
||
|
System.out.println(p.getPropertyType().equals(String.class));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
public <T> void toJsonString(T t) throws Exception {
|
||
|
BeanInfo beanInfo = Introspector.getBeanInfo(t.getClass(), Object.class);
|
||
|
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
||
|
for (PropertyDescriptor proper : propertyDescriptors) {
|
||
|
String name = proper.getName();
|
||
|
Class<?> propertyType = proper.getPropertyType();
|
||
|
if (int.class.equals(propertyType) || long.class.equals(propertyType)
|
||
|
|| short.class.equals(propertyType) || byte.class.equals(propertyType)
|
||
|
|| float.class.equals(propertyType) || double.class.equals(propertyType)
|
||
|
|| boolean.class.equals(propertyType) || Boolean.class.equals(propertyType)
|
||
|
|| Integer.class.equals(propertyType) || Long.class.equals(propertyType)
|
||
|
|| Short.class.equals(propertyType) || Byte.class.equals(propertyType)
|
||
|
|| Float.class.equals(propertyType) || Double.class.equals(propertyType)) {
|
||
|
// 整数类型和浮点数以及boolean类型
|
||
|
continue;
|
||
|
}
|
||
|
if (String.class.equals(propertyType) || Character.class.equals(propertyType)
|
||
|
|| char.class.equals(propertyType)) {
|
||
|
// 字符串类型的数据处理
|
||
|
continue;
|
||
|
}
|
||
|
if (proper.getReadMethod().invoke(t) instanceof Collection<?>) {
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|