Grails 2.5.0 management object interface after accessing the request. JSON in the filter

In the Grails 2.5.0 controller action method, it seems that the properties in the HTTP JSON object will not be used to bind the command object if the filter has been accessed request.JSON.

Why? It makes no sense to me.

Is it possible to allow use request.JSONin the filter, as well as to bind the command object?

+4
source share
1 answer

, Grails, . request.JSON , . , Grails .

, , , .

http://grails.imtqy.com/grails-doc/2.5.0/guide/theWebLayer.html#dataBinding:

, . . , ( , - .JSON), .

, , . - . params session ( ), :

MyFilters.groovy

class MyFilters {

    def filters = {
        foo(/* your filter */) {
            before = {
                // Your checks
                Map requestData = request.JSON as Map
                session.requestData = requestData
                return true
            }
        }
    }
}

, , :

class MyController {

    def fooAction(MyCommandObject object) {
    }
}

- :

class MyController {

    def fooAction() {
        MyCommandObject object = new MyCommandObject(session.requestData)
        // Clear from session to clear up the memory
        session.requestData = null
    }
}

. , , , . @JoshuaMoore Http Servlet POST .

+4

Source: https://habr.com/ru/post/1599591/


All Articles