1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "=//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="ArticleDAO"> <select id="getNowSystemDate" resultType="string"> SELECT SYSDATE FROM DUAL </select> <select id="getAllEmployeeInfo" parameterType="map" resultType="EmployeesVO"> SELECT /* [ArticleDAO.getAllEmployeeInfo] */ EMPLOYEE_ID employeeId , FIRST_NAME firstName <choose> <when test="employee.firstName!=null and employee.firstName!=''"> , LAST_NAME lastName , EMAIL email , SALARY salary , COMMISSION_PCT commissionPct , HIRE_DATE hireDate , D.DEPARTMENT_NAME departmentName </when> <when test="employee.lastName != null and employee.lastName !=''"> , LAST_NAME lastName , EMAIL email </when> <otherwise> , LAST_NAME lastName , EMAIL email , SALARY salary , COMMISSION_PCT commissionPct , HIRE_DATE hireDate </otherwise> </choose> FROM EMPLOYEES <if test="employee.firstName != null and employee.firstName != ''"> E , DEPARTMENTS D </if> <where> <if test="employee.lastName != null and employee.lastName !=''"> LAST_NAME=#{lastName} </if> <if test="employee.firstName != null and employee.firstName != ''"> AND E.DEPARTMENT_ID = D.DEPARTMENT_ID AND FIRST_NAME=#{firstName} </if> <if test="managerIds != null"> AND MANAGER_ID IN <foreach collection="managerIds" item="managerId" separator=", " open="(" close=")"> #{managerId} </foreach> </if> </where> </select> </mapper> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | @Override public List<EmployeesVO> getAllEmployeeInfo() { // String lastName = "King"; Map<String, Object> parameters = new HashMap<String, Object>(); // parameters.put("firstName", "Steven"); // parameters.put("lastName", "King"); // parameters.put("other", new EmployeesVO()); 이런것도 가능하다. EmployeesVO employee = new EmployeesVO(); //employee.setFirstName("Steven"); //employee.setLastName("King"); List<Integer> managerId = new ArrayList<Integer>(); managerId.add(100); managerId.add(101); managerId.add(102); managerId.add(103); parameters.put("employee", employee); parameters.put("managerIds", managerId); return getSqlSession().selectList("ArticleDAO.getAllEmployeeInfo", parameters); } | cs |
'Back-end > Spring' 카테고리의 다른 글
[Spring] 게시판 만들기 (0) | 2016.04.21 |
---|---|
[Spring] 게시판 만들기 기본 (2) | 2016.04.21 |
[Spring] Insert, Select, 실습 (0) | 2016.04.20 |
[Spring] DB를 사용하는 방법 - myBatis 개념 (0) | 2016.04.20 |
[Spring] ORM : MyBatis 연동 2 (0) | 2016.04.19 |