본문 바로가기

Programming/Spring27

[spring] MyBatis 구현 [spring] MyBatis 구현 http://www.mybatis.org/mybatis-3/ko/ 마이바티스는 무엇인가? 마이바티스는 개발자가 지정한 SQL, 저장프로시저 그리고 몇가지 고급 매핑을 지원하는 퍼시스턴스 프레임워크이다. 마이바티스는 JDBC로 처리하는 상당부분의 코드와 파라미터 설정및 결과 매핑을 대신해준다. 마이바티스는 데이터베이스 레코드에 원시타입과 Map 인터페이스 그리고 자바 POJO 를 설정해서 매핑하기 위해 XML과 애노테이션을 사용할 수 있다. SqlSession 이 필요하다. @Autowired SqlSession session; MyBatis root element 는 configuration mapper 파일 목록 등록 mapper 파일 doctype namespace.. 2016. 4. 25.
[spring] iBatis 구현 [spring] iBatis 구현 서비스에서 ibatis 로 변경 @Resource(name = "ibatis") private UserDAO dao; mappers 패키지 생성 ibatis 용 map file 생성 usermapper_i.xml 파일 생성생성된 코드 쿼리들을 XML 파일에 넣어야 한다. insert into userinfo (userid, username, userpwd, email, phone,address) values (?, ?, ?,?,?,?) select * from userinfo where userid=? and userpwd = ? select * from userinfo where userid = ? select * from userinfo update userinfo .. 2016. 4. 25.
[spring] iBatis, MyBatis Framework 아키텍처 [spring] iBatis, MyBatis Framework 아키텍처 컬럼의 이름과 동일하게 만들었으므로 자동으로 매핑된다. 어떻게 세팅이 되는지 주의 깊게 본다. 이름만 잘 매핑되면 자동으로 처리된다.SQL 구문이 XML 문서로 존재한다. 환경이 달라진다. 프레임워크 이므로, 환경 설정 파일이 있다.2 버전 이하는 iBatis 3 버전 이상은 MyBatis JDBC Connection 부터 시작 중복코드 발생결과값 핸들링을 해야함. 직접 while loop 로 처리? 에 세팅 작업 필요 Spring DataSource 라는 환경을 기본으로 함 JDBCTemplate (커넥션을 알아야 함.)RowMapper 를 사용하여 결과값 처리세팅을 위한 인터페이스 제공 PreparedStatementSetter .. 2016. 4. 24.
[Spring] JDBC 설정 [Spring] JDBC 설정 DataSource 설정 JdbcTemplate 생성 JdbcTemplate 를 사용한다. JdbcTemplate template; UserRowMapper 클래스 생성RowMapper 를 구현한다. class UserRowMapper implements RowMapper{ @Override public UserVO mapRow(ResultSet arg0, int arg1) throws SQLException { // TODO Auto-generated method stub return null; } } 컬럼데이터를 바이딩해 준다. class UserRowMapper implements RowMapper { @Override public UserVO mapRow(Result.. 2016. 4. 24.
[spring] 데이터 접근 디자인 패턴 [spring] 데이터 접근 디자인 패턴 Template Method Pattern JDBC 개념 인터페이스만 보고 작업을 한다. JDBC DRIVER 를 사용한다. JDBC 구현 순서 특정 DBMS 에ego당하는 Driver 로딩 DBMS 와의 Connection 연결 Statement 객체 생성 SQL 문에 파라미터 정보 설정 Statement 실행 ResultSet 처리하기 위한 Loop 문 실행 예외처리 트랜잭션 처리 Connection 해제 기본형태 생성 Connection con = null; PreparedStatement ps = null; ResultSet rs = null; int result = 0; try { con = JDBCUtil.getConnection(); ps = con... 2016. 4. 23.
[spring] 다국어 지원 [spring] 다국어 지원 다국어 지원을 위해서 메세지 리소스를 구축해야 함 resources 폴더에 작업 다국어 지원 개념 메시지 소스 파일 resources 에 패키지 생성messages 패키지 생성message_ko.properties 파일 생성내용입력 hello=안녕하세요 login.success=로그인 되었습니다. {0}님 login.fail=id:{0} 로그인 실패 영어 기반 파일 생성. message_en.properties 파일 생성 hello=HI!! login.success=Welcome {0} login.fail=id:{0} retry message 로 시작하는 프로퍼티 파일을 만들었다. 시스템의 로케일에 따라 언어별 코드가 매핑되어 리소스 파일을 사용한다.applicationCon.. 2016. 4. 22.