2

I want to send js object to java controller and to receivce with @RequestParam anotation.

Javascript

(function(){

    var testVO = {
        member1 : 'hello',
        member2 : 'world'
    }
    $.ajax({
        url : 'myurl.do',
        type : 'get',
        dataType : 'json',
        data : JSON.stringify({
            testVO : testVO
        }),
        success : function(data)
        {
            console.log(data);
        },
        error : function(error)
        {
            console.log(error);
        }
    });
})();

Java Controller

@RequestMapping("myurl.do")
@ResponseBody
public Object test3(@RequestBody TestVO testVO)
{
    return testVO;
}

Java TestVO Class

public class TestVO
{
    private String member1;
    private String member2;

    public String getMember1()
    {
        return member1;
    }

    public void setMember1(String member1)
    {
        this.member1 = member1;
    }

    public String getMember2()
    {
        return member2;
    }

    public void setMember2(String member2)
    {
        this.member2 = member2;
    }

    public MMMooVO getMamamoo()
    {
        return mamamoo;
    }
}

I want to map js object to Java object. For example, js's testVO object to Java's TestVO object with annotation. How to set controller's annotation to map??

What is right in @RequestParam("testVO") and @RequestBody?? I'm confusing.... please help.

1 Answer 1

1

I you want to send data to server we would suggest to use POST not Get ajax request.

GET is mainly used to get data from server.

@RequestBody annotation maps the HttpRequest body to a transfer or domain object.

HTTP GET don't have request body it sends data in the header or URLparams

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.