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框架. ...
随机推荐
- 汇编_指令_DS*10H的含义
在8086存储器系统中,20位地址总线的地址是物理地址.但是由于8086内部寄存器都是16位的, 用16位寄存器直接访问20位存储器空间显然不可能,所以8086CPU使用了存储器分段的办法.这 样内存 ...
- 网络异常时抓包操作说明tcpdump+Wireshark
转债至 https://help.aliyun.com/knowledge_detail/40564.html?spm=5176.11065259.1996646101.searchclickresu ...
- 【BZOJ】1913: [Apio2010]signaling 信号覆盖(计算几何+计数)
题目 传送门:QWQ 分析 人类智慧题,不会做...... 详细题解1 详细题解2 总体思路是考虑四边形 讨论凹四边形凸四边形,最后加一个单调性优化省掉个$ O(n) $ 代码 代码感觉好短 ...
- 【学习笔记】LCT link cut tree
大概就是供自己复习的吧 1. 细节讲解 安利两篇blog: Menci 非常好的讲解与题单 2.模板 把 $ rev $ 和 $ pushdown $ 的位置记清 #define lc son[x][ ...
- 【POJ】2385 Apple Catching(dp)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13447 Accepted: 6549 D ...
- MySQL--产品的起源和状态
MySQL这个名字,起源不是很明确.一个比较有影响的说法是,基本指南和大量的库和工具带有前缀“my”已经有10年以上,而且不管怎样,MySQL AB创始人之一的Monty Widenius的女儿也叫M ...
- 「小程序JAVA实战」小程序的flex布局(22)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...
- Android apk couldn't install
an existing package with the same name and signature is already installed
- 为什么是static?
为什么是static因为系统开始执行一个程序前,并没有创建main()方法所在类的实例对象,它只能通过类名类调用主方法. public static void main(String args[])我 ...
- Server_id 冲突导致 IO 等待故障
问题描述: 线上添加新的 MySQL Slave 后,服务器异常. 1.show processlist; Queueing master event to the relay log Reconne ...