Spring data rest bulk insert (대량입력)
Spring Data Rest 는 편하게 RESTful API 를 제공합니다
그러나 데이터를 입력할 때 1건씩밖에 입력을 못하고 커넥션을 다시 호출해야 하죠
이걸 기본 로직을 커스터마이징 해서 처리합니다
로컬에 패키지 및 클래스를 복사해서 생성해야 하구요
org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter class
204 line convert
@Override
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
HttpInputMessage inputMessage2 = new HttpInputMessage(){
HttpInputMessage httpInputMessage;
byte[] b;
public HttpInputMessage setHttpInputMessage(HttpInputMessage httpInputMessage) throws IOException {
this.httpInputMessage = httpInputMessage;
b = IOUtils.toByteArray(inputMessage.getBody());
return this;
}
@Override
public HttpHeaders getHeaders() {
return httpInputMessage.getHeaders();
}
@Override
public InputStream getBody() throws IOException {
return new ByteArrayInputStream(b);
}
}.setHttpInputMessage(inputMessage);
// 20160624 한순모 커스터마이징 bulk insert 를 지원하도록..
try {
JavaType javaType = getJavaType(clazz, null);
return readJavaType(javaType, inputMessage2);
} catch(Exception e){
// javaType = getJavaType(CashierSettlementEntity[].class, null)
JavaType javaType = getJavaType(Array.newInstance(clazz, 1).getClass(), null);
return readJavaType(javaType, inputMessage2);
}
}
org.springframework.data.rest.webmvc.RepositoryEntityController
269 line convert
@ResponseBody
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.POST)
public ResponseEntity<ResourceSupport> postCollectionResource(RootResourceInformation resourceInformation,
PersistentEntityResource payload, PersistentEntityResourceAssembler assembler,
@RequestHeader(value = ACCEPT_HEADER, required = false) String acceptHeader)
throws HttpRequestMethodNotSupportedException {
resourceInformation.verifySupportedMethod(HttpMethod.POST, ResourceType.COLLECTION);
Object obj = payload.getContent();
if(obj.getClass().isArray()) {
ResponseEntity<ResourceSupport> rtn = null;
for(Object d : (Object[])obj){
rtn = createAndReturn(d, resourceInformation.getInvoker(), assembler,
config.returnBodyOnCreate(acceptHeader));
}
return rtn;
}else
return createAndReturn(payload.getContent(), resourceInformation.getInvoker(), assembler,
config.returnBodyOnCreate(acceptHeader));
}
REST API CALL
POST METHOD
JSON DATA Example
[{
"sno": 2,
"amt": 1,
"updateDate": null,
"regDate": "2016-06-21T14:20:28.000+0000"
},
{
"sno": 1,
"amt": 1,
"updateDate": null,
"regDate": "2016-06-21T14:20:28.000+0000"
}]
음 시간될때 스택트레이스에도 남겨야겟네요..
'개발' 카테고리의 다른 글
IntelliJ 에서 Spring Boot + Mybatis + log4jdbc 한글깨지는 현상 (1) | 2016.07.19 |
---|---|
삽질을 줄이자 키보드 마우스매크로 소개 Mouse Recorder Premium 1.0.46 (0) | 2016.06.27 |
전자정부프레임워크 올인원 게시판 컴포넌트 에러 (0) | 2016.06.22 |
전자정부프레임워크 우편번호 다음 open api 연계 (0) | 2016.06.20 |
[개발] sitemesh + velocity 한글 깨지는 현상 (0) | 2012.04.22 |