Skip to content

Instantly share code, notes, and snippets.

View arahansa's full-sized avatar

arahansa arahansa

  • Seoul, South Korea
View GitHub Profile
@arahansa
arahansa / 01_테스트대상코드.java
Last active July 29, 2016 00:09
Spring MVC테스트에서 mocikto와 assertj 로 테스트해보는 연습을 하고 있습니다.
// 밸리데이션이나 이늄 세팅같은 부분은 AOP로 빠졌다.
@PostMapping("/{boardType}/form")
public String postCreate(
@Valid @ModelAttribute BoardArticle article,
BindingResult result,
@PathVariable BoardType boardType){
final BoardArticle save = boardArticleService.save(article);
log.debug("saved Article : {}", save);
return article.getBoardType().getRedirectionPage();
}
@arahansa
arahansa / Controller.java
Last active July 27, 2016 22:03
프로퍼티 에디터
@Inject
Provider<FakeDbUserPropertyEditor> fakeDbUserPropertyEditorProvider;
@InitBinder
public void initBinder(WebDataBinder dataBinder){
dataBinder.registerCustomEditor(Level.class, new LevelPropertyEditor());
// 커스텀 서비스를 넣어주는 방법
dataBinder.registerCustomEditor(int.class, "age", new MinMaxPropertyEditor(0, 200));
// 02. 모조 방법
@Bean
/*@Profile({"default", "test"})*/
public MessageSource messageSource() {
return messageSourcePrivate(seconds);
}
private ResourceBundleMessageSource messageSourcePrivate(int seconds){
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasenames("i18n/messages", "i18n/category" , "i18n/main", "i18n/intro", "i18n/customer");
@arahansa
arahansa / DTO.java
Last active July 26, 2016 19:38
커스텀 밸리데이션
@PasswordsNotEqual(
passwordFieldName = "password",
passwordVerificationFieldName = "passwordVerification"
)
@arahansa
arahansa / ArticlePageInfo.java
Last active May 11, 2016 17:04
예전에 잠깐 쓰던 페이지 도우미 4 JPA
package com.example.domain;
import java.util.Arrays;
import java.util.List;
import org.springframework.data.domain.Page;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Test
public void beanRegistryTest() throws Exception{
log.info("beanRegistryTest");
BeanDefinitionRegistry bdr = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("kerry.class", "org.springframework.beans.TestBean");
p.setProperty("kerry.age", "35");
(new PropertiesBeanDefinitionReader(bdr)).registerBeanDefinitions(p);
final BeanDefinition kerry = bdr.getBeanDefinition("kerry");
log.info("Kerry : {} ", kerry);
@arahansa
arahansa / Korean3byte.java
Created March 2, 2016 01:52
한글 3바이트 처리하는 자바처리
@Test
public void koreanCheck2() throws Exception {
String msg ="일이>삼사오육칠팔구십";
byte[] test = msg.getBytes("UTF-8");
System.out.println("총길이 :"+test.length);
int lastPosition = 0;
for(int i=0;i<20;i++){
int iChar = (int) test[i];
if ((iChar > 127) || (iChar < 0)) {
// 한글의 경우(2byte 통과처리)
@Aspect
public class LucyAspect4BoardArticle{
private static final Logger LOGGER = LoggerFactory.getLogger(LucyAspect4BoardArticle.class);
//TODO 이 부분은 좀 더 세련되게 바꿔야한다.
//@Pointcut("execution(* com.example.service.BoardArticleService.create(..))")
private void profileTarget() {
LOGGER.debug("컨트롤러 프로필 설정");
}

댓글달기 [post]

댓글 생성하는데 사용 합니다.

/comment [POST]

POST 요청은 댓글을 생성하는 것을 보여줍니다.

@arahansa
arahansa / build.gradle
Created December 31, 2015 17:06
restDocs 추가
dependencies {
testCompile "org.springframework.restdocs:spring-restdocs-mockmvc:$springRestdocsVersion"
}
plugins {
id "org.asciidoctor.convert" version "1.5.2"
}
ext {
snippetsDir = file('build/generated-snippets')