• spring boot(一)


    freemarker:

    freemarker所需要依赖:

    <!-- 添加freemarker模版的依赖 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-freemarker</artifactId>
            </dependency>
    

    application.properties中freemarker的配置:

    ## Freemarker 配置
    spring.freemarker.template-loader-path=classpath:/templates/
    spring.freemarker.cache=false
    spring.freemarker.suffix=.ftl
    spring.freemarker.charset=UTF-8
    spring.freemarker.check-template-location=true
    spring.freemarker.content-type=text/html
    spring.freemarker.expose-request-attributes=false
    spring.freemarker.expose-session-attributes=false
    spring.freemarker.request-context-attribute=request  
    Controller中的配置:

     所需要的页面:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    欢迎!${name}
    </body>
    </html>
    

      

    springboot中运行时报错是如何跳转到错误页面:

    package com.example.demo.exception;
    
    import org.springframework.web.bind.annotation.ControllerAdvice;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import java.util.HashMap;
    import java.util.Map;
    
    @ControllerAdvice   //所有Controller运行都会进过这个
    public class ExceptionHandler {
    
      //如果报错执行这个方法
     @org.springframework.web.bind.annotation.ExceptionHandler(RuntimeException.class) 
     @ResponseBody
     public Map<String,Object> ExceptionHandler(){
       Map<String,Object> map = new HashMap<>();
       map.put("error:","500");
       map.put("msg:","頁面報錯了,請稍後,在重試!!1");
       return map;  
       }
     }
    

      

      

  • 相关阅读:
    nginx 配置文件配置
    源码编译php5.4 ./configure参数
    腾讯云Linux VPS新硬盘分区与挂载教程(面板重装不丢失数据)
    十行代码带你量化交易入门
    谱聚类(转)
    随机模拟(MCMC)
    LDA 线性判别分析
    Windows10上安装Keras 和 TensorFlow-GPU
    ASCII 码
    KL距离,Kullback-Leibler Divergence
  • 原文地址:https://www.cnblogs.com/wishsaber/p/12016382.html
Copyright © 2020-2023  润新知