참조 : http://stackoverflow.com/questions/15774475/how-to-send-a-getforobject-request-with-parameters-spring-mvc


RestTemplate 객체를 사용하여 url 주소를 호출과 동시에 파라미터를 전달 해줄 경우 Uri 객체에 파라미터를 넣어 코드를 작성하여야한다.


Uri targetUrl= UriComponentsBuilder.fromUriString(BASE_URL)
    .path("/android/played.json")
    .queryParam("name", nome)
    .build()
    .toUri();
return restTemplate.getForObject(targetUrl, Name.class);


설정

트랙백

댓글

ContentNegotiatingViewResolver

 

user.html, user.json, user.xml .... 확장자에 따라서 보여주는 페이지를 바꿀 수 있고,

 

ResponseBody

반환하는 형태를 명시를 해서 반환 하는 형태이다.

설정

트랙백

댓글

기존에 다른 방식들도 있지만 이게 제일로 깔금한 우리 여우한테 실험해 본 결과 완벽함.

출처: http://linuxism.tistory.com/720

the default charset of @ResponseBody is iso-8859-1, how to change to utf8.


@RequestMapping(value = "/path", produces="text/plain;charset=UTF-8")

public @ResponseBody String handlePath() {

    .....

}


produces="text/plain;charset=UTF-8"를 사용하여 응답 페이지에 대한 UTF-8 인코딩이 가능하여 한글 깨짐을 방지 할 수 있음.



우리 fox 가 변했쪄요.
    @RequestMapping(value="/fox", produces="text/html;charset=UTF-8")
    @ResponseBody
    public String tiger() {
        return "<html><head></head><body><h1>" + "Lion" + "<br>호랑이" + "</h1></body></html>";
    }

 

설정

트랙백

댓글

Validate 종류들

S/Spring 2014. 6. 21. 12:53

5.7.4.3 Configuring a JSR-303 Validator for use by Spring MVC

With JSR-303, a single javax.validation.Validator instance typically validates all model objects that declare validation constraints. To configure a JSR-303-backed Validator with Spring MVC, simply add a JSR-303 Provider, such as Hibernate Validator, to your classpath. Spring MVC will detect it and automatically enable JSR-303 support across all Controllers.

The Spring MVC configuration required to enable JSR-303 support is shown below:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <!-- JSR-303 support will be detected on classpath and enabled automatically -->
    <mvc:annotation-driven/>
    
</beans>

				

With this minimal configuration, anytime a @Valid @Controller input is encountered, it will be validated by the JSR-303 provider. JSR-303, in turn, will enforce any constraints declared against the input. Any ConstaintViolations will automatically be exposed as errors in the BindingResult renderable by standard Spring MVC form tags.

 

참조 : http://docs.spring.io/spring/docs/3.0.0.RC3/reference/html/ch05s07.html

 

