[Java] 纯文本查看 复制代码
public class User {
@NotNull(groups = {First.class})
private int id;
@NotNull(groups = {First.class, Second.class})
private String username;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
interface First {
}
interface Second {
}
[Java] 纯文本查看 复制代码
@RestController
public class UserControllerTest {
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String save(@Validated({Second.class}) User user, BindingResult result) {
if (result.hasErrors()) {
return "validate/error";
}
return "redirect:/success";
}
@RequestMapping(value = "/update", method = RequestMethod.PUT)
public String update(@Validated({First.class, Second.class}) User user, BindingResult result) {
if (result.hasErrors()) {
return "validate/error";
}
return "redirect:/success";
}
}