From 60fc80b6ac01ff9c1b602f9af1cdbeab653fb068 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 3 Feb 2026 12:57:39 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=8A=82=E7=82=B9=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6serverIpV4/V6/=E5=9F=9F=E5=90=8D=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=AD=A3=E7=A1=AE=E6=B8=85=E7=A9=BA=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用LambdaUpdateWrapper替代updateById以确保null值能正确更新到数据库 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- .../admin/service/impl/NodeServiceImpl.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/springboot-backend/src/main/java/com/admin/service/impl/NodeServiceImpl.java b/springboot-backend/src/main/java/com/admin/service/impl/NodeServiceImpl.java index b711317..e30e472 100644 --- a/springboot-backend/src/main/java/com/admin/service/impl/NodeServiceImpl.java +++ b/springboot-backend/src/main/java/com/admin/service/impl/NodeServiceImpl.java @@ -15,6 +15,7 @@ import com.admin.service.*; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; @@ -142,10 +143,26 @@ public class NodeServiceImpl extends ServiceImpl implements No - Node updateNode = buildUpdateNode(nodeUpdateDto); - this.updateById(updateNode); - return R.ok(); - } + Node updateNode = buildUpdateNode(nodeUpdateDto); + // Use LambdaUpdateWrapper to explicitly set nullable fields (serverIpV4/V6) + // because updateById() skips null fields by default + LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); + wrapper.eq(Node::getId, updateNode.getId()) + .set(Node::getName, updateNode.getName()) + .set(Node::getServerIp, updateNode.getServerIp()) + .set(Node::getServerIpV4, updateNode.getServerIpV4()) + .set(Node::getServerIpV6, updateNode.getServerIpV6()) + .set(Node::getPort, updateNode.getPort()) + .set(Node::getHttp, updateNode.getHttp()) + .set(Node::getTls, updateNode.getTls()) + .set(Node::getSocks, updateNode.getSocks()) + .set(Node::getInterfaceName, updateNode.getInterfaceName()) + .set(Node::getTcpListenAddr, updateNode.getTcpListenAddr()) + .set(Node::getUdpListenAddr, updateNode.getUdpListenAddr()) + .set(Node::getUpdatedTime, updateNode.getUpdatedTime()); + this.update(wrapper); + return R.ok(); + } @Override public R deleteNode(Long id) {