Throws the Exception {
If (file. GetOriginalFilename ()!=null) {
Int fileNamelength=file. GetOriginalFilename (.) length ();
If (fileNamelength & gt; FILE_NAME_MAX) {
Throw new Exception (" file name is too long ");
}
}
Long size=file. GetSize ();
If (size & gt; DEFAULT_MAX_SIZE) {
Throw new Exception (" the file is too large ");
}
String extension=getExtension (file);
If (allowedExtension!=null & amp; & ! IsAllowedExtension (extension, allowedExtension)) {
Throw new Exception (" please upload specify the type of file!" );
}
}
CodePudding user response:
The controller layer, the try catch (Exception e) {} {} can also print the captured anomalies in the logCodePudding user response:
Your post is that the business layer code, do you want to get what you said the Controller layer exception information, conditions are not met, actually don't have to throw exceptions, you into the method, a new map, as the map.. put (" MSG ", "file name is too long"), then the return line, the Controller is given,If you want to be a little more advanced, you customize a class, get a few property returns also line
If you want to throw Exception ways, a custom Exception, such as MyFileException inherit the Exception, catch a Msg attribute, the Controller layer (MyFileException e)