Modifying employeecontroller.java file – HP Integrity NonStop H-Series User Manual
Page 375
![background image](/manuals/397675/375/background.png)
public Employee getDetail(int empid)throws SQLException;
public void insertDetail(int empid, String firstname, String lastname,
int age, String email)throws SQLException;
public String deleteEmployee(int empid)throws SQLException;
Modifying
EmployeeController.java
File
Modify
EmployeeController.java
to replace the instance of the
EmployeeDao.java
class
with the instance of the
IEmployeeDao.java
interface.
To modify the
EmployeeController.java
file, complete the following steps:
1.
Change an import statement to import the
IEmployeeDao.java
interface instead of
EmployeeDao.java
.
import com.hp.empinfo.service.IEmployeeDao;
2.
Replace the
EmployeeDao
instance with that of
IEmployeeDao
as:
private IEmployeeDao empdao;
empdao = (IEmployeeDao) wac.getBean("iempdao");
After modification, the
EmployeeController.java
file must appear as:
package com.hp.empinfo.web;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import com.hp.empinfo.domain.Employee;
import com.hp.empinfo.service.IEmployeeDao;
public class EmployeeController extends SimpleFormController {
private IEmployeeDao empdao;
public ModelAndView onSubmit(Object command) throws ServletException,
SQLException {
WebApplicationContext wac = WebApplicationContextUtils
.getRequiredWebApplicationContext(getServletContext());
empdao = (IEmployeeDao) wac.getBean("iempdao");
int empid = ((Employee) command).getEmpid();
String firstname = ((Employee) command).getFirstname();
String lastname = ((Employee) command).getLastname();
int age = ((Employee) command).getAge();
String email = ((Employee) command).getEmail();
String rord = ((Employee) command).getRord();
if (rord != null && rord.equalsIgnoreCase("Retrieve")) {
Employee emp1 = empdao.getDetail(empid);
Map
model.put("empid", "" + emp1.getEmpid());
model.put("empfn", emp1.getFirstname());
Example of Using Spring Transaction Manager
375