1.导入jar包

2.在web.xml中配置前端控制器

  <!-- spring前端控制器 -->
  <servlet>
      <servlet-name>springmvc</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <!-- 加载配置文件 -->
      <!-- SpringMVC的配置文件的默认路径是/WEB-INF/${servlet-name}-servlet.xml -->
      <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath:springmvc.xml</param-value>
      </init-param>
  </servlet>

  <!-- 映射 设置所有以action结尾的请求进入SpringMVC-->
  <servlet-mapping>
      <servlet-name>springmvc</servlet-name>
      <url-pattern>*.action</url-pattern>
  </servlet-mapping>

3.创建配置文件和包结构

springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

</beans>

4.创建实体类和controller

Item.java

public class Item {
    // 商品id
    private int id;
    // 商品名称
    private String name;
    // 商品价格
    private double price;
    // 商品创建时间
    private Date createtime;
    // 商品描述
    private String detail;

        set/get....
}

ItemController.java

@Controller
public class ItemController {

    @RequestMapping(value="/iteam/findAllItem.action")
    public ModelAndView findALLItem(){

        ModelAndView mav = new ModelAndView();

        //模拟查找数据
        List<Item> list = new ArrayList<>();
        list.add(new Item(1, "1华为 荣耀8", 2399, new Date(), "质量好!1"));
        list.add(new Item(2, "2华为 荣耀8", 2399, new Date(), "质量好!2"));
        list.add(new Item(3, "3华为 荣耀8", 2399, new Date(), "质量好!3"));
        list.add(new Item(4, "4华为 荣耀8", 2399, new Date(), "质量好!4"));
        list.add(new Item(5, "5华为 荣耀8", 2399, new Date(), "质量好!5"));
        list.add(new Item(6, "6华为 荣耀8", 2399, new Date(), "质量好!6"));

        mav.addObject("itemList", list);
        mav.setViewName("/WEB-INF/jsp/itemList.jsp");
        return mav;
    }

}

5.在springmvc.xml中添加扫描注释

<context:component-scan base-package="com.springmvc.controller"/>

6.加载的服务器,启动服务器测试

最新文章

  1. F2工作流引擎Web层全新扁平化UI上线
  2. 软工_Alpha阶段事后分析总计
  3. Ubuntu中查看32还是64
  4. 基于ArcEngine的空间数据通用建库软件介绍
  5. spring整合各大ORM框架的原理图
  6. 首页视频播放jquery
  7. Traffic Lights - SGU 103(最短路)
  8. LeetCode OJ 118. Pascal&#39;s Triangle
  9. PS2键盘 + LCD12864 实验
  10. H3CNE实验:配置交换机接口
  11. Struts2学习笔记(六)——Action处理请求参数
  12. Gym 100952F&amp;&amp;2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+优先队列】
  13. 小实验3:实现haproxy的增、删、查
  14. UNIX网络编程——名字与地址转换(gethostbyname,gethostbyaddr,getservbyname,getservbyport,getaddrinfo,getnameinfo函数)
  15. 解析xml字符串时报“前言中不允许有内容”错误。
  16. Java 多线程(五)—— 线程池基础 之 FutureTask源码解析
  17. python pip 使用时错误: Patal error in launcher:Unable to create process using &#39;&quot;&#39;
  18. e803. 获得和设置JProgressBar的值
  19. 2018C语言第三次作业
  20. 微信都在用的移动敏捷测试方法和工具|视频+PPT

热门文章

  1. transport error 202: bind failed: Address already in use
  2. 2018-2-13-win10-uwp-音频
  3. 代码托管平台--GitHub 使用小结
  4. python png与jpg的相互转换
  5. java.sql.Date和java.util.Date的联系和区别
  6. Maven pom配置(Spring+SpringMvc+mybaties)
  7. leetcood学习笔记-104-二叉树的最大深度
  8. cmake -help
  9. python 远程执行命令
  10. BZOJ 3779: 重组病毒(线段树+lct+树剖)