zachary280 2017-08-16 12:00 采纳率: 20%
浏览 809
已结题

spring mvc模式下为何controller无法与前台传输数据

spring mvc模式下做了一个web练习项目
这是欢迎界面的controller,能够正常运行

 package wxj.welcom.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class Welcom {
    @RequestMapping("")
    public String Create(Model model) {     
        return "showTable";
    }
}

这是功能的controller不能正常运行

 package wxj.table.controller;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import wxj.table.dto.TableInfo;
import wxj.table.service.TableInfoService;

@Controller
@RequestMapping("/showTable")
public class TableInfoController {
    @Resource
    TableInfoService tableInfoService;

    @RequestMapping("/showTable.do")
    @ResponseBody
    public Map<String, Object> showTable() {

        /*
         * Map<String, Object> map = new HashMap<String, Object>(); map=
         * tableInfoService.queryPageStaffByCondition(pageObj); return map;
         */
        List<TableInfo> result = new LinkedList<TableInfo>();
        TableInfo tableInfo;
        for (int i = 0; i < 10; i++) {
            tableInfo = new TableInfo();
            tableInfo.setUserId("1" + i);
            tableInfo.setPassword("123456");
            result.add(tableInfo);
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows", result);
        map.put("total", 10);
        return map;

    }

}

这是jsp文件

 $(document).ready(function() {
    // 用于显示表格
    $('#userTable').datagrid({
        url : '/showTable.do',      
        columns : [ [ {
            field : 'userId',
            title : '用户名',
            width : 50

        }, {
            field : 'password',
            title : '密码',
            width : 50
        }, ] ]
    });
    });

这是运行的截图
运行的截图

  • 写回答

6条回答 默认 最新

  • threenewbee 2017-08-17 00:55
    关注

    看下页面的相对路径是不是在根路径下,也就是/showTable.do是不是和你的页面地址一致,不行指定下完整路径

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