ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 ``` /** * <b>方法描述:</b> 创建实体类对象(赋值) <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-06-28 10:10:42 <br/> * * @param className 入参|实体全路径名称|{@link java.lang.String} * @param fieldValue 入参|属性和值|{@link java.util.Map} * @param entity 出参|对象实例|{@link Object} * @return -1 异常<br/> * 0 失败<br/> * 1 成功<br/> */ @Component( label = "创建实体类对象(赋值)", style = "判断型", type = "同步组件", comment = "创建一个实体bean对象并给属性赋值,传入参数为bean的Fieldandvalue 值,配置格式:{'key1':'test','key2': __REQ__['name'],'key3':{'key3_1':12},'key4':['abc',2]}", version = "1.0.0", deprecated = false, author = "admin", date = "2018-06-28 10:10:42") @InParams(param = {@Param(name = "className", comment = "实体全路径名称", type = java.lang.String.class), @Param(name = "fieldValue", comment = "属性和值", type = java.util.Map.class)}) @OutParams(param = {@Param(name = "entity", comment = "对象实例", type = Object.class)}) @Returns(returns = {@Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功")}) public static ResultBase P_CreateBean(String className, Map fieldValue) { if (StringUtil.isEmpty(className)) { return ResultBase.newFailureResult("TPTB0001", "参数错误:实体类名称参数【className】不能为空"); } Object obj = null; StringBuffer sb = new StringBuffer(); try { if (fieldValue != null && !fieldValue.isEmpty()) { Class cls = Class.forName(className); obj = cls.newInstance(); setValue(cls, fieldValue, obj, sb); return ResultBase.newSuccessResult(obj); } AppLog.debug("创建实体类对象(赋值),类={},赋值字段列表为空,反回空对象", className); return P_CreateBeanNull(className); } catch (Exception e) { AppLog.error("创建实体类对象(赋值)异常:", e); AppLog.error("创建实体类对象,对象属性赋值,已赋值字段:", sb.toString()); return ResultBase.newExceptionResult("TPTB0002", "className=" + className + "创建实例化对象错误:" + AppLog.errorMsg(e)); } } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/bb/0a/bb0a78fe1d6dfa2555296f85e6132024_1869x892.png) # 参数说明及示例 ## 入口参数 对象类路径:数据管理中数据对象的源码中的对象的全路径名,示例: `"data.test.test.entity.TUser"` 属性和值:根据对象属性以 map 的形式赋值,示例: `{ "id":20, "name":"xyz" }` ## 出口参数 对象实例:根据输入参数创建一个对象,示例: `__INNER__["object"]`