1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| package org.miage.sid.controller;
import java.util.List;
import javax.validation.Valid;
import org.miage.sid.entity.Commune;
import org.miage.sid.service.CommuneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class CommuneController {
@Autowired
private CommuneService metier;
@ModelAttribute(value = "communes")
public List<Commune> getCommuneList() {
return metier.findAll();
}
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView index(ModelMap model) {
model.put("commune", new Commune());
return new ModelAndView("formCommunes", model);
}
@RequestMapping(value = "/saveCommune", method = RequestMethod.POST)
public ModelAndView save(@Valid Commune c, BindingResult bindingResult, ModelMap model) {
if (bindingResult.hasErrors()) {
return new ModelAndView("formCommunes");
}
metier.insert(c);
model.put("commune", new Commune());
return new ModelAndView("formCommunes", model);
}
@RequestMapping(value = "/editCommune", method = RequestMethod.GET)
public ModelAndView edit(@RequestParam String codeInsee, ModelMap model) {
model.put("commune", metier.findOne(codeInsee));
return new ModelAndView("formCommunes", model);
}
@RequestMapping(value = "/deleteCommune", method = RequestMethod.GET)
public ModelAndView delete(@RequestParam String codeInsee, ModelMap model) {
metier.delete(codeInsee);
model.put("commune", new Commune());
return new ModelAndView("formCommunes", model);
}
@RequestMapping(value = "/codeInsee/{value}", method = RequestMethod.GET)
public ModelAndView getCommuneByCodeInsee(@PathVariable("value") String key, ModelMap model) {
model.put("communeList", metier.findByCodeInsee(key));
return new ModelAndView("f_comboCommune", model);
}
@RequestMapping(value = "/codePostal/{value}", method = RequestMethod.GET)
public ModelAndView getCommuneByCodePostal(@PathVariable("value") String key, ModelMap model) {
model.put("communeList", metier.findByCodePostal(key));
return new ModelAndView("f_comboCommune", model);
}
@RequestMapping(value = "/libelle/{value}", method = RequestMethod.GET)
public ModelAndView getCommuneByLibelle(@PathVariable("value") String key, ModelMap model) {
model.put("communeList", metier.findByLibelle(key));
return new ModelAndView("f_comboCommune", model);
}
} |
Partager