Rest接口和Thymeleaf的两个坑
2017-06-19 22:27
120 查看
spring boot thymeleaf 热部署
在使用spring boot 开发的时候,使用了Thymeleaf 作为前端的模板开发,发现在调试过程中,改动了Thymeleaf模板后,需要重新启动下项目,才可以立即生效
解决办法:
ctrl+shift+f9
http://www.oschina.net/question/779083_2148086
spring boot推荐支持,因为spring boot是快速开发,而thymeleaf又是原型即页面,所以从理念是接近的
单纯从效率上看,没有什么优势,而且用这种测试也不太准
thymeleaf 的首次渲染比Beetl差的是数量级,后续的持续渲染,3.0版本是有很大提升的,也和Beetl也差不多
优势是 html 的显示优势 前后端可以很好的分离,要是有很多的页面拆分(include 的部分)优势也不是很明显了
是的,基本上都会抽出一些公用模版,所以这种优势并不明显,像引入的js,css
如果配置了HttpMessageConverter,然后在@ResponseBody的接口的返回值使用JSON.toJSONString()转换过,输出的结果就会有以下提示
解决办法:接口直接返回对象,Spring会调用已经配置的HttpMessageConverter将对象转换成json字符串
另外一个解决地思路:http://blog.csdn.net/u010161082/article/details/46618947
HttpMessageConvert配置示例:
http://blog.csdn.net/my_god_sky/article/details/53385246
http://www.cnblogs.com/sunp823/p/5601397.html
在使用spring boot 开发的时候,使用了Thymeleaf 作为前端的模板开发,发现在调试过程中,改动了Thymeleaf模板后,需要重新启动下项目,才可以立即生效
解决办法:
ctrl+shift+f9
http://www.oschina.net/question/779083_2148086
spring boot推荐支持,因为spring boot是快速开发,而thymeleaf又是原型即页面,所以从理念是接近的
单纯从效率上看,没有什么优势,而且用这种测试也不太准
thymeleaf 的首次渲染比Beetl差的是数量级,后续的持续渲染,3.0版本是有很大提升的,也和Beetl也差不多
优势是 html 的显示优势 前后端可以很好的分离,要是有很多的页面拆分(include 的部分)优势也不是很明显了
是的,基本上都会抽出一些公用模版,所以这种优势并不明显,像引入的js,css
如果配置了HttpMessageConverter,然后在@ResponseBody的接口的返回值使用JSON.toJSONString()转换过,输出的结果就会有以下提示
解决办法:接口直接返回对象,Spring会调用已经配置的HttpMessageConverter将对象转换成json字符串
另外一个解决地思路:http://blog.csdn.net/u010161082/article/details/46618947
HttpMessageConvert配置示例:
<bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> </list> </property> <property name="fastJsonConfig"> <bean class="com.alibaba.fastjson.support.config.FastJsonConfig"> <property name="features"> <list> <value>AllowArbitraryCommas</value> <value>AllowUnQuotedFieldNames</value> <value>DisableCircularReferenceDetect</value> </list> </property> <property name="dateFormat" value="yyyy-MM-dd HH:mm:ss"></property> </bean> </property> </bean>
http://blog.csdn.net/my_god_sky/article/details/53385246
<?xml version="1.0" encoding="UTF-8"?> <!-- 注意!SpringMVC的配置文件使用的是mvc命名空间 --> <beans:beans xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> <context:annotation-config/> <context:component-scan base-package="com.mkyong.common.controller" /> <annotation-driven> <message-converters register-defaults="true"> <!-- @ResponseBody乱码问题,将StringHttpMessageConverter的默认编码设为UTF-8 --> <beans:bean class="org.springframework.http.converter.StringHttpMessageConverter"> <beans:constructor-arg value="UTF-8"/> </beans:bean> <!-- 配置Fastjson支持 --> <beans:bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <beans:property name="charset" value="UTF-8"/> <beans:property name="supportedMediaTypes"> <beans:list> <beans:value>application/json</beans:value> <beans:value>text/html;charset=UTF-8</beans:value> </beans:list> </beans:property> <beans:property name="features"> <beans:list> <beans:value>WriteMapNullValue</beans:value> <beans:value>QuoteFieldNames</beans:value> <beans:value>WriteDateUseDateFormat</beans:value> <beans:value>WriteEnumUsingToString</beans:value> </beans:list> </beans:property> </beans:bean> </message-converters> </annotation-driven> <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <beans:property name="prefix" value="/WEB-INF/"/> <beans:property name="suffix" value=".jsp"/> </beans:bean> </beans:beans>
http://www.cnblogs.com/sunp823/p/5601397.html
相关文章推荐
- SOA两个接口通常用于实现更:SOAP vs REST
- 测试rest接口的两个工具使用详解(restclient+soapUI)
- 随便选择两个城市作为预选旅游目标。实现两个独立的线程分别显示10次城市名,每次显示后休眠一段随机时间(1000ms以内),哪个先显示完毕,就决定去哪个城市。分别用Runnable接口和Thread类实现。
- Jersey+jetty 搭建高并RestFull 接口服务
- JIRA的外部请求接口REST的基本使用
- 利用两种不同的NAT配置实现两个接口的双向静态NAT测试
- RestEasy 调用Rest接口使用详解
- 简易rest接口调试工具
- rest接口设计之--返回值设计
- elasticsearch源码分析之Rest/RPC 接口解析(八)
- .使用Swagger导出rest接口文档
- 耳机接口的两个标准——OMTP和CTIA
- iServer 8C(2017)新增BaiduREST服务接口说明
- RestTemplate访问Spring MVC restFul接口
- http接口—SpringMVC+Rest集成服务端
- 关于服务器双网卡接口连接两个网络的静态路由配置---处理
- 项目应用:使用springmvc框架完成rest接口开发
- Spring Boot实战之Rest接口开发及数据库基本操作
- 打造完美接口文档 - 应用springboot+swagger2编写restFull接口文档
- ashx,页面一般情况下不能方法session,必须添加两个接口。才能访问session。