AUTO INCREMENT를 지원해 주는 DBMS의 경우 @Options(useGeneratedKeys=true, keyProperty = “id”) public class User { private int id; private String name; // getters and setters... } @Mapper public interface UserMapper { @Insert("INSERT INTO users (name) VALUES (#{name})") @Options(useGeneratedKeys = true, keyProperty = "id") int insert(User user); } useGeneratedKeys: 이 속성을 true로 설정하면 MyBatis가 쿼리 실행 후에 데이터베이스..
MyBatis
MyBatis Dynamic SQL (동적 SQL) 어노테이션에 직접 태그 등을 사용하려면 """) @Select(""" """) if SELECT * FROM BLOG WHERE state = ‘ACTIVE’ AND title like #{title} 조건식이 참인 경우 쿼리문을 실행한다. test문 따옴표 주의 test문은 ‘작은따옴표’(싱글쿼테이션) 로 묶는 것이 좋다. 문자열을 인식시키기 위해서는 큰 따옴표를 사용한다. ‘Y’는 char형식으로 취급되어 숫자 86으로 인식한다. 한 캐릭터의 문자열인 "Y"를 비교하려면 test문을 작은따옴표로 묶은 후, 문자열 등은 큰 따옴표로 묶어주는 것이 좋다. @Select(""" """) String select1(String country); foreac..