Programing/Spring Framework 13

Spring JDBC

Spring JDBCSQL를 쉽게 날릴수 있도록 만들어진 libraryRowMapper 인터페이스를 통해 데이터맵핑을 할수 있다.JdbcTemplate, NamedParameterTemplateDatasource가 필요하다.Spring Data Jpa 등의 ORM을 사용할때, DB의 Index Hints 기능을 활용하지 못하는데 Spring JDBC를 직접 Native Query를 작성함으로써 해결을 할수있다.JdbcTemplateint rowCount = this.jdbcTemplate.queryForObject("select count(*) from t_actor", Integer.class); int countOfActorsNamedJoe = this.jdbcTemplate.queryForObjec..

Attribute Converter를 이용한 커스텀 컬럼 사용하기

Attribute Converter를 이용한 커스텀 컬럼 사용하기데이터를 저장할때 사용하는 방식으로 JSON 방식으로 사용하는 경우가 많다. DB에서 데이터를 읽을 때에는 객체로 변환하고 저장할때에는 스트링 형태로 다시 변환하는 과정이 필요하다. JPA의 Attribute Converter를 이용하면 이러한 과정 없이 Repository에서 읽어들인 값을 이용하여 바로 객체로 변환할수가 있다.Json Object@JsonIgnoreProperties(ignoreUnknown = true)public class EventData { private String name; private String password;}Converter@Converterpublic class EventDataConverter i..

@Value 어노테이션 활용

@Value 어노테이션 활용Code exmaple@Value("${property_name}")private String name; @Value("${property_boolean_name}")private Boolean name;Property관련 설정이 있어야 가능.PropertySource 어노테이션을 이용하여 가능(참고) PropertySource AnnotationProfile에 따라 PropertySource를 다르게 설정하는 법.@Componentpublic class PropertyConfig { @Configuration @Profile("develop") @PropertySource("classpath:develop.properties") public static class Develo..