💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 组件源码 ``` /** * <b>方法描述:</b> 更新(按条件) <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2020-09-14 14:48:22 <br/> * * @param poolName * 入参|数据源名称|{@link java.lang.String} * @param className * 入参|执行操作类名|{@link java.lang.String} * @param entity * 入参|更新对象|{@link com.baomidou.mybatisplus.extension.activerecord.Model} * @param where * 入参|条件|{@link com.baomidou.mybatisplus.extension.activerecord.Model} * @param count * 出参|更新条数|{@link int} * @return -1 异常<br/> * 0 失败<br/> * 1 成功<br/> */ @Component(label = "更新(Entity)", style = "判断型", type = "同步组件", comment = "根据条件更新数据库,第一个实体是更新后的值,即拼接set语句;第一个实体是条件,即拼接where语句", version = "1.0.0", deprecated = false, author = "admin", date = "2020-09-14 02:48:22") @InParams(param = {@Param(name = "poolName", comment = "数据源名称", type = java.lang.String.class), @Param(name = "className", comment = "执行操作类名", type = java.lang.String.class), @Param(name = "entity", comment = "更新对象", type = com.baomidou.mybatisplus.extension.activerecord.Model.class), @Param(name = "where", comment = "条件", type = com.baomidou.mybatisplus.extension.activerecord.Model.class)}) @OutParams(param = {@Param(name = "count", comment = "更新条数", type = int.class)}) @Returns( returns = {@Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功")}) public static ResultBase P_update(String poolName, String className, Model entity, Model where) { try { AppLog.debug("根据主键更新 组件参数,poolName={},className={},entity={}", poolName, className, entity); if (StringUtil.isEmpty(className)) { return ResultBase.newFailureResult("TPTD0021", "参数错误:执行类参数【className】不能为空"); } if (entity == null || where == null) { return ResultBase.newFailureResult("TPTD0022", "参数错误:更新对象和条件对象都不能为空"); } setDatasource(poolName); Object maper = BundleUtil.getService(className); if (maper == null) { return ResultBase.newFailureResult("TPTD0010", "错误:当前环境未找到[" + className + "]的可用数据库操作Mapper 实例"); } Method method = getMethod(maper.getClass(), className, MybatisPlusMapperMehtod.update); if (method != null) { AppLog.debug("开始执行相应的Mapper 方法"); Wrapper wrapper = Wrappers.lambdaUpdate(where); return ResultBase.newSuccessResult(method.invoke(maper, entity, wrapper)); } } catch (Exception e) { AppLog.error(e); return ResultBase.newExceptionResult("TPTD0023", "方法调用错误,类:" + className + "调用:" + MybatisPlusMapperMehtod.update + " 方法错误" + AppLog.errorMsg(e)); } return ResultBase.newFailureResult("TPTD0024", "方法调用错误,类:" + className + "没有可执行方法:" + MybatisPlusMapperMehtod.update); } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/59/0c/590ca13b7be168c04682efd9abfd9ba7_1867x892.png) # 参数说明及示例 ## 入口参数 数据源名称:使用的数据源名称,可以为空 执行操作类名:执行 SQL 语句的类,示例: `"data.test.test.mapper.TUserMapper"` 更新对象:更新后的值,示例: `__INNER__["update"]` 条件:传入一个实体类对象,拼接 where 语句,示例: `__INNER__["t"]` ## 出口参数 更新条数:成功更新的记录数,示例: `__INNER__["result"]` > 当交易部署到微服务上时,数据源在微服务界面上配置。