springmvc中的RequestBody自动注入List, Map, String数据结构的数据

不说废话,直接上代码:

1. JS:

html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
xmlns="http://www.w3.org/1999/xhtml">

    
    

class="showmenu">
travel-web1



2. User-Bean

package com.bilibili.travel.model;

import com.bilibili.base.BaseEntity;

import java.util.List;
import java.util.Map;

/**
 * Created by bls on 16-4-30.
 */
public class User extends BaseEntity {

    private String name = null;
    private Map, Object> map = null;
    private List list = null;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Map, Object> getMap() {
        return map;
    }

    public void setMap(Map, Object> map) {
        this.map = map;
    }

    public List getList() {
        return list;
    }

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

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", map=" + map +
                ", list=" + list +
                '}';
    }
}


3. Controller



import com.bilibili.travel.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by bls on 16-4-30.
 */
@Controller
@RequestMapping(value = "/bb")
public class BBController extends BaseSpringController {

    @ResponseBody
    @RequestMapping(value = "/aj")
    public User addJson(@RequestBody User user){
        System.out.println(user);
        return user;
    }

}

以上,如果对你有帮助。请为我点赞,谢谢。


你可能感兴趣的:(Java,js,编程语言,前端)