温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

springMVC传递参数内有list的提交

发布时间:2020-07-20 17:31:58 来源:网络 阅读:972 作者:王起飞 栏目:开发技术

最后使用ajax提交成功,下面是一些代码,后面如果有时间再完善。

ajax:

   function test(){
        $.ajax({
            type: "POST",
            url: "test2",
            contentType:"application/json",
            data: '{"propTest":"test","list":[{"prop1":"a"},{"prop1":"b"}]}',
            dataType: "json",
            success: function(data){
                console.log(data);
            }
        });
    }

controller:

    @ResponseBody
    @RequestMapping(value="/test2",method=RequestMethod.POST)
    public String hello2(@RequestBody TestList test){
        System.out.println(test);
        //value="/hello/{id}",
        //@PathVariable(value="id") Integer id,
        //@RequestParam(value="username") String username
        //@CookieValue
        return testBiz.getTest(1L);
    }

spring配置:

    <bean id="mappingJacksonHttpMessageConverter"
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
                <value>application/json;charset=UTF-8</value>    
            </list>
        </property>
    </bean>

bean信息:

public class TestList {
    private String propTest;
    public String getPropTest() {
        return propTest;
    }

    public void setPropTest(String propTest) {
        this.propTest = propTest;
    }

    private List<TestInner> list;

    public List<TestInner> getList() {
        return list;
    }

    public void setList(List<TestInner> list) {
        this.list = list;
    }
    
}


public class TestInner {
    private String prop1;

    public String getProp1() {
        return prop1;
    }

    public void setProp1(String prop1) {
        this.prop1 = prop1;
    }
}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI