Skip to content
Snippets Groups Projects

Draft: Towns

Closed Rhys Nute requested to merge towns into main
Files
2
@@ -33,4 +33,19 @@ public class organisationControllers {
ModelAndView modelAndView = new ModelAndView("WorkWith/towns.html");
return modelAndView;
}
@Autowired
private addAddTownsRepository addAddTownsRepository;
@PostMapping("/townssub")
public ModelAndView townsSent(@Valid @ModelAttribute("towns-data")Towns towns, BindingResult bindingResult, Model model ) {
if (bindingResult.hasErrors()) {
ModelAndView modelAndView = new ModelAndView("towns-data", model.asMap());
return modelAndView;
} else {// converts user input using the organisation constructor into a submittable format to the sql table
Towns tow= new Towns(towns.getTownName(), towns.getAddress1(), towns.getAddress2(), towns.getCity(), towns.getCounty(), towns.getPostcode());
System.out.println(bus);
addAddTownsRepository.addAddTown(tow); //add new towns to Add Towns table
ModelAndView modelAndView = new ModelAndView("redirect:/businesses");
return modelAndView;
}
}
Loading