Lang
BlurObject: Blur object
BlurObject.bind("1234").toLongValue();
List<String> _key = new ArrayList<String>();
Map<String, String> _value = new HashMap<String, String>();
...
PairObject _pObj = new PairObject(_key, _value);
//
_pObj.getKey();
//
_pObj.getValue();
Object _id = UUIDUtils.UUID();
TreeObject _target = new TreeObject()
.put("id", _id)
.put("category", new Byte[]{1, 2, 3, 4})
.put("create_time", new Date().getTime(), true)
.put("is_locked", true)
.put("detail", new TreeObject()
.put("real_name", "汉字将被混淆", true)
.put("age", 32));
// 这样赋值是List
TreeObject _list = new TreeObject();
_list.add("list item 1");
_list.add("list item 2");
// 这样赋值代表Map
TreeObject _map = new TreeObject();
_map.put("key1", "keyvalue1");
_map.put("key2", "keyvalue2");
TreeObject idsT = new TreeObject();
idsT.put("ids", _list);
idsT.put("maps", _map);
// List操作
System.out.println(idsT.get("ids").isList());
System.out.println(idsT.get("ids").getList());
// Map操作
System.out.println(idsT.get("maps").isMap());
System.out.println(idsT.get("maps").getMap());
//
_target.put("map", _map);
_target.put("list", _list);
//
System.out.println(_target.get("detail").getMixString("real_name"));
// TreeObject对象转换为JSON字符串输出
String _jsonStr = _target.toJson().toJSONString();
System.out.println(_jsonStr);
// 通过JSON字符串转换为TreeObject对象-->再转为JSON字符串输出
String _jsonStrTmp = (_target = TreeObject.fromJson(_target.toJson())).toJson().toJSONString();
System.out.println(_jsonStrTmp);
System.out.println(_jsonStr.equals(_jsonStrTmp));
Regarding the commonly used tool classes in the YMP framework, here we focus on the following:
- The BeanWrapper tool provided by ClassUtils, which is a class object wrapper that gives objects simple attribute manipulation capabilities;
public static void main(String[] args) throws Exception {
// 包裹一个Bean对象
ClassUtils.BeanWrapper<DemoBean> _w = ClassUtils.wrapper(new DemoBean());
// 输出该对象的成员属性名称
for (String _fieldName : _w.getFieldNames()) {
System.out.println(_fieldName);
}
// 为成员属性设置值
_w.setValue("name", "YMP");
// 获取成员属性值
_w.getValue("name");
// 拷贝Bean对象属性到目标对象(不局限相同对象)
DemoBean _bean = _w.duplicate(new DemoBean());
// 将对象属性转为Map存储
Map<String, Object> _maps = _w.toMap();
// 通过Map对象构建Bean对象并获取Bean实例
DemoBean _target = ClassUtils.wrapper(DemoBean.class).fromMap(_maps).getTargetObject();
}
##RuntimeUtils runtime tool class to obtain runtime related information; Get Current environment variables: RuntimeUtils.getSystemEnvs();
RuntimeUtils.getSystemEnv("JAVA_HOME");
Determine the current running environment operating system: RuntimeUtils.isUnixOrLinux();
RuntimeUtils.isWindows();
Get the application root path: If the WEB project is based on.../WEB-INF/, it will be returned. If it is an ordinary project, the path where the class is located will be returned. RuntimeUtils.getRootPath();
RuntimeUtils.getRootPath(false);
Replace environment variables: Support ${root}, ${user.dir} and ${user.home} environment variable placeholder replacementRuntimeUtils.replaceEnvVariable("${root}/home");