Formatted the code

This commit is contained in:
Dheeraj-Baluja 2014-07-05 01:27:10 +05:30
parent c3d7000ff1
commit 8434f826e6
4 changed files with 53 additions and 51 deletions

View File

@ -12,7 +12,7 @@
<body> <body>
<h3>Welcome, Enter The Employee Details</h3> <h3>Welcome, Enter The Employee Details</h3>
<form:form method="POST" action="/SpringMVCFormExample/addEmployee" <form:form method="POST" action="/spring-mvc-forms/addEmployee"
commandName="employee"> commandName="employee">
<table> <table>
<tr> <tr>

View File

@ -1,16 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee"
<javaee:display-name>SpringMVCFormExample</javaee:display-name> xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
<servlet> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5">
<servlet-name>dispatcher</servlet-name> <javaee:display-name>SpringMVCFormExample</javaee:display-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <servlet>
<load-on-startup>1</load-on-startup> <servlet-name>dispatcher</servlet-name>
</servlet> <servlet-class>org.springframework.web.servlet.DispatcherServlet
<servlet-mapping> </servlet-class>
<servlet-name>dispatcher</servlet-name> <load-on-startup>1</load-on-startup>
<url-pattern>/</url-pattern> </servlet>
</servlet-mapping> <servlet-mapping>
<welcome-file-list> <servlet-name>dispatcher</servlet-name>
<welcome-file>index.jsp</welcome-file> <url-pattern>/</url-pattern>
</welcome-file-list> </servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app> </web-app>

View File

@ -15,20 +15,19 @@ import com.demo.form.Employee;
@Controller @Controller
public class EmployeeController { public class EmployeeController {
@RequestMapping(value = "/employee", method = RequestMethod.GET) @RequestMapping(value = "/employee", method = RequestMethod.GET)
public ModelAndView showForm() { public ModelAndView showForm() {
return new ModelAndView("employeeHome", "employee", new Employee()); return new ModelAndView("employeeHome", "employee", new Employee());
} }
@RequestMapping(value = "/addEmployee", method = RequestMethod.POST) @RequestMapping(value = "/addEmployee", method = RequestMethod.POST)
public String submit(@Valid @ModelAttribute("employee")Employee employee, BindingResult result, public String submit(@Valid @ModelAttribute("employee") Employee employee, BindingResult result, ModelMap model) {
ModelMap model) { if (result.hasErrors()) {
if (result.hasErrors()) { return "error";
return "error"; }
} model.addAttribute("name", employee.getName());
model.addAttribute("name", employee.getName()); model.addAttribute("contactNumber", employee.getContactNumber());
model.addAttribute("contactNumber", employee.getContactNumber()); model.addAttribute("id", employee.getId());
model.addAttribute("id", employee.getId()); return "employeeAdded";
return "employeeAdded"; }
}
} }

View File

@ -2,32 +2,32 @@ package com.demo.form;
public class Employee { public class Employee {
private String name; private String name;
private long id; private long id;
private String contactNumber; private String contactNumber;
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public long getId() { public long getId() {
return id; return id;
} }
public void setId(long id) { public void setId(long id) {
this.id = id; this.id = id;
} }
public String getContactNumber() { public String getContactNumber() {
return contactNumber; return contactNumber;
} }
public void setContactNumber(String contactNumber) { public void setContactNumber(String contactNumber) {
this.contactNumber = contactNumber; this.contactNumber = contactNumber;
} }
} }