Category Archives: FrameWork

json 출력 혹은 swagger 문서에서 VO객체의 일부 필드(멤버) 숨기기 (Spring 4, jackson2, springfox 2.9 환경)

By | 6월 30, 2021

@ApiModelProperty(notes = "책 썸네일 atchFileId", hidden = true) @JsonIgnore private String bookThumbnailFileId; swagger의 모델 정의에서 필드 숨기기 @ApiModelProperty를 아예 필드에 붙이지 않는다. 모종의 이유로 붙였을 경우에는 @ApiModelProperty(hidden = true)를 사용한다. json response 에서 필드 숨기기 @JsonIgnore 를 사용한다. @JsonIgnore는 꼭 com.fasterxml.jackson.annotation.JsonIgnore 을 사용해야 한다. (java 패키지 확인)

MyBatis insert 문 사용시 PK 획득하기 (useGeneratedKeys)

By | 9월 25, 2021

mybatis query xml <insert id="insertBook" useGeneratedKeys="true" keyProperty="bookId"> INSERT /* insertBook */ INTO book ( book_title ) VALUES ( #{bookTitle} ) </insert> 쿼리 이후 result 객체가 아닌 parameter 객체에서 bookId 를 참조하면 PK 획득. 이 테이블의 PK는 book_id 이지만 auto increment 이기 때문에 쿼리에는 기재되지 않았음. 대신 keyProperty 에 프로퍼티명이 명시되어 있음 mybatis config에 mapUnderscoreToCamelCase 가… Read More »

[펌글] Spring Security 에서의 CORS 설정

By | 6월 29, 2021

spring security config 클래스 @EnableWebSecurity public class CustomSecurityConfig extends WebSecurityConfigurerAdapter { … @Override protected void configure(HttpSecurity http) throws Exception { http … .and() .authorizeRequests() .requestMatchers(CorsUtils::isPreFlightRequest).permitAll() // cors setting 1 … .and().cors(); // cors setting 2 } // cors setting 3 @Bean public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); // configuration.addAllowedOrigin("*"); configuration.addAllowedOrigin("http://localhost:3000"); configuration.addAllowedMethod("*"); configuration.addAllowedHeader("*");… Read More »

Mybatis 오류 어리둥절 케이스 (Error setting non null for parameter #12 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Could not set parameter at position 12 (values was ‘1’))

By | 6월 23, 2021

이 오류의 해결을 위해서 한참을 헤멨는데, mybatis mapper config 의 jdbcTypeForNull 을 NULL로 해 주라느니 등등 이것저것 해 봤지만 아무리 해도 듣지 않았다. 변수 바인딩 표현식 #{}도 오타/누락 등의 문제 없었고, 파라미터 갯수도 문제 없고. 그러다가 그냥 기존 xml 쿼리를 밀고 다시 짰더니 됐다. -_-… 뭐지..뭐였지…

Spring 4 JUnit 테스트 샘플 코드 (Spring 4.3.16 기준, Spring boot 예제 아님)

By | 6월 14, 2021

pom.xml <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.3.16</version> </dependency> TestJUnit.java package twopro; // 테스트코드에서도 log4j를 사용하고 싶다면 패키지는 꼭 필요한 듯. import cmm.jwt.TokenProvider; import lombok.extern.slf4j.Slf4j; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; /** * JUnit 테스트 * * @author 이프로 * @version 2021.06… Read More »

Spring 에서 @ResponseBody 로 json serialized response(응답) 를 생성할 때의 json 변환 규칙 재정의 하기 (null => “” 변환 등…)

By | 2월 11, 2022

일단 Spring 4에 내장된 jackson2 를 그대로 활용한다는 가정하에 기술한다. NullSerializer 작성 import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import java.io.IOException; /** * jackson > Object의 null값을 "null" 문자열 대신 ""로 출력할 수 있도록 설정 */ public class NullSerializer extends JsonSerializer<Object> { @Override public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException… Read More »

[링크] MyBatis 1:N select 결과 매핑하는 예제 (e.g. 게시물 목록조회시 게시물당 첨부파일목록을 함께 조회하여 그룹핑, group, collection, one to many)

By | 7월 8, 2021

[Mybatis] 1:N 관계 데이터 처리 data concatenation 주의사항 resultMap > collection 을 사용할 경우 collection 의 요소가 두 개 이상일 경우(거의 그렇겠지만) 평범한 페이징으로는 오류가 날 수 밖에 없다. offset, limit 등은 그룹핑 후에 걸어야 하는데, collection의 경우 쿼리가 다 끝나고 그룹핑 되므로 그래서 나는 그냥 resultMap-collection 패턴을 포기하고 주 레코드만 select 후, select된 목록의… Read More »

Spring 5 에 ehcache 2 적용 샘플

By | 4월 9, 2020

1.  pom.xml <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> <!– Spring 혹은 Terasoluna 에 최신버전이 내장되어 있어서 버전을 지정하지 않았었음. 아마 2.10.x 버전인듯 –> </dependency>   2. ehcache.xml <?xml version=”1.0″ encoding=”UTF-8″?> <ehcache xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”http://ehcache.org/ehcache.xsd” updateCheck=”false”> <!– * 속성 설명 (출처: https://javacan.tistory.com/entry/133) – maxElementsInMemory: 메모리에 저장될 수 있는 객체의 최대 개수 (필수) – eternal: 이 값이 true이면 timeout 관련 설정은… Read More »

Spring 파일 다운로드(file download)시 사용하는 View 샘플 코드

By | 9월 5, 2019

* View 정의 /** * 파일 다운로드시 Controller 에서 return 할 목적으로 생성한 view * * @author STEVE */ @Slf4j @Component(“fileDownloadView”) public class FileDownloadView extends AbstractView { private FileInputStream fin = null; private BufferedInputStream bis = null; private ServletOutputStream sout = null; private BufferedOutputStream bos = null; @SuppressWarnings(“rawtypes”) @Override protected void renderMergedOutputModel(Map params, HttpServletRequest request,… Read More »

[펌글] Spring MVC 사용시 Controller Method 없이 View Jsp를 매핑해 주도록 하는 설정 (mvc:view-controller)

By | 2월 28, 2017

– 출처: http://kdarkdev.tistory.com/105 –   별도의 모델이나 컨트롤러가 없이 URL요청이 왔을때 뷰로 연결만 해주는 경우는 굳이 컨트롤러가 필요없이 <mvc:view-controller>태그를 사용하면 URL과  뷰를 매핑해 줄 수 있습니다. 아래의 태그는 /common/gg 라는 URL을  요청 받았을때 gg라는 뷰 이름을 리턴 받게 됩니다 만약 InternalResourceViewResolver 에서 prefix/suffix가 각각 /WEB-INF/jsp/ 와 .jsp 라고 가정 한다면 결과적으로 /WEB-INF/jsp/gg.jsp 라는 jsp view를 찾게 됩니다.   <mvc:view-controller path=”/common/gg”… Read More »