JPA-Test/src/main/java/com/guwan/backend/jpaTest/EmployeeController.java

44 lines
1.4 KiB
Java

package com.guwan.backend.jpaTest;
import com.guwan.backend.jpaTest.domain.EmployeeDTO;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/employees")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@Autowired
private JdbcTemplate jdbcTemplate;
@PersistenceContext
private EntityManager entityManager;
/**
* 获取员工详细信息,包含部门和项目信息
* 使用Spring JdbcTemplate直接映射SQL结果
*
* @param departmentName 部门名称过滤条件
* @param projectDeleted 项目是否已删除的过滤条件
* @return 员工DTO列表
*/
@GetMapping("/details")
public Page<EmployeeDTO> getEmployeeDetails(
@RequestParam(required = false) String departmentName,
@RequestParam(required = false, defaultValue = "false") boolean projectDeleted) {
return employeeService.getEmployeeDetails(departmentName, projectDeleted, 0, 2);
}
}