Hibernate4+Spring JPA+SpringMVC+Volecity搭建web应用(二)
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:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <!-- 使Spring支持自动检测组件,如注解的Controller -->
//base-package中的属性是controller所在的路径
<context:component-scan base-package="cn.bdqn.smvc.controller" />
<context:annotation-config /> <!--避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean> <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" /> <!-- JSON转换器 -->
</list>
</property>
</bean> <!-- jsp视图解析器 -->
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
//下面value中的是jsp所在的路径
<property name="prefix" value="WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean> <!-- velocity视图解析器 <bean id="velocityViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
<property name="exposeRequestAttributes" value="true" /> <property name="contentType"
value="text/html;charset=UTF-8" /> <property name="prefix" value="" /> <property
name="suffix" value=".html" /> <property name="layoutUrl" value="layout.html"
/> </bean> <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath"> <value>WEB-INF/template/</value> </property>
<property name="velocityProperties"> <props> <prop key="input.encoding">UTF-8</prop>
<prop key="output.encoding">UTF-8</prop> <prop key="contentType">text/html;charset=UTF-8</prop>
</props> </property> </bean> -->
</beans> web.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>smvc</display-name> <!-- spring全局监听 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 同时加载多个spring配置文件可用 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:SpringConfig.xml
</param-value>
</context-param> <!-- spring mvc控制 -->
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:SpringMVC.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping> <!-- 忽略过滤的文件 -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping> <!-- 出错页面定义 -->
<error-page>
<error-code>500</error-code>
<location>/error.shtml</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/nofound.shtml</location>
</error-page> <welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app> 控制器示例 package cn.bdqn.smvc.controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class HelloController { @RequestMapping("/hi.shtml")
public String hello(){
return "hello";
}
}
Hibernate4+Spring JPA+SpringMVC+Volecity搭建web应用(二)的更多相关文章
- Hibernate4+Spring JPA+SpringMVC+Volecity搭建web应用(一)
pom.xml配置 <dependencies> <!-- hibernate begin --> <dependency> <groupId>org. ...
- 联系 管理 Hibernate4+Spring JPA+SpringMVC+Volecity搭建web应用(三)
hibernate注解实体类示例 package cn.bdqn.smvc.entity; import java.io.Serializable; import javax.persistence. ...
- Spring Boot入门-快速搭建web项目
Spring Boot 概述: Spring Boot makes it easy to create stand-alone, production-grade Spring based Appli ...
- springmvc+maven搭建web项目
1.创建一个maven project 为spring1 2.进行项目的配置:默认的java 1.5 在properties中选择project facts项目进行配置,反选web之后修改java环境 ...
- springmvc+maven搭建web项目之二 通过另一种方式配置spring
1.创建maven web项目 2. 配置pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:x ...
- Spring+Druid+SpringMVC的搭建(附Demo)
最近公司事情比较少,便想利用这段空闲时间做一个自己的博客. 前端界面已经搞好,感谢杨姐的模板,自己稍微把模板没有的模块给补全了. 今天便开始自己的SSM框架搭建,数据库链接是采用数据库连接池.先上个项 ...
- SpringMVC Memcached 搭建WEB项目缓存框架
最近做的项目一直在使用memcached作为缓存来缓存各种数据,现在BOSS要在项目上加上缓存.并把任务交给我.便琢磨怎么解决这个问题. 看了很多文章,写的比较详尽靠谱的就是这篇了http://www ...
- 用dotnet core搭建web服务器(二)路由表与封装
https://gitee.com/lightsever/netcore_study/tree/master/server02_path 先上代码,首先我们把httpserver封装一下,以后用起来方 ...
- springMVC+Hibernate4+Spring整合一(配置文件部分)
本实例采用springMvc hibernate 与 spring 进行整合, 用springmvc 取代了原先ssh(struts,spring,hibernate)中的struts来扮演view层 ...
随机推荐
- 【leetcode❤python】235. Lowest Common Ancestor of a Binary Search Tree
#-*- coding: UTF-8 -*- # Definition for a binary tree node.# class TreeNode(object):# def __init ...
- 【leetcode❤python】171. Excel Sheet Column Number
#-*- coding: UTF-8 -*- # ord(c) -> integer##Return the integer ordinal of a one-character string. ...
- SQL 汉字转换成拼音首字母 首字母查
-- ============================================= -- 功能:汉字转换成拼音首字母 首字母查 -- ========================== ...
- Fully differential amplifiers
Introduction 专业音频工程师通常使用术语“平衡”来指代差分信号传输.这也告知了我们对称的概念,同时它在差分系统中也是非常重要的.在差分系统中,驱动器有平衡的输出,传输线有平衡的 ...
- 测试框架Mockito使用笔记
Mockito,测试框架,语法简单,功能强大! 静态.私有.构造等方法测试需要配合PowerMock,PowerMock有Mockito和EasyMock两个版本,语法相同,本文只介绍Mockito. ...
- python_way day12 RabbitMQ ,pymysql
python_way day12 1.RabbitMQ 2.pymysql RabbitMQ 1.基本用法 """ producer """ ...
- data-*属性——使用自定义属性的方式存储数据
HTML5提供了data-*属性能存储页面或应用程序的私有自定义数据.只需在属性前加上data-前缀即可,值可以是任意字符串. 存储的(自定义)数据能够被页面的 JavaScript 中利用,以创建更 ...
- C#垃圾回收机制(GC)
GC的前世与今生 虽然本文是以.net作为目标来讲述GC,但是GC的概念并非才诞生不久.早在1958年,由鼎鼎大名的图林奖得主John McCarthy所实现的Lisp语言就已经提供了GC的功能,这是 ...
- jquery animate 改变元素背景颜色
通过animate不能直接设置css样式可以通过https://cdnjs.cloudflare.com/ajax/libs/jquery-color/2.1.2/jquery.color.min.j ...
- 无法在web服务器上启动调试。打开的URL的IIS辅助进程当前没有运行。
调试时弹出:无法在web服务器上启动调试.打开的URL的IIS辅助进程当前没有运行.