Struts 2 및 REST 플러그인을 사용하고 있습니다. Struts 2의 유효성 검사는 ClassName-actionAlias-validation.xml입니다. 그러나 REST 플러그인을 사용하면 동작 별칭은 항상 /입니다. 예를 들어 OrdersController ->/orders -> OrdersController-orders-validation.xml입니다. REST 메서드에 따라 다른 유효성 검사를 어떻게받을 수 있습니까? 주로 update() 메서드와 create() 메서드에 대해 한 가지 유형의 유효성 검사가 필요합니다.Struts 2 REST 및 유효성 검사
1
A
답변
1
using annotations for the validations을 고려하셨습니까? 따라서 올바른 방법으로 연결하는 것이 더 간단합니다.
0
아, 저는 특정 방법에 대해 주석 기반 유효성 검사를 사용할 수 있는지 여부를 몰랐습니다. Struts를 그렇게 많이 사용하지 않았습니다. 감사!
그러나 다른 메소드 (validateAnnotatedMethodOnly가 true 여야 함)에서 다른 유효성 검증을 허용하도록 struts.xml을 수정해야했습니다. 모양은 다음과 같습니다.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.convention.action.suffix" value="Controller" />
<constant name="struts.convention.action.mapAllMatches" value="true" />
<!-- Set to "default" instead of "rest-default" -->
<constant name="struts.convention.default.parent.package"
value="default" />
<constant name="struts.convention.package.locators" value="rest" />
<package name="default" extends="rest-default">
<interceptors>
<interceptor-stack name="restDefaultStack">
<interceptor-ref name="exception" />
<interceptor-ref name="alias" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="messages">
<param name="operationMode">AUTOMATIC</param>
</interceptor-ref>
<interceptor-ref name="prepare" />
<interceptor-ref name="i18n" />
<interceptor-ref name="chain" />
<interceptor-ref name="debugging" />
<interceptor-ref name="profiling" />
<interceptor-ref name="actionMappingParams" />
<interceptor-ref name="scopedModelDriven" />
<interceptor-ref name="modelDriven">
<param name="refreshModelBeforeResult">true</param>
</interceptor-ref>
<interceptor-ref name="fileUpload" />
<interceptor-ref name="checkbox" />
<interceptor-ref name="staticParams" />
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*</param>
</interceptor-ref>
<interceptor-ref name="rest" />
<interceptor-ref name="conversionError" />
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse,index</param>
<!-- Modified! -->
<param name="validateAnnotatedMethodOnly">true</param>
</interceptor-ref>
<interceptor-ref name="restWorkflow">
<param name="excludeMethods">input,back,cancel,browse,index</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
</package>
</struts>