source: trip-planner/src/main/java/finki/diplomska/tripplanner/service/impl/MapValidationErrorService.java

Last change on this file was 1ad8e64, checked in by Ema <ema_spirova@…>, 3 years ago

spring security

  • Property mode set to 100644
File size: 844 bytes
Line 
1package finki.diplomska.tripplanner.service.impl;
2
3import org.springframework.http.HttpStatus;
4import org.springframework.http.ResponseEntity;
5import org.springframework.stereotype.Service;
6import org.springframework.validation.BindingResult;
7import org.springframework.validation.FieldError;
8
9import java.util.HashMap;
10import java.util.Map;
11
12@Service
13public class MapValidationErrorService {
14 public ResponseEntity<?> MapValidationService(BindingResult result){
15
16 if(result.hasErrors()){
17 Map<String, String> errorMap = new HashMap<>();
18
19 for(FieldError error: result.getFieldErrors()){
20 errorMap.put(error.getField(), error.getDefaultMessage());
21 }
22 return new ResponseEntity<Map<String, String>>(errorMap, HttpStatus.BAD_REQUEST);
23 }
24
25 return null;
26
27 }
28}
Note: See TracBrowser for help on using the repository browser.