Spring MVC(26)
-
Spring MVC - JSR-303 어노테이션 정리
JSR-303 - JSR-303 어노테이션은 빈 객체에 주입되는 값의 유효성 검사를 하기 위해 제공되는 어노테이션이다. ▪@AssertTrue : true가 아닌 값이 들어오면 오류 ▪@AssertFalse : false가 아닌 값이 들어오면 오류 ▪@Max(값) : 값보다 큰 값이 들어오면 오류 ▪@Min(값) : 값보다 작은 값이 들어오면 오류 ▪@DecimalMax(value=값, inclusive=true/false) : 값보다 작거나 같은 값이 들어와야 한다. Inclusive가 false면 값은 포함하지 않기 때문에 작은 값이 들어와야 한다. 생략하면 true ▪@DecimalMin(value=값, inclusive=true/false) : 값보다 크거나 같은 값이 들어와야 한다. Inclus..
2020.09.19 -
Spring MVC - 유효성 검사(@Valid,JSR-303)
JSR-303 - Spring MVC는 JSR-303 규격의 유효성 검사 라이브러리를 사용할 수 있다. - Bean에 데이터가 입력될 때 어떤 검사를 할 것인지 어노테이션으로 지정하고 지정된 어노테이션의 조건에 맞지 않으면 개발자에게 입력값에 오류가 있다는 정보를 전달한다. - 개발자는 이를 통해 유효성 검사를 진행할 수 있다. 1. Pom.xml에 라이브러리 추가 아래 사이트에서 validation maven 코드를 복사하여 붙여 넣는다. mvnrepository.com/artifact/javax.validation/validation-api Maven Repository: javax.validation » validation-api mvnrepository.com Hibernate Validator ..
2020.09.17 -
Spring MVC - Message
Message - Properties 파일을 Message로 등록하면 이 데이터는 JSP에서도 사용할 수 있다. - Properties 파일을 Message로 등록하면 다국어 처리가 가능하다. MessageSource - MessageSource 객체를 이용해 properties 파일을 등록해주면 Message로 등록할 수 있다. - 여기에서는 일정 시간마다 한번씩 갱신되는 ReloadableResourceBundleMessageSource를 사용한다. Java 세팅 Java에서 Message를 사용하기 위해 ServletAppcontext에 다음 메소드를 추가한다. //Properties 파일을 Message로 등록한다. @Bean public ReloadableResourceBundleMessageS..
2020.09.16 -
Spring MVC - Properties
Properties - 애플리케이션을 개발할 때 프로그램 실행 중 절대 변하지 않는 값들이 있을 수 있다. - Spring MVC에서는 이러한 값들을 properties 파일에 작성하고 이를 가져다 사용할 수 있도록 제공되고 있다. Propery Editor - Properties 파일에 한글을 작성하면 유니코드 형식의 문자열로 변경된다. - 이는 Property Editor 설치로 해결할 수 있다. - http://propedit.sourceforge.jp/eclipse/updates Downloading File /eclipse/updates - Properties Editor - OSDN Free download page for Project Properties Editor's updates.Thi..
2020.09.15 -
Spring MVC - Cookie
Spring에서의 쿠키 사용은 Servlet과 같다. 하지만 @CookieValue를 통해서 받아오는 동작을 쉽게 처리 가능하다. @Controller public class TestController { @GetMapping("/cookieIn") public String cookieIn(HttpServletResponse response) { try { Cookie cookie = new Cookie("cookie1","문자열1"); Cookie cookie2 = new Cookie("cookie2","문자열2"); cookie.setMaxAge(365*24*60*60); cookie2.setMaxAge(365*24*60*60); response.addCookie(cookie); response.ad..
2020.09.14 -
Spring MVC - ApplicationScope
ApplicationScope - 서버가 실행되고 종료되기까지의 생명주기를 갖는다. ApplicationScope는 request 객체에서 가져와서 사용해야 한다. 아래와 같이 사용을 원하는 곳에서 request 객체를 매개변수로 받아와 application 객체를 받아온다. @Controller public class TestController { @GetMapping("/test1") public String test1(HttpServletRequest request) { ServletContext application = request.getServletContext(); application.setAttribute("data1","문자열1"); return "test1"; } @GetMapping..
2020.09.14