javax.validation.constraints.Digits

  • javax.validation.constraints.Min
  • javax.validation.constraints.Max
  • javax.validation.constraints.NotNull
  • javax.validation.constraints.DecimalMax
  • javax.validation.constraints.DecimalMin
  • javax.validation.constraints.Pattern
  • javax.validation.constraints.Null
  • javax.validation.constraints.Size
  •  

    org.hibernate.validator.constraints.URL

    org.hibernate.validator.constraints.NotEmpty

    org.hibernate.validator.constraints.NotBlank

    org.hibernate.validator.constraints.Length

    org.hibernate.validator.constraints.Email

    org.hibernate.validator.constraints.CreditCardNumber

     

     

     

    설정

    트랙백

    댓글

    Request processing failed; nested exception is org.apache.tiles.definition.DefinitionsFactoryException: I/O Error reading definitions.] with root cause

     

    이 에러의 대처법은 아직은 잘 모르겠지만 혹시 이 에러가 뜬다면

    1. 인터넷 연결

    2. Tiles

    3. Mybatis 매퍼 xml 부분 논리적 오류거나 띄어쓰기 등등..

    4. Spring-Security

    5. dispatcher-servlet.xml 부분 Controller??

     

    1, 2, 3, 4일 경우도 있었던거 같다.

    5번은 명확하지 않아서 이런 순으로 점검을 해보는 것이 좋을 거 같다.

     

    3번 같은 경우 왠만하면 ctrl + shift + f 단축키 정렬을 mapper.xml 부분에 하지 말하야한다.

    query 문이 난잡하게 되서 에러를 유발할 수 있을 수 있다.

     

     

    설정

    트랙백

    댓글

    Here’s another handy stuff I found on Spring MVC, if you have an unknown number of elements on your form (say a fruit basket), you can bind them into a List with @RequestParam annotation.

    Let’s say this is our form:
    spring-bind-list

    Each text input has the same name fruits:

    1
    2
    3
    4
    5
    6
    <form method="post">
      Fruit 1: <input type="text" name="fruits"/><br/>
      Fruit 2: <input type="text" name="fruits"/><br/>
      Fruit 3: <input type="text" name="fruits"/><br/>
      <input type="submit"/>
    </form>

    On your controller’s handler method, you can obtain the list of all fruit names by binding it like this:

    1
    2
    3
    4
    @RequestMapping(value = "/", method = RequestMethod.POST)
    public String addFruits(@RequestParam("fruits") List<String> fruits) {
      // ...
    }

    The order of fruit names added to the list will be the same as the order of your form text inputs.

     

    참조 : http://gerrydevstory.com/2013/11/14/binding-a-list-request-parameter-on-spring-mvc/

    설정

    트랙백

    댓글

     <form:form class="form-horizontal" action="${ boardType }/article/write.do" method="post" commandName="articleView" >
      <div class="form-group">
       <label for="inputTitle" class="col-md-1 control-label">제목 : </label>
       <div class="col-md-11">
        <form:input path="title" class="title form-control"
         id="inputTitle" placeholder="제목" />
       </div>
      </div>  
      <div class="form-group">
       <form:textarea id="editor" class="ckeditor form-control" path="contentView" />
      </div>
      <div class="form-group">
       <input class="btn" type="submit" value="확인" /> <a
        href="${ boardType }/board.do?${ pagination }&pg=${ pagination.currentPage}"
        class="btn">취소</a>
      </div>
      
      <form:hidden path="writerId" />
      <form:hidden path="boardCodeId" />
      <form:hidden path="authId"/>
     </form:form>

     

    이렇게 form 태그가 있다

    여기서 에러가 발생해서 <!-- -->로 주석 처리하면서 에러를 찾으면 효과가 없다.

    왜냐 spring form 태그 라이브러리가 <!-- --> 주석 처리 안 까지 처리를 하기때문에 에러가 계속 발생하게 되므로 에러 부분을 찾으려면 해당 폼 태그 부분을 지우면서 확인하는 수 밖에 없다.

    설정

    트랙백

    댓글

     

     <http auto-config="true">
      <intercept-url pattern="/**" access="ROLE_USER" />
      </http>

     <authentication-manager>


      <authentication-provider>
       <jdbc-user-service data-source-ref="dataSource"
        users-by-username-query="select username, password, enabled from [dbo].[User] where username = ?"
        authorities-by-username-query="select a.username, b.authority from [dbo].[User] a join [dbo].[UserSep] b on a.username = b.username where a.username = ?"
       />
      </authentication-provider>
     </authentication-manager>
    </beans:beans>

    char(30) 했을 경우, 30글자 다 차지하기 때문에 조건식에서 일치 인식이 맞지 않을 수 있다.

    그러므로 varchar(30)으로 하던가 해야지 쿼리문 인식이 원활히 진행된다.

    설정

    트랙백

    댓글

    Looks like your "Deployment Assembly" is missing the Maven Dependencies being added to the packaging structure of your project. The way this should look is:

    enter image description here

    The way to add that in is:
    - click on Add
    - select Java Build Path Entries
    - select Maven Dependencies
    - Finish

    That should add your Maven Dependencies into WEB-INF/lib. In case your project structure is not standard, you can also edit that path by double-clicking inside your Deploy Path column - in this case, on WEB-INF/lib.

    Hope that helps.

    참조 : http://stackoverflow.com/questions/20718566/maven-dependencies-not-being-added-to-web-inf-lib

    설정

    트랙백

    댓글

    AOP 용어

    S/Spring 2014. 3. 16. 22:22

    1. 결합점(Joint Point)

    인스턴스의 생성시점, 메소드를 호출하는 시점, Exception이 발생하는 시점과 같이 애플리케이션이 실행될 때, 특정 작업이 실행되는 시점을 의미한다. (Aspect를 플러그인 할 수 있는 애플리케이션의 실행 지점)

     

    2. 교차점(Pointcut)

    충고가 어떤 결합점에 적용되어야 하는지 정의. 명시적인 클래스의 이름, 메소드의 이름이나 클래스나 메소드의 이름과 패턴이 일치하는 결합점을 지정 가능토록 해준다.(스프링 설정 파일 안에서 XML로 작성)

     

    3. 충고(Advice)

    충고는 교차점에서 지정한 결합점에서 실행(삽입) 되어야하는 코드이다. Aspect의 실제 구현체

     

    4. 에스팩트(Aspect)

    에스팩트는 AOP의 중심단위, Advice와 Pointcut을 합친 것이다. 구현하고자 하는 횡단 관심사의 기능.

    애플리케이션의 모듈화 하고자 하는 부분

     

    5. 대상(target)

    충고를 받는 클래스를 대상(target)라고 한다. 대상은 여러분이 작성한 클래스는 물론, 별도의 기능을 추가하고자 하는 써드 파티클래스가 될 수 있다.

     

     

    설정

    트랙백

    댓글