Advertisement
Amakesh

Untitled

Mar 24th, 2022 (edited)
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. package com.walidatorpnr.pesel;
  2.  
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Controller;
  5. import org.springframework.ui.Model;
  6. import org.springframework.validation.BindingResult;
  7. import org.springframework.web.bind.annotation.*;
  8.  
  9. import javax.validation.Valid;
  10. import java.util.Arrays;
  11. import java.util.Iterator;
  12. import java.util.List;
  13.  
  14. @Controller
  15. public class Controller {
  16.  
  17.     private final PeselService peselService;
  18.  
  19.     public PeselController(PeselService peselService){
  20.         this.peselService = peselService;
  21.        
  22.     }
  23.  
  24.     @Autowired
  25.     Pesel pesel;
  26.  
  27.     @GetMapping("/pesel")
  28.     public String getPesel(Model model) {
  29.  
  30.         model.addAttribute("numbersList", pesel);
  31.         return "pesel";
  32.     }
  33.  
  34.     @PostMapping("/validate")
  35.     public String submitPesel(@Valid @ModelAttribute("numbersList") Pesel pesel, BindingResult bindingResult) {
  36.        // model.addAttribute("numbers", pesel);
  37.         if (bindingResult.hasErrors()) {
  38.             System.out.println("There were errors");
  39.             bindingResult.getAllErrors().forEach(error -> {
  40.                 System.out.println(error.getObjectName() + " " + error.getDefaultMessage());
  41.             });
  42.             return "pesel";
  43.         }
  44.         else {
  45.             List<Integer> temp2 = pesel.getNumbersList();
  46.             }
  47.            pesel.setSerial_number(peselService.readSerial(temp2));
  48.            pesel.setBirthday(peselService.readBirthday(pesel));
  49.            pesel.setSex(peselService.readSex(pesel));
  50.             pesel.setControl_number(pesel.getNumbersList().get(10));
  51.             pesel.setResult(peselValidationService.ResultText(pesel));
  52.          
  53.            return "/pesel_validate";
  54.  
  55.         }
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement