ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 /** * <b>方法描述:</b> 设置字段值(不覆盖) <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2020-06-10 15:10:12 <br/> * * @param key * 入参|key|{@link java.lang.String} * @param field * 入参|字段|{@link java.lang.String} * @param value * 入参|value|{@link java.lang.String} * @return -1 异常<br/> * 1 设置成功<br/> */ @Component(label = "设置字段值(不覆盖)", style = "判断型", type = "同步组件", comment = "字段不存在时,才进行set", version = "1.0.0", deprecated = false, author = "admin", date = "2020-06-10 03:10:12") @InParams(param = { @Param(name = "key", comment = "key", type = java.lang.String.class), @Param(name = "field", comment = "字段", type = java.lang.String.class), @Param(name = "value", comment = "value", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "1", desp = "设置成功") }) public static ResultBase P_hsetnx(String key, String field, String value) { try { redisTemplate.opsForHash().putIfAbsent(key, field, value); return ResultBase.newSuccessResult(); } catch (Exception e) { AppLog.error(e); return ResultBase.newExceptionResult("TPTR1004", "设置字段值(不覆盖) 异常:" + AppLog.errorMsg(e)); } } 交易中组件使用方式: ![](https://img.kancloud.cn/80/87/80876d10b86caaee24cbd526e3252398_1466x1158.jpg) ## 参数说明及示例 key:redis中的key,示例: `"test"` 字段:覆盖设值的字段名,示例: `"label"` value:新的字段值,示例: `"new value"` > 字段不存在时,才进行set