我有API接受文件及其所有者,但我不能接受空所有者。另外,gona拥有他的电子邮件,因此需要对其进行验证。 但是,尽管我使用了@initBinder
,但似乎验证无法正常工作@RequestMapping(path = "/lib")
@RestController
public class UploaderController extends AbstractController {
@PostMapping(path = "/novel", consumes = {"multipart/form-data"})
@ResponseBody
@ResponseStatus(HttpStatus.CREATED)
public String upload(@RequestPart("book") MultipartFile file
, @NotEmpty @RequestPart(name = "name") String name
, @Email @RequestPart(name = "email") String email){
//
}
public abstract class AbstractRestController {
@InitBinder
protected void initBinder(WebDataBinder binder) {
binder.initDirectFieldAccess();
}
}
要通过电子邮件formate进行验证并且名称不为Empy,我该怎么办