Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 10th, 2020 136 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Controller
  2. @RequestMapping(value = "/admin")
  3. public class ControllerAdminPompa {
  4.  
  5.     @Autowired
  6.     PompaServiceImpl pompaService;
  7.  
  8.     /* Gestione Pompe */
  9.     @GetMapping("/pompe")
  10.     public String pompeList(Model model) {
  11.  
  12.         Iterable<Pompa> allPompe = pompaService.findAll();
  13.         model.addAttribute("pompe", allPompe);
  14.  
  15.         return "/admin/visualizzaPompe";
  16.     }
  17.  
  18. @GetMapping("/modificaPompa/{idPompa}")
  19.     public String updatePath(@PathVariable("idPompa") int idPompa, Model model) {
  20.  
  21.         Optional<Pompa> p = pompaService.findById(idPompa);
  22.         if (p.isPresent()) {
  23.  
  24.             model.addAttribute("pompa", p.get());
  25.             System.out.println("get: " + p.toString());
  26.             return "/admin/modificaPompa";
  27.  
  28.         } else {
  29.             System.out.println("La pompa non esiste");
  30.             return "redirect:/admin/pompe";
  31.         }
  32.     }
  33.  
  34.     @PostMapping(value = "/modificaPompa/{idPompa}")
  35.     public String updatePath(@ModelAttribute("pompa") Pompa editedPompa, @PathVariable("idPompa") int idPompa,
  36.             BindingResult result, RedirectAttributes redirectAttributes, Model model) {
  37.  
  38.         System.out.println("Post: " + editedPompa.toString() + idPompa);
  39.  
  40.         redirectAttributes.addFlashAttribute("message", "Impossibile Effettuare la modifica");
  41.         redirectAttributes.addFlashAttribute("alertClass", "alert alert-danger");
  42.  
  43.         if (result.hasErrors()) {
  44.             System.out.println("BindingResult : C'è stato un errore");
  45.         }
  46.  
  47.         if (result.getSuppressedFields().length > 0) {
  48.             System.out.println("ValidationBindingResult : "
  49.                     + StringUtils.arrayToCommaDelimitedString(result.getSuppressedFields()));
  50.         } else {
  51.  
  52.             Optional<Pompa> p = pompaService.findById(idPompa);
  53.  
  54.             // if (editedPompa.getId()==null) {//significa che è una modifica
  55.             if (p.isPresent()) {
  56.                 editedPompa.setQRcode(p.get().getQRcode());
  57.                 editedPompa.setId(idPompa);
  58.                 pompaService.save(editedPompa);
  59.  
  60.                 redirectAttributes.addFlashAttribute("message", "Modifica Avvenuta Con Successo");
  61.                 redirectAttributes.addFlashAttribute("alertClass", "alert alert-success");
  62.  
  63.                 return "redirect:/admin/modificaPompa/" + editedPompa.getId();
  64.  
  65.             } else {
  66.                 System.out.println("pompa inesistente");
  67.             }
  68.  
  69.         }
  70.  
  71.         return "redirect:/admin/pompe";
  72.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top