public class MemberDTO { private String id; private String name; private int age; public MemberDTO() { super(); } public MemberDTO(String id, String name, int age) { super(); this.id = id; this.name = name; this.age = age; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "MemberDTO [id=" + id + ", name=" + name + ", age=" + age + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + age; result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; MemberDTO other = (MemberDTO) obj; if (age != other.age) return false; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; }
}
package aop.service;
import java.util.ArrayList;
import aop.dto.MemberDTO;
public interface MemberService {
public abstract MemberDTO selectMemberById(String id);
public abstract ArrayList selectAllMember();
public abstract void registerMember(MemberDTO mto);
public abstract void modifyMember(MemberDTO mto);
}
package aop.service;
import java.util.ArrayList;
import aop.dto.MemberDTO;
public class MemberServiceImpl implements MemberService {
@Override public MemberDTO selectMemberById(String id){ System.out.println("MemberServiceImpl.selectMemberById() 실행"); return new MemberDTO(id, "홍길동", 33); }
@Override public ArrayList selectAllMember(){ System.out.println("MemberServiceImpl.selectAllMember() 실행"); return new ArrayList(); }
@Override public void registerMember(MemberDTO mto){ System.out.println("MemberServiceImpl.registerMember(mto) 실행"); throw new RuntimeException("가입도중 오류 발생"); }
@Override public void modifyMember(MemberDTO mto){ System.out.println("MemberServiceImpl.modifyMember(mto) 실행"); throw new RuntimeException("회원 정보 수정 도충 오류발생"); } }
* 결과
MemberServiceImpl.selectMemberById() 실행 ------------LoggerAdvice.afterReturnLogger 시작-------------- ------------LoggerAdvice.afterReturnLogger 종료-------------- ------------LoggerAdvice.afterReturnLogger2 시작-------------- ret : MemberDTO [id=abcde, name=홍길동, age=33] ------------LoggerAdvice.afterReturnLogger2 종료-------------- main() : MemberDTO [id=abcde, name=홍길동, age=1000] MemberServiceImpl.selectAllMember() 실행 ------------LoggerAdvice.afterReturnLogger 시작-------------- ------------LoggerAdvice.afterReturnLogger 종료-------------- ------------LoggerAdvice.afterReturnLogger2 시작-------------- ret : [] ------------LoggerAdvice.afterReturnLogger2 종료-------------- main() : [] MemberServiceImpl.registerMember(mto) 실행 가입도중 오류 발생