1.1 环境准备

java环境:

  • jdk1.7.0_72
  • eclipse indigo
  • springmvc版本:spring3.2

 所需要的jar包:

  • 数据库驱动包:mysql5.1
  • mybatis的jar包
  • mybatis和spring整合包
  • log4j包
  • dbcp数据库连接池包
  • spring3.2所有jar包
  • jstl包

 2018-02遇到的坑:在html中,表单命名应该是:< form  name="itemForm".....>结果,我错写成了<form id="itemsForm".....>然后,balabala两个小时过去了。知识不牢固造成的。希望以后会牢记此坑(<form name="itemsForm"....>

遇到的坑标记下:
package cn.itcast.ssm.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView; import cn.itcast.ssm.po.ItemsCustom;
import cn.itcast.ssm.service.ItemsService; /**
遇到的坑标记下:如果在类的前面,使用@RequestMapping注解,指定了新的前缀,如:@RequestMapping("/items"),那么在页面访问页面时一定要加上去,如本例就是:localhost:8080/spring2018/items/queryItems.action
因为是直接拷的代码,没有详细看注释说明,在测试时,还一直按原地址:localhost:8080/spring2018/queryItems.action 访问,一直出错,原因找来找去整整折腾了10天,从放假前就找原因,一直找到春节初六上班,才明白;
*/
@Controller
//为了对url进行分类管理 ,可以在这里定义根路径,最终访问url是根路径+子路径
//比如:商品列表:/items/queryItems.action
@RequestMapping("/items")
public class ItemsController { @Autowired
private ItemsService itemsService; // 商品查询
@RequestMapping("/queryItems")
public ModelAndView queryItems(HttpServletRequest request) throws Exception {
//测试forward后request是否可以共享 System.out.println(request.getParameter("id")); // 调用service查找 数据库,查询商品列表
List<ItemsCustom> itemsList = itemsService.findItemsList(null); // 返回ModelAndView
ModelAndView modelAndView = new ModelAndView();
// 相当 于request的setAttribut,在jsp页面中通过itemsList取数据
modelAndView.addObject("itemsList", itemsList); // 指定视图
// 下边的路径,如果在视图解析器中配置jsp路径的前缀和jsp路径的后缀,修改为
// modelAndView.setViewName("/WEB-INF/jsp/items/itemsList.jsp");
// 上边的路径配置可以不在程序中指定jsp路径的前缀和jsp路径的后缀
modelAndView.setViewName("items/itemsList"); return modelAndView; } }

最新文章

  1. ios NSLayoutConstraint
  2. BZOJ4538 : [Hnoi2016]网络
  3. SpringMVC学习系列(7) 之 格式化显示
  4. 关于多线程与CRITICAL_SECTION的使用
  5. GO語言基礎教程:Hello world!
  6. table和div设置height:100%无效的完美解决方法
  7. No data in the view dba_hist_undostat (文档 ID 1558157.1)
  8. VS2015中添加新建项,找不到ado .net entity datamodel的解决方法
  9. Rop 文件上传解决思路
  10. nginx 详解
  11. 第七届河南省赛F.Turing equation(模拟)
  12. Accounting Flexfield Setup and Usage (Doc ID 124333.1)
  13. [转]GO err is shadowed during return
  14. 自己制作Chrome便携版实现多版本共存
  15. for..in 遍历js对象
  16. JS之事件机制
  17. PHP支付宝支付开发流程
  18. opencv ---getRotationMatrix2D函数
  19. API接口规范
  20. hadoop redis install (4)

热门文章

  1. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:2.搭建环境-2.8. 配置用户环境
  2. BSP
  3. 用 JavaScript 检测浏览器在线/离线状态(JavaScript API — navigator.onLine)
  4. socket编程演示样例(多线程)
  5. Unity 配置静态excel 工作流程
  6. php RSA 加密 与java加密互交,java解密
  7. Java基于注解和反射导入导出Excel
  8. poj 3592 Instantaneous Transference 【SCC +缩点 + SPFA】
  9. mongoDB 数据导出之mongoexport的用法
  10. Access 连接字符串全集