html怎么获取后端数据

前端html携带id字段超链接到后端的方法 处理后返回一个对象并控制跳转到另一个页面,在jsp中可以用el表达式接受这个对象,在HTML中怎么接受?

第一个页面:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>账户列表页面</title>
    <script type="text/javascript" src="js/jquery-3.4.1.js"></script>
    <script type="text/javascript">
        $(function () {
            $.get("/arAccount/findAll",function (data) {
                console.log(data)
                for (var n=0;n <data.length;n++) {
                    var str ="<tr ><td>"+data[n].id+"</td><td>"+data[n].username+"</td><td>"+data[n].money+"</td><td><a href='/arAccount/findOne?id="+data[n].id+"'>查询</a></td></tr>"
                    $("table").append(str);
                }
            },"json");
        });
    </script>
</head>
<body>
<table>
    <tr>
        <td>id</td>
        <td>用户名</td>
        <td>资金</td>
        <td>查询</td>
    </tr>

    <!--<tr class="hehe"></tr>-->
</table>
</body>
</html>

方法

package com.xpc.controller;

import com.alibaba.fastjson.JSON;
import com.xpc.pojo.ArAccount;
import com.xpc.service.ArAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/arAccount")
public class ArAccountController {
    @Autowired
    private ArAccountService arAccountService;
    @RequestMapping("/findAll")
    @ResponseBody
    public String findAll(){
        List<ArAccount> list = arAccountService.findAll();
        return JSON.toJSONString(list);
    }
    @RequestMapping("/findOne")
    public ModelAndView findOne(Integer id,ModelAndView modelAndView){
        ArAccount arAccount = arAccountService.findOne(id);
        modelAndView.addObject("arAccount",arAccount);
        modelAndView.setViewName("findOne.html");
        return modelAndView;
    }

}

如何在第二个html中进行数据接受

求教!

可以说的具体一点 不要说用ajax,我要的是怎么用,具体的操作流程.

我这方面特别懵逼 大佬最好说的详细一点

不胜感激

猜你喜欢

转载自blog.csdn.net/Riding_ants/article/details/106671649
今日推荐