@RequestMapping(value = "/doRegister", method = RequestMethod.POST)
public @ResponseBody User doRegister(@Valid User user, BindingResult result, Model model) {
if (result.hasErrors()) {
List<ObjectError> list = result.getAllErrors();
for (ObjectError error : list) {
System.out.println(error.getDefaultMessage());
}
return null;
}
System.out.println("注册..");
return user;
}
public class ReturnType {
private int code;
private User data;
private String msg;
public ReturnType(int code, String msg, User data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public User getData() {
return data;
}
public void setData(User data) {
this.data = data;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
@RequestMapping(value = "/doRegister", method = RequestMethod.POST)
public @ResponseBody ReturnType doRegister(@Valid User user, BindingResult result, Model model) throws Exception {
throw new Exception("new Exception");
}
@ControllerAdvice
public class ExceptionHandle {
/* 表明这个handler只处理什么类型的异常
* */
@ExceptionHandler(value = Exception.class)
// 返回值为json或者其他对象
@ResponseBody
public ReturnType handle(Exception e) {
return new ReturnType(-1, e.getMessage(), null);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有