springMVC和spring+hibernate架构.docx

上传人:b****8 文档编号:10964741 上传时间:2023-02-24 格式:DOCX 页数:29 大小:217.79KB
下载 相关 举报
springMVC和spring+hibernate架构.docx_第1页
第1页 / 共29页
springMVC和spring+hibernate架构.docx_第2页
第2页 / 共29页
springMVC和spring+hibernate架构.docx_第3页
第3页 / 共29页
springMVC和spring+hibernate架构.docx_第4页
第4页 / 共29页
springMVC和spring+hibernate架构.docx_第5页
第5页 / 共29页
点击查看更多>>
下载资源
资源描述

springMVC和spring+hibernate架构.docx

《springMVC和spring+hibernate架构.docx》由会员分享,可在线阅读,更多相关《springMVC和spring+hibernate架构.docx(29页珍藏版)》请在冰豆网上搜索。

springMVC和spring+hibernate架构.docx

springMVC和spring+hibernate架构

SpringMVC和spring+hibernate架构

Author:

zxw

Time:

2015-05-25

1、SpringMVC项目:

 

新建一个配置文件的源文件目录:

 

2、导入SpringMVC所需要的jar包:

(http:

//www.springsource.org/spring-community-download)或者右键创建AddSpring:

此实例需要收到导入的jar包有(如果用到其它jar包可手动再次导入):

org.springframework.aop-3.0.5.RELEASE.jar:

与Aop编程相关的包

org.springframework.beans-3.0.5.RELEASE.jar:

提供了简捷操作bean的接口

org.springframework.context-3.0.5.RELEASE.jar:

构建在beans包基础上,用来处理资源文件及国际化。

org.springframework.context.support-3.1.1.RELEASE.jar

org.springframework.core-3.0.5.RELEASE.jar:

spring核心包

org.springframework.web-3.0.5.RELEASE.jar:

web核心包,提供了web层接口

org.springframework.web.servlet-3.0.5.RELEASE.jar:

web层的一个具体实现包,DispatcherServlet也位于此包中。

org.springframework.asm-3.0.5.RELEASE.jar

mons.logging-1.1.1.jar

org.springframework.expression-3.0.5.RELEASE.jar

为了方便,建议在搭建环境中导入spring的所有jar包(所有jar包位于dist目录下),不需要的jar包可以在以后删除。

如果报错的话,可以导入下面jstl的两个核心jar包:

jstl.jarjstl标签的核心包。

standard.jar标准标签库包(此包也可以不导入)。

3、index.jsp首页内容:

springMVC和spring+hibernate架构

第一步:

跳转到添加用户界面

4、success.jsp页内容:

spring集成成功!

!

!

5、error.jsp页内容:

错误页面!

!

!

6、addUser.jsp页内容:

functionaddUser(){

varform=document.forms[0];

form.action="addUser.html";

form.method="post";

form.submit();

}

添加用户

姓名:

年龄:

7、editUser.jsp页内容:

添加用户

姓名:

年龄:

8、userManager.jsp页内容:

 

functiondel(id){

$.get("delUser.html?

id="+id,function(data){

alert(data.result);

if("success"==data.result){

alert("删除成功!

");

window.location.reload();

}else{

alert("删除失败!

")

}

});

}

姓名

年龄

编辑

iftest="${!

emptyuser}">

forEachitems="${user}"var="u">

${u.userName}

${u.age}

id=${u.id}">编辑

del('${u.id}')">删除

forEach>

if>

9、web.xml内容:

xmlversion="1.0"encoding="UTF-8"?

>

xmlns="

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xsi:

schemaLocation="

--加载顺序:

context-param>listener>filter>servlet-->

contextConfigLocation

classpath:

config/springAnnotation-*.xml

org.springframework.web.context.ContextLoaderListener

--第三步:

加载解析初始化Spring配置文件(利用总分配器DispatcherServlet处理请求到Spring配置文件)-->

User

org.springframework.web.servlet.DispatcherServlet

--读取Spring配置文件,加载解析初始化(默认查找路径:

/WEB-INF/[servlet-name]-servlet.xml)-->

contextConfigLocation

--查找spring配置文件路径(不配置init-param的话,默认为/WEB-INF/下Login-servlet.xml)-->

classpath:

config/springAnnotation-servlet.xml

--classpath路径为:

\WebRoot\WEB-INF\classes-->

1

--tomcat启动时加载解析DispatcherServlet类(如果不设置启动,则第一次访问时启动,比较慢)-->

--第二步:

index页面请求映射-->

User

*.html

--配置编码格式过滤器-->

EncodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

UTF-8

--初始化编码是UTF-8-->

forceEncoding

true

--强制转换response和request.setCharacterEncoding("UTF-8")编码格式-->

--过滤器映射-->

EncodingFilter

/*

--过滤所有请求-->

--如果不加,查询所有用户时的session关闭;NoSessionfoundforcurrentthread解决

OpenSessionInViewFilter

org.springframework.orm.hibernate4.support.OpenSessionInViewFilter

-->

--指定在spring配置的sessionFactory

sessionFactoryBeanName

sessionFactory

-->

--singleSession默认为true,若设为false则等于没用OpenSessionInView

singleSession

true

OpenSessionInViewFilter

/*

-->

index.jsp

10、springmvc配置文件springAnnotation-servlet.xml内容:

xmlversion="1.0"encoding="UTF-8"?

>

//www.springframework.org/schema/beans"

xmlns:

aop="http:

//www.springframework.org/schema/aop"xmlns:

context="http:

//www.springframework.org/schema/context"

xmlns:

p="http:

//www.springframework.org/schema/p"xmlns:

tx="http:

//www.springframework.org/schema/tx"

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xmlns:

mvc="http:

//www.springframework.org/schema/mvc"

xsi:

schemaLocation="

http:

//www.springframework.org/schema/beanshttp:

//www.springframework.org/schema/beans/spring-beans-3.0.xsd

http:

//www.springframework.org/schema/contexthttp:

//www.springframework.org/schema/context/spring-context-3.0.xsd

http:

//www.springframework.org/schema/aophttp:

//www.springframework.org/schema/aop/spring-aop-3.0.xsd

http:

//www.springframework.org/schema/txhttp:

//www.springframework.org/schema/tx/spring-tx-3.0.xsd">

--第四步:

启动注解组件扫描加载指定包下面的注解(需包含头部的:

xmlns、xmlns:

context、xmlns:

mvc、xsi:

schemaLocation)-->

component-scanbase-package="com.tgb.web.controller"/>

--第八步:

利用视图解析器继承扩展UrlBasedViewResolver的子类InternalResourceViewResolver解析返回的模型页面-->

--InternalResourceViewResolver解析器可以解析jstl所以不需要此viewClass-->

--此路径下文件安全性高,不可直接访问-->

--查找文件的后缀-->

11、spring配置文件springAnnotation-core.xml内容:

xmlversion="1.0"encoding="UTF-8"?

>

DOCTYPEbeansPUBLIC"-//SPRING//DTDBEAN2.0//EN""http:

//www.springframework.org/dtd/spring-beans-2.0.dtd"[

ENTITYcontextIncludeSYSTEM"org/springframework/web/context/WEB-INF/contextInclude.xml">

]>

--自己定义springbean-->

--beanid="springServiceImpl"class="com.test.service.impl.SpringServiceImpl">

--导入springbean文件-->

com/tgb/web/controller/spring/springAnnotation-import.xml"/>

12、hibernate配置文件springAnnotation-hibernate.xml内容:

xmlversion="1.0"encoding="UTF-8"?

>

DOCTYPEbeansPUBLIC"-//SPRING//DTDBEAN2.0//EN""http:

//www.springframework.org/dtd/spring-beans-2.0.dtd"[

ENTITYcontextIncludeSYSTEM"org/springframework/web/context/WEB-INF/contextInclude.xml">

]>

--配置数据库连接-->

mysql:

//localhost:

3306/test?

useUnicode=true&characterEncoding=utf-8"/>

org.hibernate.dialect.MySQLDialect

update

true

true

classpath*:

com/tgb/web/controller/hibernate/hibernate.cfg.test.xml

PROPAGATION_REQUIRED,-Exception

PROPAGATION_REQUIRED,-Exception

PROPAGATION_REQUIRED,-Exception

PROPAGATION_REQUIRED,-Exception

PROPAGATION_REQUIRED,-Exception

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 经济学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1