Spring+Springmvc+Hibernate框架搭建,简单实例

最近学习spring框架,学习中总是磕磕绊绊的,出现这样或者那样的问题,于是就像写一篇笔记,将spring,springmvc,hibernate框架整合的过程,以及简单的实现记录下来,一来加深印象,二来一遍以后忘记好找资料(...)当然,初学者也可以借鉴一下。废话不多说,直接上干货!

平台:eclipse

1.首先看看我整个项目的结构

2.项目开始:开始配置配置文件,主要有web.xml, applicationContext.xml, springmvc这三个文件

web.xml文件如下(主要是配置spring IOC容器,springmvc的dispacherServlet, 编码的格式化:防止出现乱码,SessionFilter过滤器:防止session异常。这里主要注意的是路径问题,由于楼主的配置文件是放在src下的config包中的,所以配置的时候用classpath:包名/配置文件名.xml的形式;如果放在WebContext下,直接写文件名就行, WEB-INF下就是/WEB-INF/文件名.xml,以此类推。。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>springmvc_1</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <!-- 配置spring ioc容器 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:config/applicationContext.xml</param-value>
	</context-param>

	<!-- Bootstraps the root web application context before servlet initialization -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
	<!-- 配置springmvc 的DispatcherServlet -->
	<servlet>
		<servlet-name>dispatcherServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:config/springmvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<!-- Map all requests to the DispatcherServlet for handling -->
	<servlet-mapping>
		<servlet-name>dispatcherServlet</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
	
	<
  • 12
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值