SSSP项目-分层结构设计

  • A+
所属分类:JAVA

一、分层结构设计

设计如下:

DAO层:数据处理层

Service层:业务逻辑层

Controller层:操作控制层

JSP页面:使用JSTL来显示页面

各层的具体基本实现如下:

DAO层

EmployeeRepository

  1. public interface EmployeeRepository extends JpaRepository<Employee, Integer>{
  2. }

DeptRepository

  1. public interface DeptRepository extends JpaRepository<Dept, Integer>{
  2.     @QueryHints({@QueryHint(name=org.hibernate.ejb.QueryHints.HINT_CACHEABLE,value="true")})
  3.     @Query("from Dept d")
  4.     List<Dept> getAll();
  5. }

Service层

EmployeeService

  1. @Service
  2. public class EmployeeService {
  3.     @Autowired
  4.     private EmployeeRepository employeeRepository;
  5.     /**
  6.      * 所有员工列表信息
  7.      * @return
  8.      */
  9.     @Transactional(readOnly=true)
  10.     public List<Employee> getAll(){
  11.         return employeeRepository.findAll();
  12.     }
  13. }

DeptService

  1. @Service
  2. public class DeptService {
  3.     @Autowired
  4.     private DeptRepository deptRepository;
  5. }

Controller层

EmployeeController

  1. @Controller
  2. public class EmployeeController {
  3.     @Autowired
  4.     private EmployeeService employeeService;
  5.     @Autowired
  6.     private DeptService deptService;
  7.     @RequestMapping("/emplist")
  8.     public String emplist(Map<String, Object> map) {
  9.         List<Employee> empList = employeeService.getAll();
  10.         map.put("empList", empList);
  11.         return "employee/list";
  12.     }
  13. }

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: