2014-05-10 17 views
2
request.withFormat { 
      form { 
       redirect humanInstance 
       //Explain : old grails redirect like redirect(action: "show", id: humanInstance.id) 
       //but in 2.3.0 by redirect humanInstance this statement i saw it goes to def show(Human humanInstance) action 
       //Q1: how it understand that it has to redirect def show(Human humanInstance) action ? 
       //cause here so many methods which receives humanInstance 
       //Q2: And where it get processed ? 
      } 
      '*' { 
       respond humanInstance, [status: CREATED] 
      } 
      //Explain : I tested it that in the above {works for normalCall}'*'{works for restCall} 
      //Q3: What is '*' operator do here what it's name? 
     }

답변

2

'*'는 다른 블록이 해당 블록과 일치하지 않을 때 실행해야하는 코드 블록과 관련된 종류의 catch-all입니다. 수락 헤더. 다음을 참조하십시오 ...

request.withFormat { 
    xml { 
     // execute this if the request content type is xml 
    } 
    json { 
     // execute this if the request content type is json 
    } 
    '*' { 
     // execute this if neither of the other 2 matched the request's content type 
    } 
} 

구성한 MIME 유형을 포함하여이 문제를 이해하고 싶을 것입니다. 공식 사용자 가이드의 Content Negotiation 섹션을 http://grails.org/doc/2.3.x/guide/theWebLayer.html#contentNegotiation으로보아야합니다.

도움이되기를 바랍니다.

UPDATE :

당신이 (someDomainClassInstance)를 재 호출하면 https://github.com/grails/grails-core/blob/v2.3.8/grails-web/src/main/groovy/org/codehaus/groovy/grails/web/mapping/DefaultLinkGenerator.groovy#L175를 호출 https://github.com/grails/grails-core/blob/v2.3.8/grails-plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/web/metaclass/RedirectDynamicMethod.java#L160

호출 https://github.com/grails/grails-core/blob/v2.3.8/grails-plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/plugins/web/api/ControllersApi.java#L248

호출 https://github.com/grails/grails-core/blob/v2.3.8/grails-plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/plugins/web/api/ControllersApi.java#L270

에서 끝낸다.

이 시점에서 "method"의 값은 "GET_ID"입니다. GET_ID와 연결된 https://github.com/grails/grails-core/blob/v2.3.8/grails-web/src/main/groovy/org/codehaus/groovy/grails/web/mapping/DefaultLinkGenerator.groovy#L56의 값은 "show"이며 이는 show 메소드로 리디렉션 할 것을 지시합니다.

+0

감사합니다. 제프, 제 3의 좋은 대답은 대답 할 수 있었습니까? 대답 –

+0

답변이 너무 길어서이 답변에 답을 추가했습니다. 나는 몇 가지 질문을 보았고 몇 가지 질문을 하나의 게시물에 쌓기 때문에 대부분 답답하고 일관성이없는 부분은 비 일관적인 부분에 의해 불필요하게 복잡해 지므로 실제로해야하는 것보다 더 많은 노력이 필요합니다 도움이되는 정보를 제공합니다. 서로 조화를 이루지 않고 더 단순하게 지키면 질문에 답하기가 더 쉬울 것입니다. –

+0

두 번째 답변을 삭제하고 그 내용을 이미 수락 된 첫 번째 답변에 붙여 넣었습니다. 나는이 문제를보다 쉽게 ​​보게 될 것이라고 생각합니다. –

관련 문제