zoukankan      html  css  js  c++  java
  • spring boot 入门

    1、  spring boot默认使用json的解析框架Jackson.

    2、  使用fastjson,需要引入fastjson依赖包:

    A、 我们需要在pom.xml中引入相应的依赖;

    B、 需要在App.java中将fastJson添加到转换器中,使用@bean注解

             @Bean

             public HttpMessageConverters fastJsonHttpMessageConverters() {

                       //创建fastjsonconverter

                       FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();

                       //格式化fastjsonconfig

                       FastJsonConfig fastJsonConfig = new FastJsonConfig();

                       fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);                

                       fastConverter.setFastJsonConfig(fastJsonConfig); 

                       HttpMessageConverter<?> converter = fastConverter; 

                       return new HttpMessageConverters(converter); 

             }

    3、  Spring devtools热部署,引入包:

    <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-devtools</artifactId>

            <optional>true</optional>

            <scope>true</scope>

    </dependency>

    写plugin:

    <!-- 热部署 -->

      <build>

         <plugins>

            <plugin>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>

                <configuration>

                      <fork>true</fork>

                </configuration>

            </plugin>

         </plugins>

      </build>

    热部署出现的问题:开始使用1.4.1版本的spring boot,配置的热部署不起作用,将版本换成1.3.3可以实现。

    4、  全局异常捕捉:

     

    @ControllerAdvice

    public class GlobalDefaultExceptionHandler {

             @ExceptionHandler(Exception.class)

             @ResponseBody

             public String defaultExceptionHandler(HttpServletRequest req,Exception e) {

                       return "对不起,服务器繁忙,请稍后再试!";

             }

    }

    5、  Spring boot server在application.properties中的配置

     

    作者:战旗 内容声明: 本内容属自己学习使用 ,若有抄袭情邮件(zhanqi3712@qq.com)告知 ,本人会尽快删除
  • 相关阅读:
    [NOI 2011][BZOJ 2434] 阿狸的打字机
    列出cocos2dx运行场景所有节点信息
    png 转 eps (电脑已安装latex环境前提下)
    latex小记
    第二篇
    博客第一篇
    百度动态规划
    百度约瑟夫算环
    转~最大连续子序列求和
    Oracle学习笔记——一对多的关系关联查询时只关联查找最新的第一条数据
  • 原文地址:https://www.cnblogs.com/liuyun-10/p/7865154.html
Copyright © 2011-2022 走看看