springmvc框架简单搭建
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>Spring MVC Application</display-name> <servlet> <servlet-name>mymvc-dispatcher</servlet-name> <!--声明mvc控制器DispatcherServlet--> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!--声明mvc配置文件--> <!--如果不配置该选项,则默认扫描 ‘servlet-name’-servlet.xml文件 , 以该web.xml为例,如不配置,默认访问 mymvc-dispatcher-servlet.xml--> <init-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/mymvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mymvc-dispatcher</servlet-name> <!--请求路径--> <url-pattern>/</url-pattern> </servlet-mapping></web-app><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd" >
<mvc:annotation-driven />
<context:component-scan base-package="com"/>
<import resource="myjpa.xml"/>
<bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/page/"/>
<property name="suffix" value=".jsp"/>
</bean> </beans> 二、利用java 配置
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package com.springapp.mvc;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.ViewResolver;import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;import org.springframework.web.servlet.config.annotation.EnableWebMvc;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;import org.springframework.web.servlet.view.InternalResourceViewResolver;import org.springframework.web.servlet.view.JstlView;import org.springframework.web.servlet.view.UrlBasedViewResolver;/** * Created by zzq on 2017/11/30. */@Configuration@EnableWebMvc@ComponentScan(basePackages = "com")public class MvcConfig{ @Bean public InternalResourceViewResolver setupViewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/pages/"); resolver.setSuffix(".jsp");// resolver.setViewClass(JstlView.class); return resolver; }} |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
package com.springapp.mvc;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.FilterType;import org.springframework.web.servlet.config.annotation.EnableWebMvc;/** * Created by zzq on 2017/11/30. */@Configuration@ComponentScan(basePackages = "com",excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,value = EnableWebMvc.class)})public class RootConfig {} |
package com.springapp.mvc;import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;/** * Created by zzq on 2017/11/30. */public class SpringMvcWebIn extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class<?>[] getRootConfigClasses() { return new Class<?>[]{RootConfig.class}; } @Override protected Class<?>[] getServletConfigClasses() { return new Class<?>[]{MvcConfig.class}; } @Override protected String[] getServletMappings() { return new String[]{"/"}; }}springmvc框架简单搭建的更多相关文章
- Asp.net框架与SpringMvc框架简单分析
(此文为自我总结,错误很多请勿借鉴) 1.就前两天分析SpringMvc框架中是通过controler来实现跳转页面,通过mapping来实现数据连接 分析的方法又通过java的类之间进行相互调用,个 ...
- ssh框架简单搭建
这里是个人对SSH框架搭建的一点心得,仅供新手,勿喷 首先,搞清楚分层, 视图层 --> 控制层 --> 业务层 --> DAO层--> 持久层 搭建的顺序是从后向前,搭建一 ...
- PHP之MVC微型框架简单搭建
好长时间没有写博客了,这段时间过得紧张的不行,以致于都没有抽出时间来好好的总结一下自己这段时间的生活和学习. 其实今天不想写什么技术博客,就想简单总结一下这段时间的生活.10月8号从家里回来以后决定自 ...
- SpringMVC 框架的搭建及基本功能的实现
首先新建一个WEB项目 导入jar包 我们基于Spring mvc框架进行开发,需要依赖一下的spring jar包: spring-aop-4.0.4.RELEASE.jar spring-bean ...
- Spring学习之SpringMVC框架快速搭建实现用户登录功能
引用自:http://blog.csdn.net/qqhjqs/article/details/41683099?utm_source=tuicool&utm_medium=referral ...
- Django学习(二) Django框架简单搭建
为了快速学习Python进行Web的开发,所以我不准备从Python的基础学起,直接从Django框架入手,边学框架边学Python的基础知识. 下面就开始Django的快速开发之旅吧. 关于Djan ...
- springmvc框架的搭建
1引入jar包 jar包下载地址http://maven.springframework.org/release/org/ 以下是我引入的jar包 aopalliance-1.0.jaraspectj ...
- 新手springmvc web简单搭建过程-caidachun
第一次做整了一天,中间各种报错,大佬肯定要嘲笑我了,但还是很有成就敢,现在只知道怎么装配,还不知道为什么,还需要学习.加油 1.新建动态web项目 2. 添加jar包,可以到网上下载,commons- ...
- Idea搭建SpringMVC框架(初次接触)
公司转Java开发,做的第一个项目是SpringMVC框架,因为底层是同事封装,等完成整个项目,对SpringMVC框架的搭建还不是很了解,所以抽时间不忙的时候自己搭建了一个SpringMVC框架. ...
随机推荐
- [转]关闭 Chrome 浏览器的启动时提示 - 请停用以开发者模式运行的扩展程序
最新版本 69.0.3497.92 (x64) 解决办法: https://www.cnblogs.com/liuxianan/p/disable-chrome-extension-warning.h ...
- Ubuntu16下编译linux内核,报"mkimage" command not found错的解决
"mkimage" command not found - U-Boot images will not be built /work/system/linux-3.4.20/ar ...
- 搭建psdash 监控系统
一.监控系统介绍 Psdash 是一款查看 Linux 系统信息的 web 面板,和另一款系统监控工具 Glances 一样,psDash 的系统信息的采集也是由 psutil 完成的.和 Glanc ...
- ceph---luminous版的安装
前言 ceph luminous版本新增加了很多有意思的功能,这个也是一个长期支持版本,所以这些新功能的特性还是很值得期待的,从底层的存储改造,消息方式的改变,以及一些之前未实现的功能的完成,都让ce ...
- pycharm多行代码缩进、左移
在使用pycharm时,经常会需要多行代码同时缩进.左移,pycharm提供了快捷方式 1.pycharm使多行代码同时缩进 鼠标选中多行代码后,按下Tab键,一次缩进四个字符 2.pycharm使多 ...
- Spring、Springboot常用注解:@Qualifier(不定时更新)
1.@Qualifier 出现场景: 老项目中有多个实现类实现同一个接口时,或者一个项目中有多个数据源时,spring容器不知道该注入哪个实现类或者使用哪个数据源,该注解就派上用场. 1)多实现类实现 ...
- SQL 语句中的in、find_in_set、like的区别
1.in查询相当于多个or条件的叠加,例如: select * from user where user_id in (1,2,3);等效于select * from user where user_ ...
- ios笔试题
最近找工作,有面试有笔试部分,故把笔试题自己整理了下. 面试能力要求:精通iphone的UI开发,能熟练操作复杂表视图,熟练使用图层技术, 可以自定义UI控件,使用类别扩展系统控件功能; 擅长通讯 ...
- Bug of VS2015+WDK
1> Signability test failed.1> 1> Errors:1> 22.9.7: DriverVer set to incorrect date ( ...
- Python基础:字符串的常见操作
# 切片 # 切片 获取对象中一部分数据 [起始位置:结束位置(不包含):步长] qpstr = "山东张学友" result = qpstr[1: 3: 1] # 东张 prin ...