maven构建springmvcWord格式文档下载.docx

上传人:b****6 文档编号:18621394 上传时间:2022-12-29 格式:DOCX 页数:11 大小:354.50KB
下载 相关 举报
maven构建springmvcWord格式文档下载.docx_第1页
第1页 / 共11页
maven构建springmvcWord格式文档下载.docx_第2页
第2页 / 共11页
maven构建springmvcWord格式文档下载.docx_第3页
第3页 / 共11页
maven构建springmvcWord格式文档下载.docx_第4页
第4页 / 共11页
maven构建springmvcWord格式文档下载.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

maven构建springmvcWord格式文档下载.docx

《maven构建springmvcWord格式文档下载.docx》由会员分享,可在线阅读,更多相关《maven构建springmvcWord格式文档下载.docx(11页珍藏版)》请在冰豆网上搜索。

maven构建springmvcWord格式文档下载.docx

?

xmlversion="

1.0"

encoding="

UTF-8"

>

web-appxmlns:

xsi="

http:

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

xmlns="

xmlns:

web="

xsi:

schemaLocation="

id="

study"

version="

2.5"

<

display-name>

ArchetypeCreatedWebApplication<

/display-name>

description>

sprintMVC环境搭建<

/description>

!

--加载Spring配置文件-->

context-param>

<

param-name>

contextConfigLocation<

/param-name>

param-value>

classpath:

/configs/spring-*.xml<

/param-value>

/context-param>

--Spring监听-->

listener>

listener-class>

org.springframework.web.context.ContextLoaderListener<

/listener-class>

/listener>

--SpringMVC配置-->

servlet>

servlet-name>

Dispatcher<

/servlet-name>

servlet-class>

org.springframework.web.servlet.DispatcherServlet<

/servlet-class>

--自定义springmvc的配置文件名称和路径-->

init-param>

<

configs/spring-servlet.xml<

/init-param>

load-on-startup>

1<

/load-on-startup>

/servlet>

--springmvc请求后缀-->

servlet-mapping>

url-pattern>

*.do<

/url-pattern>

/servlet-mapping>

/web-app>

Web.xml文件设置完后,需要创建一个配置文件,用于配置

在src/main/resources/configs下创建spring-servlet.xml文件。

文件内容下面有两种

上面头部分都是一样的,只有下面bean中的信息不一样

第一种是,映射到jsp到,从controller中返回到jsp中;

第二种是,controller返回json数据,返回json数据,需要添加下面的配置,是json对象转换的类包

beansxmlns="

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

jee="

//www.springframework.org/schema/jee"

context="

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

p="

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

mvc="

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

util="

//www.springframework.org/schema/util"

//www.springframework.org/schema/beans

http:

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

http:

//www.springframework.org/schema/context

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

//www.springframework.org/schema/jee

//www.springframework.org/schema/jee/spring-jee-4.1.xsd

//www.springframework.org/schema/mvc

//www.springframework.org/schema/mvc/spring-mvc-4.1.xsd

//www.springframework.org/schema/util

//www.springframework.org/schema/util/spring-util-4.1.xsd"

context:

annotation-config/>

component-scanbase-package="

demo.test"

/>

beanclass="

org.springframework.web.servlet.view.InternalResourceViewResolver"

propertyname="

prefix"

value="

/WEB-INF/views/"

suffix"

value="

.jsp"

/bean>

/beans>

 

bean

class="

org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"

messageConverters"

list>

<

class="

org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"

supportedMediaTypes"

value="

application/json;

charset=utf-8;

"

/list>

/property>

Controller测试

首先创建一个包。

其次创建包下的类

一个是controller类,一个用于转换json的测试类

@Controller

publicclassTestController{

@RequestMapping("

/hello"

publicModelAndViewhello(){

ModelAndViewmv=newModelAndView();

mv.addObject("

spring"

"

springmvc"

);

mv.setViewName("

hello"

returnmv;

}

/h"

@ResponseBody

publicResultgettest(HttpServletResponseresponse){

response.setHeader("

Access-Control-Allow-Origin"

*"

Resulta=newResult();

a.setA("

tttt"

returna;

}

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

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

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

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