Spring常用配置及解析类说明

网友投稿 268 2023-03-14


Spring常用配置及解析类说明

springMVC配置用法的文章很多,但具体描述清楚的不多,这里主要介绍下常用的配置项的用法,以及它的解析类,springMVC处理内容有两种方式,一种是converter,另一种是ViewResolver,两种都能处理json,xml以及form内容格式。

xmlns:context="http://springframework.org/schema/context"

xmlns:aop="http://springframework.org/schema/aop" xmlns:mvc="http://springframework.org/schema/mvc"

xmlns:p="http://springframework.org/schema/p" xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:util="http://springframework.org/schema/util"

xmlns:c="http://springframework.org/schema/c"

xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans-3.2.xsd

http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-3.2.xsd

http://springframework.org/schema/mvc http://springframework.org/schema/mvc/spring-mvc-3.2.xsd

http://springframework.org/schema/util http://springframework.org/schema/util/spring-util.xsd

http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop-3.2.xsd">

class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"

p:favorPathExtension="false" p:favorParameter="true"

p:parameterName="format" p:ignoreAcceptHeader="true"

p:defaultContentType="application/json">

application/json

application/xml

class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">

true

com.api.domain

com.api.web.controller.vo

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

value="org.springframework.web.servlet.view.JstlView" />

class="org.springframework.http.converter.StringHttpMessageConverter">

text/plain;charset=UTF-8

text/html;charset=UTF-8

class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />

class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">

SpringMVC返回json配置步骤如下:

1、添加jackson.jar包

2、在applicationContext.xml配制文件中添加如下代码

class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">

text/html;charset=UTF-8

3、在controller中添加如下代码

@RequestMapping(value="/chinese/listTree", method = RequestMethod.POST)

@ResponseBody

public List getlistChinese(Model model){

List list = (List) commonMgr.find("from User");

return list;

}

返回值可以为list也可以为Map类型

总结

以上就是本文关于Spring常用配置及解析类说明的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站:

Spring中利用配置文件和@value注入属性值代码详解

spring配置扫描多个包问题解析

Spring配置使用之Bean生命周期详解

如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

xmlns:context="http://springframework.org/schema/context"

xmlns:aop="http://springframework.org/schema/aop" xmlns:mvc="http://springframework.org/schema/mvc"

xmlns:p="http://springframework.org/schema/p" xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:util="http://springframework.org/schema/util"

xmlns:c="http://springframework.org/schema/c"

xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans-3.2.xsd

http://springframework.org/schema/context http://springframework.org/schema/context/spring-context-3.2.xsd

http://springframework.org/schema/mvc http://springframework.org/schema/mvc/spring-mvc-3.2.xsd

http://springframework.org/schema/util http://springframework.org/schema/util/spring-util.xsd

http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop-3.2.xsd">

class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"

p:favorPathExtension="false" p:favorParameter="true"

p:parameterName="format" p:ignoreAcceptHeader="true"

p:defaultContentType="application/json">

application/json

application/xml

class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"

p:favorPathExtension="false" p:favorParameter="true"

p:parameterName="format" p:ignoreAcceptHeader="true"

p:defaultContentType="application/json">

application/json

application/xml

class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">

class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">

true

com.api.domain

com.api.web.controller.vo

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

value="org.springframework.web.servlet.view.JstlView" />

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

value="org.springframework.web.servlet.view.JstlView" />

value="org.springframework.web.servlet.view.JstlView" />

class="org.springframework.http.converter.StringHttpMessageConverter">

text/plain;charset=UTF-8

text/html;charset=UTF-8

class="org.springframework.http.converter.StringHttpMessageConverter">

text/plain;charset=UTF-8

text/html;charset=UTF-8

class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />

class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">

SpringMVC返回json配置步骤如下:

1、添加jackson.jar包

2、在applicationContext.xml配制文件中添加如下代码

class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />

class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">

class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">

SpringMVC返回json配置步骤如下:

1、添加jackson.jar包

2、在applicationContext.xml配制文件中添加如下代码

class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">

text/html;charset=UTF-8

class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">

text/html;charset=UTF-8

3、在controller中添加如下代码

@RequestMapping(value="/chinese/listTree", method = RequestMethod.POST)

@ResponseBody

public List getlistChinese(Model model){

List list = (List) commonMgr.find("from User");

return list;

}

返回值可以为list也可以为Map类型

总结

以上就是本文关于Spring常用配置及解析类说明的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站:

Spring中利用配置文件和@value注入属性值代码详解

spring配置扫描多个包问题解析

Spring配置使用之Bean生命周期详解

如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:微服务api网关安全(微服务 网关)
下一篇:Servlet获取AJAX POST请求中参数以form data和request payload形式传输的方法
相关文章

 发表评论

暂时没有评论,来抢沙发吧~