2012-01-31 2 views
1

안녕하세요, 내 첫 번째 RESTful 응용 프로그램을 개발 중입니다 ... 그 중 일부는 같은 내부 오류가 발생했습니다 method.its 저장하려면 게시 요청을 매핑했습니다. 내부 오류 .. 모든 서버 하나는 제가 게시물을 사용하여 데이터를 저장하는 방법을 사용하는 방법을 간략히하는 데 도움주세요 게시물 요청 ...? 다음과 같이 는REST 게시 통화를 통해 응용 프로그램에 대한 데이터를 저장하는 방법

class ImageProperties { 
    static hasMany={categories:Categories} 
    String name 
    String place 
    String description 
    String path 
    String category 
    Categories categories 
} 
+0

Plese 사용하는 코드를 게시하고 더 자세히 오류를 설명합니다. –

+0

의견에 아니오! 위의 게시물을 편집하고 코드를 추가 한 다음 4 칸으로 들여 쓰세요. –

+0

줄 바꿈에 '
'이 (가) 필요하지 않습니다. 그냥 그대로 코드를 게시하고 4 줄 간격으로 모든 줄을 들여 쓰기하십시오. –

답변

0

안녕 오랜 시행 착오 방법 후 내가 답을 찾았 ..이 많은 사용자에게 도움이 될 것입니다 희망 ...

def save = { 
    def xml = request.XML 
    def post = new ImageProperties() 
    post.name = xml.name.text() 
    post.place = xml.place.text() 
    post.path = xml.path.text() 
    post.description = xml.description.text() 
    post.category = xml.category.text() 
    post.categories = Categories.get([email protected]()) 
    def markup 

    if (post.save()) { 
     markup = { 
      status("OK") 
     } 
    } else { 
      markup = { 
      status("FAIL") 
     } 
    } 
    render contentType: "text/xml; charset=utf-8", 
    markup 
} 
0

당신이 당신의 ImageProperties

def post = new ImageProperties() 
post.content = xml.content.text() 
의 예상 content 속성에 게시 된 데이터를 할당하는 ... ... 다음과 같은 방법이

def save = { 
    def xml = request.XML 
    def post = new ImageProperties() 
    post.content = xml.content.text() 
    def markup 
    if (post.save()) { markup = { status("OK") } } 
    else { markup = { status("FAIL") } } 
    render contentType: "text/xml; charset=utf-8", markup } } 

및 ImageProperties 클래스를 저장 내

귀하의 법인은 어디에서 해당 자산입니까?

class ImageProperties { 
    static hasMany={categories:Categories} 
    String name 
    String place 
    String description 
    String path 
    String category 
    Categories categories 
} 

업데이트 :

def post = new ImageProperties(xml.content) 

이 섹션 REST와 Grails의 설명서의 Data Binding에 대한 자세한 내용보기 : 당신은 단순히 모든 속성을 채우려면 도메인 클래스 생성자를 사용할 수 있습니다.

+0

미안 해요 귀하의 질문에 .. 게시 된 데이터의 내용을 post.content = xml.content.text()의 도움으로 ImageProperties 클래스에 직접 저장하려고합니다 ... 가능합니까? 어떻게하면 안되지 .. – Shagul

+0

"new ImageProperties (xml.content)"와 같은 도메인 클래스 생성자를 사용할 수 있습니다. - anwer를 확장했습니다. – david

관련 문제