डीटीओ:मैं वसंत @ वैध सत्यापन से डिफ़ॉल्ट त्रुटि संदेश कैसे अनुकूलित करूं?
public class User {
@NotNull
private String name;
@NotNull
private String password;
//..
}
नियंत्रक:
@RequestMapping(value = "/user", method = RequestMethod.POST)
public ResponseEntity<String> saveUser(@Valid @RequestBody User user) {
//..
return new ResponseEntity<>(HttpStatus.OK);
}
डिफ़ॉल्ट json त्रुटि:
{"timestamp":1417379464584,"status":400,"error":"Bad Request","exception":"org.springframework.web.bind.MethodArgumentNotValidException","message":"Validation failed for argument at index 0 in method: public org.springframework.http.ResponseEntity<demo.User> demo.UserController.saveUser(demo.User), with 2 error(s): [Field error in object 'user' on field 'name': rejected value [null]; codes [NotNull.user.name,NotNull.name,NotNull.java.lang.String,NotNull]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.name,name]; arguments []; default message [name]]; default message [may not be null]],"path":"/user"}
मैं अपने कस्टम json के लिए के लिए प्रत्येक त्रुटि हो गई चाहते हैं। मैं इसे कैसे पूरा करूं?
@ksaughs क्या ApiErrors वर्ग है? – user6123723
org.springframework.validation. वसंत-संदर्भ जार – kswaughs
@kswaughs से त्रुटि, मैंने हर जगह ApiErrors की खोज की और इसे कहीं भी नहीं मिला। मैंने मेवेन में वसंत-संदर्भ निर्भरता भी शामिल की और कुछ भी नहीं मिला। एकमात्र वेब परिणाम इस स्टैक ओवरफ्लो पृष्ठ पर हैं जहां आप इसे अपने उत्तर में उल्लेख करते हैं। क्या आप सहायता कर सकते हैं? – user238607