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
}, ] ]
});
});
这是运行的截图