Spring MVC --- 异步请求

1. web 

<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
    </script>
    <script>
        function fun1() {
            $.ajax({
                type:"post",
                url:"getJson.action",
                data:'{"name":"张三","money":"200"}',
                contentType:"application/json",
                success:function (data) {
                    alert(data);
                }
            });
        }
    </script>
<a href="/abc/findById.action?id=2">response---json</a>
<button onclick="fun1()">request---json</button>

2. Controller

 1     @RequestMapping("findById.action")
 2     public  @ResponseBody Account findById(Integer id){
 3         return accountService.findById(id);
 4     }
 5 
 6     @RequestMapping("getJson.action")
 7     @ResponseBody
 8     public  String getJson(@RequestBody Account account){
 9         return account.toString();
10     }

3. pom.xml

1     <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
2     <dependency>
3       <groupId>com.fasterxml.jackson.core</groupId>
4       <artifactId>jackson-databind</artifactId>
5       <version>2.10.1</version>
6     </dependency>
原文地址:https://www.cnblogs.com/iscurry/p/11884792.html