Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.walidatorpnr.pesel;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.validation.BindingResult;
- import org.springframework.web.bind.annotation.*;
- import javax.validation.Valid;
- import java.util.Arrays;
- import java.util.Iterator;
- import java.util.List;
- @Controller
- public class Controller {
- private final PeselService peselService;
- public PeselController(PeselService peselService){
- this.peselService = peselService;
- }
- @Autowired
- Pesel pesel;
- @GetMapping("/pesel")
- public String getPesel(Model model) {
- model.addAttribute("numbersList", pesel);
- return "pesel";
- }
- @PostMapping("/validate")
- public String submitPesel(@Valid @ModelAttribute("numbersList") Pesel pesel, BindingResult bindingResult) {
- // model.addAttribute("numbers", pesel);
- if (bindingResult.hasErrors()) {
- System.out.println("There were errors");
- bindingResult.getAllErrors().forEach(error -> {
- System.out.println(error.getObjectName() + " " + error.getDefaultMessage());
- });
- return "pesel";
- }
- else {
- List<Integer> temp2 = pesel.getNumbersList();
- }
- pesel.setSerial_number(peselService.readSerial(temp2));
- pesel.setBirthday(peselService.readBirthday(pesel));
- pesel.setSex(peselService.readSex(pesel));
- pesel.setControl_number(pesel.getNumbersList().get(10));
- pesel.setResult(peselValidationService.ResultText(pesel));
- return "/pesel_validate";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement