MVC
- 低耦合:组件与组件之间联系不紧密,但有固定的关系,替换部分组件代价小
,比较容易。(前提原因是我们需要很多的组件将任务分工)
XX.jsp 视图层 用户(提要求)
--> XXAction 控制器层 门卫(判断要求有没有权利提,有
权利通知)
判断是否登录,判断是否取得数据,根据结果不同让用户到不同的页面去
--> XXService --> XXServiceImp 业务逻辑层 秘书(将信息处理后提交给领导)
if else for运算,将运算结果提交给领导决定如何操作数据库
XXDao --> XXDaoImp 数据访问层 领导(决定是否存取数据库)
hibernate
--> DB
private Session session = HibernateSessionFactory.getSession();
public List getServicemanInfo(){
Query query = session.createQuery("From Serviceman");
List servicemans = query.list();
HibernateSessionFactory.closeSession();
return servicemans;
}
项目设计模块(完成:将数据库数据显示在jsp页面)
ServicemanDao.java
package repairsystem.dao.imp;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import repairsystem.dao.ServicemanDaoI;
import repairsystem.entity.Serviceman;
import repairsystem.factory.HibernateSessionFactory;
public class ServicemanDao implements ServicemanDaoI{
private Session session = HibernateSessionFactory.getSession();
public List getServicemanInfo() {
Query query = session.createQuery("From Serviceman");
List servicemans = query.list();
HibernateSessionFactory.closeSession();
return servicemans;
}
}
ServicemanDaoI.java
package repairsystem.dao;
import java.util.List;
import repairsystem.entity.Serviceman;
public interface ServicemanDaoI {
public List getServicemanInfo();
}
ServicemanService.java
package repairsystem.service.serviceImp;
import java.util.List;
import repairsystem.dao.ServicemanDaoI;
import repairsystem.dao.imp.ServicemanDao;
import repairsystem.entity.Serviceman;
import repairsystem.service.ServicemanServiceI;
public class ServicemanService implements ServicemanServiceI{
private ServicemanDaoI servicemanDaoI;
public ServicemanService() {
super();
this.servicemanDaoI = new ServicemanDao();
}
public ServicemanDaoI getServicemanDaoI() {
return servicemanDaoI;
}
public void setServicemanDaoI(ServicemanDaoI servicemanDaoI) {
this.servicemanDaoI = servicemanDaoI;
}
public List getServicemanInfo(){
return servicemanDaoI.getServicemanInfo();
}
}
ServicemanServiceI.java
package repairsystem.service;
import java.util.List;
import repairsystem.entity.Serviceman;
public interface ServicemanServiceI {
public List getServicemanInfo();
}
ServicemanAction.java
package repairsystem.action;
import java.util.List;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import repairsystem.entity.Serviceman;
import repairsystem.service.ServicemanServiceI;
import repairsystem.service.serviceImp.ServicemanService;
public class ServicemanAction extends ActionSupport{
private Serviceman serviceman;
private ServicemanServiceI servicemanServiceI;
public ServicemanAction() {
super();
servicemanServiceI = new ServicemanService();
}
public Serviceman getServiceman() {
return serviceman;
}
public void setServiceman(Serviceman serviceman) {
this.serviceman = serviceman;
}
public ServicemanServiceI getServicemanServiceI() {
return servicemanServiceI;
}
public void setServicemanServiceI(ServicemanServiceI servicemanServiceI) {
this.servicemanServiceI = servicemanServiceI;
}
public String getServicemanInfo() throws Exception{
//action依次调用service dao后得到结果,再原路返回结果到了action,再将结果转发给页面
List servicemans = servicemanServiceI.getServicemanInfo();
ServletActionContext.getRequest().setAttribute("servicemans", servicemans);
return null;
}
}
struts.xml
getManagerInfo,getCustomerInfo,getHaveskillInfo,getServicemanInfo,
getServiceprojectInfo,getServiceTypeInfo,getIntentionrecordInfo
serviceman.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
test
维修者id
姓名
电话
密码
住址
状态