SpringMVC大坑一枚:ContentNegotiatingViewResolver可能不利于SEO
2014-12-11 22:12
351 查看
广大站长都有关注自己网站被搜索引擎收录的习惯,最近用百度、360等搜索引擎,查看了自己网站的一些情况,使用命令“site:fansunion.cn”。
我发现了一些异常信息,不止一次:
“http://fansunion.cn/service
{"page":{"totalCount":5,"totalPage":1,"pageNo":1,"pageSize":10,"orderBy":null,"order":null,"params":{},"rows":[{"content":" 拜小雷为师,...
fansunion.cn/service 2014-11-13 - 百度快照 - 评价 - 翻译此页”
“http://fansunion.cn/code
{"page":{"totalCount":7,"totalPage":1,"pageNo":1,"pageSize":10,"orderBy":"id","order":"desc","params":{},"rows":[{"content":" SSH框架...
fansunion.cn/code 2014-11-16 - ”
“http://fansunion.cn/code
{ page :{ totalCount :8, totalPage :1, pageNo :1, pageSize :20, orderBy : id , order : desc , params :{}, rows :[{ content : , summary : 在线演示:小游戏-会飞的猪-FlappyPig , updat...
fansunion.cn/code 2014-11-09”
很明显,这是JSON格式的数据。
但是,我是用Freemarker直接渲染的页面,不可能是我主动响应JSON格式的数据。
于是,很快联想到,项目中有SpringMVC如下配置:
有了上述配置,一个请求,a.html动态渲染, a.json返回json格式的数据。
公司项目中这么配置的,我觉得也挺有好处的,JSON格式的请求,只要在请求后面以.json格式就好了,后端不需要再手动写代码了。
比如下面的代码:
总之一句话,公司项目boss采用这种配置,最大的目的就是,很方便地响应.html页面和.json数据,甚至是2者同时支持。
但是,实际情况证实,这种情况很可能 不利于百度-360等搜索引擎的优化。
最后,我决定全面废弃: ContentNegotiatingViewResolver。
如果需要JSON格式的数据,手动使用FastJSON响应。
实践出真知呀~
自己动手写网站,还是很锻炼人的~问题一大堆~
原文首发:http://fansunion.cn/article/detail/558.html
我发现了一些异常信息,不止一次:
“http://fansunion.cn/service
{"page":{"totalCount":5,"totalPage":1,"pageNo":1,"pageSize":10,"orderBy":null,"order":null,"params":{},"rows":[{"content":" 拜小雷为师,...
fansunion.cn/service 2014-11-13 - 百度快照 - 评价 - 翻译此页”
“http://fansunion.cn/code
{"page":{"totalCount":7,"totalPage":1,"pageNo":1,"pageSize":10,"orderBy":"id","order":"desc","params":{},"rows":[{"content":" SSH框架...
fansunion.cn/code 2014-11-16 - ”
“http://fansunion.cn/code
{ page :{ totalCount :8, totalPage :1, pageNo :1, pageSize :20, orderBy : id , order : desc , params :{}, rows :[{ content : , summary : 在线演示:小游戏-会飞的猪-FlappyPig , updat...
fansunion.cn/code 2014-11-09”
很明显,这是JSON格式的数据。
但是,我是用Freemarker直接渲染的页面,不可能是我主动响应JSON格式的数据。
于是,很快联想到,项目中有SpringMVC如下配置:
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="defaultContentType" value="application/json" /> <property name="mediaTypes"> <map> <entry key="html" value="text/html" /> <entry key="json" value="application/json" /> <entry key="xml" value="application/xml" /> </map> </property> <property name="defaultViews"> <list> <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"> </bean> <bean id="marshallingView" class="org.springframework.web.servlet.view.xml.MarshallingView"> <property name="marshaller"> <bean id="xStreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"> <property name="autodetectAnnotations" value="true" /> </bean> </property> <property name="contentType" value="application/xml" /> </bean> </list> </property> </bean>
有了上述配置,一个请求,a.html动态渲染, a.json返回json格式的数据。
公司项目中这么配置的,我觉得也挺有好处的,JSON格式的请求,只要在请求后面以.json格式就好了,后端不需要再手动写代码了。
比如下面的代码:
private void list(HttpServletResponse response, List<Map<String, Object>> list) { JSONObject jsonObject = new JSONObject(); jsonObject.put("list", list); super.returnJsonObject(response, jsonObject); }
总之一句话,公司项目boss采用这种配置,最大的目的就是,很方便地响应.html页面和.json数据,甚至是2者同时支持。
但是,实际情况证实,这种情况很可能 不利于百度-360等搜索引擎的优化。
最后,我决定全面废弃: ContentNegotiatingViewResolver。
如果需要JSON格式的数据,手动使用FastJSON响应。
实践出真知呀~
自己动手写网站,还是很锻炼人的~问题一大堆~
原文首发:http://fansunion.cn/article/detail/558.html
相关文章推荐
- SpringMVC大坑一枚:ContentNegotiatingViewResolver可能不利于SEO
- SpringMVC大坑一枚:ContentNegotiatingViewResolver可能不利于SEO
- SpringMVC大坑一枚:ContentNegotiatingViewResolver可能不利于SEO
- SpringMVC之ContentNegotiatingViewResolver实现根据请求资源名选择视图
- SpringMVC之ContentNegotiatingViewResolver详解
- SpringMVC中的ContentNegotiatingViewResolver配置
- springMVC之ContentNegotiatingViewResolver_01
- SpringMVC 使用ContentNegotiatingViewResolver整合多种视图解析器
- SpringMVC ContentNegotiatingViewResolver -- 根据请求资源名选择视图
- Springmvc同一资源不同描述配置-contentnegotiatingviewresolver
- Spring mvc 视图解析器 ContentNegotiatingViewResolver 源码分析
- Spring mvc 视图解析器 ContentNegotiatingViewResolver 源码分析
- Spring mvc 视图解析器 ContentNegotiatingViewResolver 源码分析
- ContentNegotiatingViewResolver - 内容协商视图解析器
- 实现Spring 4 MVC ContentNegotiatingViewResolver example
- ContentNegotiatingViewResolver spring REST中的内容协商(同一资源,多种展现:xml,json,html)
- Spring 3 MVC ContentNegotiatingViewResolver example
- SpringMVC ContentNegotiatingViewResolver -- 根据请求资源名选择视图
- spring mvc ContentNegotiatingViewResolver 根据路径后缀,选择不同视图
- ContentNegotiatingViewResolver vs. HttpMessageConverter+ResponseBody Annotation