formatting work
This commit is contained in:
@@ -8,10 +8,10 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
||||
@Configuration
|
||||
public class ClientWebConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
public ClientWebConfig() {
|
||||
super();
|
||||
}
|
||||
public ClientWebConfig() {
|
||||
super();
|
||||
}
|
||||
|
||||
// API
|
||||
// API
|
||||
|
||||
}
|
||||
@@ -17,40 +17,40 @@ import org.springframework.web.servlet.view.JstlView;
|
||||
//@Configuration
|
||||
public class ClientWebConfigJava extends WebMvcConfigurerAdapter {
|
||||
|
||||
public ClientWebConfigJava() {
|
||||
super();
|
||||
}
|
||||
public ClientWebConfigJava() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageSource messageSource() {
|
||||
@Bean
|
||||
public MessageSource messageSource() {
|
||||
|
||||
final ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
|
||||
ms.setBasenames("messages");
|
||||
return ms;
|
||||
}
|
||||
final ResourceBundleMessageSource ms = new ResourceBundleMessageSource();
|
||||
ms.setBasenames("messages");
|
||||
return ms;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ResourceBundle getBeanResourceBundle() {
|
||||
@Bean
|
||||
public ResourceBundle getBeanResourceBundle() {
|
||||
|
||||
final Locale locale = Locale.getDefault();
|
||||
return new MessageSourceResourceBundle(messageSource(), locale);
|
||||
}
|
||||
final Locale locale = Locale.getDefault();
|
||||
return new MessageSourceResourceBundle(messageSource(), locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addViewControllers(final ViewControllerRegistry registry) {
|
||||
super.addViewControllers(registry);
|
||||
@Override
|
||||
public void addViewControllers(final ViewControllerRegistry registry) {
|
||||
super.addViewControllers(registry);
|
||||
|
||||
registry.addViewController("/sample.html");
|
||||
}
|
||||
registry.addViewController("/sample.html");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ViewResolver viewResolver() {
|
||||
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
|
||||
@Bean
|
||||
public ViewResolver viewResolver() {
|
||||
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
|
||||
|
||||
bean.setViewClass(JstlView.class);
|
||||
bean.setPrefix("/WEB-INF/view/");
|
||||
bean.setSuffix(".jsp");
|
||||
bean.setViewClass(JstlView.class);
|
||||
bean.setPrefix("/WEB-INF/view/");
|
||||
bean.setSuffix(".jsp");
|
||||
|
||||
return bean;
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
@@ -18,28 +18,28 @@ import com.baeldung.spring.form.Employee;
|
||||
@Controller
|
||||
public class EmployeeController {
|
||||
|
||||
Map<Long, Employee> employeeMap = new HashMap<>();
|
||||
Map<Long, Employee> employeeMap = new HashMap<>();
|
||||
|
||||
@RequestMapping(value = "/employee", method = RequestMethod.GET)
|
||||
public ModelAndView showForm() {
|
||||
return new ModelAndView("employeeHome", "employee", new Employee());
|
||||
}
|
||||
@RequestMapping(value = "/employee", method = RequestMethod.GET)
|
||||
public ModelAndView showForm() {
|
||||
return new ModelAndView("employeeHome", "employee", new Employee());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/employee/{Id}", produces = { "application/json", "application/xml" }, method = RequestMethod.GET)
|
||||
public @ResponseBody Employee getEmployeeById(@PathVariable final long Id) {
|
||||
return employeeMap.get(Id);
|
||||
}
|
||||
@RequestMapping(value = "/employee/{Id}", produces = { "application/json", "application/xml" }, method = RequestMethod.GET)
|
||||
public @ResponseBody Employee getEmployeeById(@PathVariable final long Id) {
|
||||
return employeeMap.get(Id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/addEmployee", method = RequestMethod.POST)
|
||||
public String submit(@ModelAttribute("employee") final Employee employee, final BindingResult result, final ModelMap model) {
|
||||
if (result.hasErrors()) {
|
||||
return "error";
|
||||
}
|
||||
model.addAttribute("name", employee.getName());
|
||||
model.addAttribute("contactNumber", employee.getContactNumber());
|
||||
model.addAttribute("id", employee.getId());
|
||||
employeeMap.put(employee.getId(), employee);
|
||||
return "employeeView";
|
||||
}
|
||||
@RequestMapping(value = "/addEmployee", method = RequestMethod.POST)
|
||||
public String submit(@ModelAttribute("employee") final Employee employee, final BindingResult result, final ModelMap model) {
|
||||
if (result.hasErrors()) {
|
||||
return "error";
|
||||
}
|
||||
model.addAttribute("name", employee.getName());
|
||||
model.addAttribute("contactNumber", employee.getContactNumber());
|
||||
model.addAttribute("id", employee.getId());
|
||||
employeeMap.put(employee.getId(), employee);
|
||||
return "employeeView";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ public class HelloController extends AbstractController {
|
||||
@Override
|
||||
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
ModelAndView model = new ModelAndView("helloworld");
|
||||
model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" +
|
||||
" using SimpleUrlHandlerMapping.");
|
||||
model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" + " using SimpleUrlHandlerMapping.");
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,7 @@ public class HelloGuestController extends AbstractController {
|
||||
@Override
|
||||
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
ModelAndView model = new ModelAndView("helloworld");
|
||||
model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" +
|
||||
" using ControllerClassNameHandlerMapping.");
|
||||
model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" + " using ControllerClassNameHandlerMapping.");
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,7 @@ public class HelloWorldController extends AbstractController {
|
||||
@Override
|
||||
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
ModelAndView model = new ModelAndView("helloworld");
|
||||
model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" +
|
||||
" using BeanNameUrlHandlerMapping.");
|
||||
model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" + " using BeanNameUrlHandlerMapping.");
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -22,63 +22,62 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
@Controller
|
||||
public class PersonController {
|
||||
|
||||
@Autowired
|
||||
PersonValidator validator;
|
||||
@Autowired
|
||||
PersonValidator validator;
|
||||
|
||||
@RequestMapping(value = "/person", method = RequestMethod.GET)
|
||||
public ModelAndView showForm(final Model model) {
|
||||
@RequestMapping(value = "/person", method = RequestMethod.GET)
|
||||
public ModelAndView showForm(final Model model) {
|
||||
|
||||
initData(model);
|
||||
return new ModelAndView("personForm", "person", new Person());
|
||||
}
|
||||
initData(model);
|
||||
return new ModelAndView("personForm", "person", new Person());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/addPerson", method = RequestMethod.POST)
|
||||
public String submit(@Valid @ModelAttribute("person") final Person person, final BindingResult result,
|
||||
final ModelMap modelMap, final Model model) {
|
||||
@RequestMapping(value = "/addPerson", method = RequestMethod.POST)
|
||||
public String submit(@Valid @ModelAttribute("person") final Person person, final BindingResult result, final ModelMap modelMap, final Model model) {
|
||||
|
||||
validator.validate(person, result);
|
||||
validator.validate(person, result);
|
||||
|
||||
if (result.hasErrors()) {
|
||||
if (result.hasErrors()) {
|
||||
|
||||
initData(model);
|
||||
return "personForm";
|
||||
}
|
||||
initData(model);
|
||||
return "personForm";
|
||||
}
|
||||
|
||||
modelMap.addAttribute("person", person);
|
||||
modelMap.addAttribute("person", person);
|
||||
|
||||
return "personView";
|
||||
}
|
||||
return "personView";
|
||||
}
|
||||
|
||||
private void initData(final Model model) {
|
||||
private void initData(final Model model) {
|
||||
|
||||
final List<String> favouriteLanguageItem = new ArrayList<String>();
|
||||
favouriteLanguageItem.add("Java");
|
||||
favouriteLanguageItem.add("C++");
|
||||
favouriteLanguageItem.add("Perl");
|
||||
model.addAttribute("favouriteLanguageItem", favouriteLanguageItem);
|
||||
final List<String> favouriteLanguageItem = new ArrayList<String>();
|
||||
favouriteLanguageItem.add("Java");
|
||||
favouriteLanguageItem.add("C++");
|
||||
favouriteLanguageItem.add("Perl");
|
||||
model.addAttribute("favouriteLanguageItem", favouriteLanguageItem);
|
||||
|
||||
final List<String> jobItem = new ArrayList<String>();
|
||||
jobItem.add("Full time");
|
||||
jobItem.add("Part time");
|
||||
model.addAttribute("jobItem", jobItem);
|
||||
final List<String> jobItem = new ArrayList<String>();
|
||||
jobItem.add("Full time");
|
||||
jobItem.add("Part time");
|
||||
model.addAttribute("jobItem", jobItem);
|
||||
|
||||
final Map<String, String> countryItems = new LinkedHashMap<String, String>();
|
||||
countryItems.put("US", "United Stated");
|
||||
countryItems.put("IT", "Italy");
|
||||
countryItems.put("UK", "United Kingdom");
|
||||
countryItems.put("FR", "Grance");
|
||||
model.addAttribute("countryItems", countryItems);
|
||||
final Map<String, String> countryItems = new LinkedHashMap<String, String>();
|
||||
countryItems.put("US", "United Stated");
|
||||
countryItems.put("IT", "Italy");
|
||||
countryItems.put("UK", "United Kingdom");
|
||||
countryItems.put("FR", "Grance");
|
||||
model.addAttribute("countryItems", countryItems);
|
||||
|
||||
final List<String> fruit = new ArrayList<String>();
|
||||
fruit.add("Banana");
|
||||
fruit.add("Mango");
|
||||
fruit.add("Apple");
|
||||
model.addAttribute("fruit", fruit);
|
||||
final List<String> fruit = new ArrayList<String>();
|
||||
fruit.add("Banana");
|
||||
fruit.add("Mango");
|
||||
fruit.add("Apple");
|
||||
model.addAttribute("fruit", fruit);
|
||||
|
||||
final List<String> books = new ArrayList<String>();
|
||||
books.add("The Great Gatsby");
|
||||
books.add("Nineteen Eighty-Four");
|
||||
books.add("The Lord of the Rings");
|
||||
model.addAttribute("books", books);
|
||||
}
|
||||
final List<String> books = new ArrayList<String>();
|
||||
books.add("The Great Gatsby");
|
||||
books.add("Nineteen Eighty-Four");
|
||||
books.add("The Lord of the Rings");
|
||||
model.addAttribute("books", books);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ public class WelcomeController extends AbstractController {
|
||||
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
ModelAndView model = new ModelAndView("welcome");
|
||||
model.addObject("msg", " Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" +
|
||||
" using SimpleUrlHandlerMapping.");
|
||||
model.addObject("msg", " Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" + " using SimpleUrlHandlerMapping.");
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -7,146 +7,146 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public class Person {
|
||||
|
||||
private long id;
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
private String email;
|
||||
private String dateOfBirth;
|
||||
private String name;
|
||||
private String email;
|
||||
private String dateOfBirth;
|
||||
|
||||
@NotEmpty
|
||||
private String password;
|
||||
private String sex;
|
||||
private String country;
|
||||
private String book;
|
||||
private String job;
|
||||
private boolean receiveNewsletter;
|
||||
private String[] hobbies;
|
||||
private List<String> favouriteLanguage;
|
||||
private List<String> fruit;
|
||||
private String notes;
|
||||
private MultipartFile file;
|
||||
@NotEmpty
|
||||
private String password;
|
||||
private String sex;
|
||||
private String country;
|
||||
private String book;
|
||||
private String job;
|
||||
private boolean receiveNewsletter;
|
||||
private String[] hobbies;
|
||||
private List<String> favouriteLanguage;
|
||||
private List<String> fruit;
|
||||
private String notes;
|
||||
private MultipartFile file;
|
||||
|
||||
public Person() {
|
||||
super();
|
||||
}
|
||||
public Person() {
|
||||
super();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(final long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(final String email) {
|
||||
this.email = email;
|
||||
}
|
||||
public void setEmail(final String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getDateOfBirth() {
|
||||
return dateOfBirth;
|
||||
}
|
||||
public String getDateOfBirth() {
|
||||
return dateOfBirth;
|
||||
}
|
||||
|
||||
public void setDateOfBirth(final String dateOfBirth) {
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
}
|
||||
public void setDateOfBirth(final String dateOfBirth) {
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(final String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public void setPassword(final String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getSex() {
|
||||
return sex;
|
||||
}
|
||||
public String getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(final String sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
public void setSex(final String sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(final String country) {
|
||||
this.country = country;
|
||||
}
|
||||
public void setCountry(final String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getJob() {
|
||||
return job;
|
||||
}
|
||||
public String getJob() {
|
||||
return job;
|
||||
}
|
||||
|
||||
public void setJob(final String job) {
|
||||
this.job = job;
|
||||
}
|
||||
public void setJob(final String job) {
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
public boolean isReceiveNewsletter() {
|
||||
return receiveNewsletter;
|
||||
}
|
||||
public boolean isReceiveNewsletter() {
|
||||
return receiveNewsletter;
|
||||
}
|
||||
|
||||
public void setReceiveNewsletter(final boolean receiveNewsletter) {
|
||||
this.receiveNewsletter = receiveNewsletter;
|
||||
}
|
||||
public void setReceiveNewsletter(final boolean receiveNewsletter) {
|
||||
this.receiveNewsletter = receiveNewsletter;
|
||||
}
|
||||
|
||||
public String[] getHobbies() {
|
||||
return hobbies;
|
||||
}
|
||||
public String[] getHobbies() {
|
||||
return hobbies;
|
||||
}
|
||||
|
||||
public void setHobbies(final String[] hobbies) {
|
||||
this.hobbies = hobbies;
|
||||
}
|
||||
public void setHobbies(final String[] hobbies) {
|
||||
this.hobbies = hobbies;
|
||||
}
|
||||
|
||||
public List<String> getFavouriteLanguage() {
|
||||
return favouriteLanguage;
|
||||
}
|
||||
public List<String> getFavouriteLanguage() {
|
||||
return favouriteLanguage;
|
||||
}
|
||||
|
||||
public void setFavouriteLanguage(final List<String> favouriteLanguage) {
|
||||
this.favouriteLanguage = favouriteLanguage;
|
||||
}
|
||||
public void setFavouriteLanguage(final List<String> favouriteLanguage) {
|
||||
this.favouriteLanguage = favouriteLanguage;
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(final String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
public void setNotes(final String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public List<String> getFruit() {
|
||||
return fruit;
|
||||
}
|
||||
public List<String> getFruit() {
|
||||
return fruit;
|
||||
}
|
||||
|
||||
public void setFruit(final List<String> fruit) {
|
||||
this.fruit = fruit;
|
||||
}
|
||||
public void setFruit(final List<String> fruit) {
|
||||
this.fruit = fruit;
|
||||
}
|
||||
|
||||
public String getBook() {
|
||||
return book;
|
||||
}
|
||||
public String getBook() {
|
||||
return book;
|
||||
}
|
||||
|
||||
public void setBook(final String book) {
|
||||
this.book = book;
|
||||
}
|
||||
public void setBook(final String book) {
|
||||
this.book = book;
|
||||
}
|
||||
|
||||
public MultipartFile getFile() {
|
||||
return file;
|
||||
}
|
||||
public MultipartFile getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(final MultipartFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
public void setFile(final MultipartFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,14 @@ import org.springframework.validation.Validator;
|
||||
@Component
|
||||
public class PersonValidator implements Validator {
|
||||
|
||||
@Override
|
||||
public boolean supports(final Class calzz) {
|
||||
return Person.class.isAssignableFrom(calzz);
|
||||
}
|
||||
@Override
|
||||
public boolean supports(final Class calzz) {
|
||||
return Person.class.isAssignableFrom(calzz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(final Object obj, final Errors errors) {
|
||||
@Override
|
||||
public void validate(final Object obj, final Errors errors) {
|
||||
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required.name");
|
||||
}
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required.name");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user