🐛 兼容列表查询传入逗号分隔的组织ID

用户绑定多个组织时 deptId 为逗号拼接字符串,绑定为 Long 会失败,现取第一个有效 ID。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-04 20:48:03 +08:00
parent 683351d764
commit 7e9caf5045
@@ -0,0 +1,58 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.transport.config;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import java.beans.PropertyEditorSupport;
/**
* 列表查询 deptId 绑定:用户可能绑定多个组织,前端会传入逗号分隔字符串。
* 组织筛选项为单选,这里取第一个有效 ID,避免 Long 类型转换失败。
*
* @author Chill
*/
@ControllerAdvice(basePackages = "org.springblade.transport.controller")
public class DeptIdBindingAdvice {
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(Long.class, "deptId", new PropertyEditorSupport() {
@Override
public void setAsText(String text) {
if (Func.isBlank(text)) {
setValue(null);
return;
}
setValue(Func.firstLong(text));
}
});
}
}