package [Link].
model;
import [Link];
import [Link];
import [Link];
import [Link];
@Entity
@Table(name="emp")
public class Employee {
@Id
@Column(name="eid")
private int empId;
@Column(name="ename")
private String empName;
@Column(name="esal")
private double empSal;
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
[Link] = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
[Link] = empName;
}
public double getEmpSal() {
return empSal;
}
public void setEmpSal(double empSal) {
[Link] = empSal;
}
@Override
public String toString() {
return "Employee [empId=" + empId + ", empName=" +
empName
+ ", empSal=" + empSal + "]";
}
}
package [Link];
import
[Link];
import [Link];
import
[Link];
import
[Link];
import
[Link];
import [Link];
import [Link];
import [Link];
@Controller
public class EmployeeController {
@Autowired
private IEmployeeService empService;
@RequestMapping(value="/regiterpage")
public ModelAndView getPage(){
ModelAndView mav=new ModelAndView("Register");
return mav;
}
@RequestMapping(value="/showData",method=[Link])
public ModelAndView
showDetails(@ModelAttribute("employee")Employee emp){
//logic to call service layer
Integer
empId=[Link](emp);
ModelAndView mav=new ModelAndView("Details");
[Link]("id",empId);
return mav;
}
package [Link];
import [Link];
public interface IEmployeeDao {
public Integer insertEmployeeDetails(Employee emp);
}
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class EmployeeDaoImplHibernate implements
IEmployeeDao {
private SessionFactory sessionFacorty;
public void setSessionFacorty(SessionFactory
sessionFacorty) {
[Link] = sessionFacorty;
}
@Override
public Integer insertEmployeeDetails(Employee emp) {
Session session=null;
Transaction tx=null;
Integer empId=null;
try {
session=[Link]();
tx=[Link]();
[Link]();
empId=(Integer)[Link](emp);
[Link]();
} catch (Exception e) {
[Link]();
}finally{
if(session!=null){
[Link]();
[Link]();
}
}
return empId;
}
}
package [Link];
import [Link];
public interface IEmployeeService {
public Integer insertEmployeeDetails(Employee emp);
}
package [Link];
import [Link];
import [Link];
import [Link];
public class EmployeeServiceImpl implements
IEmployeeService{
private IEmployeeDao empDao;
public void setEmpDao(IEmployeeDao empDao) {
[Link] = empDao;
}
@Override
public Integer insertEmployeeDetails(Employee emp) {
Integer empId=[Link](emp);
return empId;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="[Link]
xmlns:xsi="[Link]
xmlns:context="[Link]
"
xsi:schemaLocation="[Link]
ans
[Link]
[Link]
[Link]
[Link]
">
<context:annotation-config/>
<context:component-scan base-package="[Link]"/>
<!-- View Resolver Configuration -->
<bean
class="[Link]
ViewResolver">
<property name="prefix" value="/WEB-INF/jsps/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- Data Source Configuration -->
<bean
class="[Link]
Source" name="datasourceObj">
<property name="driverClassName"
value="[Link]"/>
<property name="url"
value="jdbc:mysql://localhost:3306/test"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<bean
class="[Link]
ionSessionFactoryBean" name="sessionFactoryObj">
<property name="dataSource" ref="datasourceObj"/>
<property name="hibernateProperties">
<props>
<prop
key="[Link]">[Link]</
prop>
<prop key="hibernate.show_sql">true</prop>
<prop
key="[Link]">update</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>[Link]</value>
</list>
</property>
</bean>
<bean class="[Link]"
name="empDaoObj">
<property name="sessionFacorty">
<ref bean="sessionFactoryObj"/>
</property>
</bean>
<bean class="[Link]"
name="empServiceObj">
<property name="empDao">
<ref bean="empDaoObj"/>
</property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="[Link]
instance"
xmlns="[Link]
xsi:schemaLocation="[Link]
[Link]
id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>project</servlet-name>
<servlet-
class>[Link]</
servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>project</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
</web-app>
<%@ page language="java" contentType="text/html;
charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="showData" method="POST">
<pre>
Enter Id : <input type="text" name="empId"/>
Enter Name : <input type="text" name="empName"/>
Enter Sal :<input type="text" name="empSal"/>
<input type="submit" value="Register">
<input type="reset" value="Clear">
</pre>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html;
charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<pre>
Inserted Details for Emp Id: ${id}
</pre>
</body>
</html>