SpringMVC发送请求的一个逻辑错误

今天在写代码的时候犯了一个基本的逻辑错误,细细想来还是基础不扎实。
需求:发送请求http://localhost:9555/mavenweb/customer/vueCustomerListPage.do时,会进入到页面index.html,并且显示数据库中的数据。
但是我只写了一个方法,然后后台可以打印出数据,但是前端怎么也接受不到数据。其实这里进入了一个逻辑的死循环,我发送该请求,然后得到了数据,但是返回的还是index该页面。所以前端就加载该页面,然后一加载该页面,页面就会发送请求接受数据,但是返回的还是该页面。。。于是一个死循环就诞生了。说白了,就是只有一个请求。请求和得到的响应永远都是该页面。

@RequestMapping("/customer/vueCustomerList")
    public String vueCustomerList(Model model){
        List<Customer> customerList = customerService.getCustomerList();

        model.addAttribute("customerList", customerList);

        System.out.println("list集合"+customerList);

       return "index";


    }

解决方法:发送一个请求,该请求只返回一个页面,然后一加载该页面,页面就会发送另一个请求到后台请求数据,后台返回json格式的数据,渲染页面。数据显示成功。

   @RequestMapping("/customer/vueCustomerListPage")
    public String vueCustomerPage(){
        return "VueCustomerList";
    }

    @RequestMapping("/customer/vueCustomerList")
    @ResponseBody
    public List<Customer> vueCustomerList(Model model){
        List<Customer> customerList = customerService.getCustomerList();

        model.addAttribute("customerList", customerList);

        System.out.println("list集合"+customerList);

       return customerList;

       // return customerList;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值