class id 不允许null
This commit is contained in:
@@ -10,8 +10,10 @@ import com.yunhai.bschclassmanage.service.IStudentClassHistoryService;
|
|||||||
import com.yunhai.bschclassmanage.utils.UserContext;
|
import com.yunhai.bschclassmanage.utils.UserContext;
|
||||||
import com.yunhai.platform.utils.exception.DException;
|
import com.yunhai.platform.utils.exception.DException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.beans.PropertyEditorSupport;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -24,6 +26,25 @@ public class SchHistoryController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IStudentClassHistoryService studentClassHistoryService; // 使用接口
|
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")
|
@GetMapping("getClass")
|
||||||
public HistorySchClassVO GetClassFirst(Integer classId) {
|
public HistorySchClassVO GetClassFirst(Integer classId) {
|
||||||
if (classId == null || classId <= 0) {
|
if (classId == null || classId <= 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user