介绍
这篇文章将为大家详细讲解有关教你快速搭建一个springMVC框架,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
<强>一、搭建步骤强>
1,导入jar包,创建项目包结构
2,在网络。xml中配置前端控制器
3,编写springMvc核心配置文件
4,编写pojo类和控制器类测试
<强>二,实现强>
1,导入jar包,创建项目包结构
, 2,在网络。xml中配置前端控制器
& lt; !——, springMvc前端控制器,——比; & lt; servlet> & lt; servlet-name> springMvc & lt; servlet-class> org.springframework.web.servlet.DispatcherServlet & lt; !——,指定springMvc核心配置文件位置 如果没有指定那么默认就会去“/web - inf/+, & lt; servlet-name>标签中内容,+,-servlet.xml"中找 例如:“/web - inf/springMvc-servlet.xml" ——比; & lt; init-param> & lt; param-name> contextConfigLocation & lt; param-value>类路径:SpringMvc.xml & lt;/init-param> & lt; load-on-startup> 2 & lt;/load-on-startup> & lt;/servlet> & lt; servlet-mapping> & lt; servlet-name> springMvc & lt; url-pattern> * .action & lt;/servlet-mapping>
3,编写springMvc核心配置文件
& lt; ? xml version=?.0“,编码=癠TF-8" ?比; http://www.springframework.org/schema/beans" & lt; beans  xmlns=?; xmlns: xsi=癶ttp://www.w3.org/2001/XMLSchema-instance", xmlns: p=癶ttp://www.springframework.org/schema/p" xmlns:上下文=癶ttp://www.springframework.org/schema/context" xmlns:达博=癶ttp://code.alibabatech.com/schema/dubbo", xmlns: mvc=癶ttp://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://code.alibabatech.com/schema/dubbo , http://code.alibabatech.com/schema/dubbo/dubbo.xsd ,http://www.springframework.org/schema/context , http://www.springframework.org/schema/context/spring-context-4.0.xsd"的在 & lt; !——,配置@ controller注解扫描,——比; & lt;上下文:component-scan 基础包=癱n.it.controller"祝辞& lt;/背景:component-scan> & lt;/beans>
4,编写pojo类和控制器类测试
pojo类代码:
package cn.it.pojo; import java.util.Date; public class  Items { private Integer id; private String 名称; private Float 价格; private String 图片; private Date  createtime; private String 细节; public Integer  getId (), { return id; } public void  setId (Integer id), { 时间=this.id id; } public String  getName (), { return 名称; } public void  setName (String 名称),{ 时间=this.name name ==, null ?, null :, name.trim (); } public Float  getPrice (), { return 价格; } public void  setPrice (Float 价格),{ 时间=this.price 价格; } public String  getPic (), { return 图片; } public void  setPic (String 图片),{ 时间=this.pic pic ==, null ?, null :, pic.trim (); } public Date  getCreatetime (), { return createtime; } public void  setCreatetime (Date createtime), { 时间=this.createtime createtime; } public String  getDetail (), { return 细节; } public void  setDetail (String 细节),{ 时间=this.detail detail ==, null ?, null :, detail.trim (); } }
控制器类代码:
package cn.it.controller; import java.util.ArrayList; import 并不知道; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import cn.it.pojo.Items; @ controller public class  ItemsController {//@RequestMapping指定URL到请求方法的映射,例如: @RequestMapping (“/itemsList") public ModelAndView  itemsList () { 时间=List教你快速搭建一个springMVC框架