Mapper 에서 Property, column
Q.
(24-10-21, Spring 08-08 수업의 ProfessorMapper 에서)
@Result(property = "hiredate", column = "hiredate"),여기서 property는 빈즈 클래스에서 가져올 멤버변수인가?
A.
네, 맞습니다. @Result 어노테이션의 property 속성은 Java 빈 클래스에서 가져올 멤버 변수를 나타냅니다. column 속성은 SQL 쿼리 결과에서 해당하는 컬럼 이름을 나타냅니다.
예를 들어, 다음과 같은 Professor 클래스가 있다고 가정해봅시다:
public class Professor {
private int id;
private String name;
private String userid;
private String position;
private double sal;
private Date hiredate; // hiredate 멤버 변수
private double comm;
private int deptno;
// getters and setters
}
이 경우, @Result(property = "hiredate", column = "hiredate")는 SQL 쿼리 결과에서 hiredate 컬럼의 값을 Professor 클래스의 hiredate 멤버 변수에 매핑합니다.
따라서 property는 Java 클래스의 멤버 변수 이름이고, column은 SQL 쿼리 결과의 컬럼 이름입니다.