아래와 같은 VO 클래스가 있다고 하자.

 

public class SearchDataVO {

 private String searchUserId;
 private String searchUserName;
 
    public String getSearchUserId() {
        return searchUserId;
    }

    public void setSearchUserId(String searchUserId) {
        this.searchUserId = searchUserId;
    }

    public String getSearchUserName() {
        return searchUserName;
    }

    public void setSearchUserName(String searchUserName) {
        this.searchUserName = searchUserName;
    }

}

 

콘솔에 SearchDataVO 값을 찍기위해 다음과 같이 입력하면

 

System.out.println("console : " + SearchDataVO);

 

결과는 아래와 같이 이상하게 찍힌다.

 

 

ToStringBuilder 클래스의 reflectionToString 함수를 다음과 같이 추가하여 사용하면

    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }

 

결과는 다음과 같이 보다 쉽게 VO 변수들을 json형태나 multi형식으로 볼 수 있다.

 

test.SearchDataVO@2f032f9c[
  searchUserId=superman
  searchUserName=슈퍼맨
]

 

ToStringStyle.MULTI_LINE_STYLE 이외에 아래에서 맞는 형태를 찾아서 적용하면 된다.

 

ToStringStyle.DEFAULT_STYLE

ToStringStyle.MULTI_LINE_STYLE
ToStringStyle.NO_FIELD_NAMES_STYLE
ToStringStyle.SHORT_PREFIX_STYLE
ToStringStyle.SIMPLE_STYLE
ToStringStyle.NO_CLASS_NAME_STYLE
ToStringStyle.JSON_STYLE

반응형

전자정부프레임워크 트랜잭션 파일 설정(context-transaction.xml)

 

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

 <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="egov.dataSource"/>
 </bean>
  
 <tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes> 
        <tx:method name="*" rollback-for="Exception" propagation="REQUIRED"/>
    </tx:attributes>
 </tx:advice>
   
 <aop:config>
  <aop:pointcut id="requiredTx" expression="execution(* com.testproject..impl.*Impl.*(..))"/>
  <aop:advisor advice-ref="txAdvice" pointcut-ref="requiredTx" />
 </aop:config>

</beans>

반응형

RedirectAttributes 클래스를 사용하면 리다이렉트시 주소표시줄에 덕지덕지 붙여서 안넘기고 깔끔하게 넘기는것이 가능

 

아래와 같이 addFlashAttribute 속성을 사용하여 VO나 파라미터정보 등을 리다이렉트화면으로 전송함.

 

- 주소표시줄에 표시는 되지않으나 post방식이 아니고 get방식임.

- addFlashAttribute를 사용하여 세션에 잠시 저장한 후 리다이렉트화면으로 넘기고 소멸함.

 

redirectAttributes.addFlashAttribute("SearchVO", searchVO);

 

return "redirect:/dataInfo/reqstDataInfo.do?menuId="+searchVO.getMenuId();

 

반응형

+ Recent posts