diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/config/DeptIdBindingAdvice.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/config/DeptIdBindingAdvice.java new file mode 100644 index 00000000..61845a9b --- /dev/null +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/config/DeptIdBindingAdvice.java @@ -0,0 +1,58 @@ +/** + * BladeX Commercial License Agreement + * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. + *

+ * Use of this software is governed by the Commercial License Agreement + * obtained after purchasing a license from BladeX. + *

+ * 1. This software is for development use only under a valid license + * from BladeX. + *

+ * 2. Redistribution of this software's source code to any third party + * without a commercial license is strictly prohibited. + *

+ * 3. Licensees may copyright their own code but cannot use segments + * from this software for such purposes. Copyright of this software + * remains with BladeX. + *

+ * Using this software signifies agreement to this License, and the software + * must not be used for illegal purposes. + *

+ * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is + * not liable for any claims arising from secondary or illegal development. + *

+ * 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)); + } + }); + } + +}