ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 ``` /** * <b>方法描述:</b> 查询(ID) <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2020-09-14 15:47:29 <br/> * * @param poolName * 入参|数据源名称|{@link java.lang.String} * @param className * 入参|执行操作类名|{@link java.lang.String} * @param id * 入参|查询主键|{@link java.io.Serializable} * @param entry * 出参|查询结果|{@link Object} * @return -1 异常<br/> * 0 失败<br/> * 2 无数据<br/> * 1 成功<br/> */ @Component(label = "查询(ID)", style = "判断型", type = "同步组件", comment = "根据数据库主键查询数据表数据,返回数据库封装实体对象.", version = "1.0.0", deprecated = false, author = "admin", date = "2020-09-14 03:47:29") @InParams(param = {@Param(name = "poolName", comment = "数据源名称", type = java.lang.String.class), @Param(name = "className", comment = "执行操作类名", type = java.lang.String.class), @Param(name = "id", comment = "查询主键", type = java.io.Serializable.class)}) @OutParams(param = {@Param(name = "entry", comment = "查询结果", type = Object.class)}) @Returns(returns = {@Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "2", desp = "无数据"), @Return(id = "1", desp = "成功")}) @Order(value = 2) public static ResultBase P_selectById(String poolName, String className, Serializable id) { try { AppLog.debug("根据主键查询数据 组件参数,poolName={},className={},id={}", poolName, className, id); if (StringUtil.isEmpty(className)) { return ResultBase.newFailureResult("TPTD0013", "参数错误:执行类参数【className】不能为空"); } if (id == null) { return ResultBase.newFailureResult("TPTD0014", "参数错误:查询主键【id】不能为空"); } if (id instanceof String) { if (StringUtil.isEmpty(id.toString())) { return ResultBase.newFailureResult("TPTD0014", "参数错误:查询主键【id】不能为空"); } } setDatasource(poolName); Object maper = BundleUtil.getService(className); if (maper == null) { return ResultBase.newFailureResult("TPTD0010", "错误:当前环境未找到[" + className + "]的可用数据库操作Mapper 实例"); } Method method = getMethod(maper.getClass(), className, MybatisPlusMapperMehtod.selectById); if (method != null) { AppLog.debug("开始执行相应的Mapper 方法"); Object obj = method.invoke(maper, id); ResultBase result = ResultBase.newSuccessResult(obj); if (obj == null) { return new ResultBase(2); } else { return result; } } } catch (Exception e) { AppLog.error(e); return ResultBase.newExceptionResult("TPTD0015", "方法调用错误,类:" + className + "调用:" + MybatisPlusMapperMehtod.selectById + " 方法错误" + AppLog.errorMsg(e)); } return ResultBase.newFailureResult("TPTD0016", "方法调用错误,类:" + className + "没有可执行方法:" + MybatisPlusMapperMehtod.selectById); } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/12/a8/12a85a3832d066293eb5fa48a802e47a_1870x893.png) # 参数说明及示例 ## 入口参数 数据源名称:使用的数据源名称,可以为空 执行操作类名:执行 SQL 语句的类,示例: `"data.test.test.mapper.TUserMapper"` 查询主键:根据数据库主键查询数据表数据,示例: `1` ## 出口参数 查询结果:返回数据库封装实体对象,示例: `__INNER__["result"]` > 当交易部署到微服务上时,数据源在微服务界面上配置。