diff --git a/src/main/java/com/yunhai/bschclassmanage/controller/api/SchHistoryController.java b/src/main/java/com/yunhai/bschclassmanage/controller/api/SchHistoryController.java index b9f7bdb..5718c4a 100644 --- a/src/main/java/com/yunhai/bschclassmanage/controller/api/SchHistoryController.java +++ b/src/main/java/com/yunhai/bschclassmanage/controller/api/SchHistoryController.java @@ -10,8 +10,10 @@ import com.yunhai.bschclassmanage.service.IStudentClassHistoryService; import com.yunhai.bschclassmanage.utils.UserContext; import com.yunhai.platform.utils.exception.DException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.*; +import java.beans.PropertyEditorSupport; import java.util.List; import java.util.Map; @@ -24,6 +26,25 @@ public class SchHistoryController { @Autowired private IStudentClassHistoryService studentClassHistoryService; // 使用接口 + /** + * 将 Integer 参数收到的 "null"/空串 统一当作 null,使方法内能进入并触发业务校验, + * 而不是在 Spring 类型转换阶段直接抛 MethodArgumentTypeMismatchException。 + */ + @InitBinder + public void initBinder(WebDataBinder binder) { + binder.registerCustomEditor(Integer.class, new PropertyEditorSupport() { + @Override + public void setAsText(String text) { + String t = (text == null) ? null : text.trim(); + if (t == null || t.isEmpty() || "null".equalsIgnoreCase(t)) { + setValue(null); + } else { + setValue(Integer.valueOf(t)); + } + } + }); + } + @GetMapping("getClass") public HistorySchClassVO GetClassFirst(Integer classId) { if (classId == null || classId <= 0) {