成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

一.初識(shí)SpringBoot(入門(mén)級(jí)02)

1.1 Freemarker 其他用法


@RequestMapping("/freemarkerIndex")
public String index(Map result) {

目前創(chuàng)新互聯(lián)公司已為數(shù)千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站托管維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、龍口網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。

  result.put("name", "yushengjun");
  result.put("sex", "0");
  List listResult = new ArrayList();
  listResult.add("zhangsan");
  listResult.add("lisi");
  listResult.add("itmayiedu");
  result.put("listResult", listResult);
  return "index";

}

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8" />
<title>首頁(yè)</title>
</head>
<body>
${name}
<#if sex=="1">

<#elseif sex=="2">

<#else>
其他

  </#if>      
 <#list userlist as user>
   ${user}
 </#list>

</body>
</html>

1.2 Freemarker配置
新建application.properties文件

spring.freemarker.allow-request-override=false
    spring.freemarker.cache=true
    spring.freemarker.check-template-location=true
    spring.freemarker.charset=UTF-8
    spring.freemarker.content-type=text/html
    spring.freemarker.expose-request-attributes=false
    spring.freemarker.expose-session-attributes=false
    spring.freemarker.expose-spring-macro-helpers=false
    #spring.freemarker.prefix=
    #spring.freemarker.request-context-attribute=
    #spring.freemarker.settings.*=
    spring.freemarker.suffix=.ftl
    spring.freemarker.template-loader-path=classpath:/templates/
    #comma-separated list
    #spring.freemarker.view-names= # whitelist of view names that can be resolved

1.3 使用JSP渲染W(wǎng)eb視圖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
<dependencies>
<!-- SpringBoot 核心組件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
</dependencies>

1.4 在application.properties創(chuàng)建以下配置
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

1.5 后臺(tái)代碼@Controller
br/>@Controller

   @RequestMapping("/index")
   public String index() {
         return "index";
    }

}

注意:創(chuàng)建SpringBoot整合JSP,一定要為war類型,否則會(huì)找不到頁(yè)面.
不要把JSP頁(yè)面存放在resources// jsp 不能被訪問(wèn)到

1.6 全局捕獲異常
@ExceptionHandler 表示攔截異常
? @ControllerAdvice 是 controller 的一個(gè)輔助類,最常用的就是作為全局異常處理的切面類
? @ControllerAdvice 可以指定掃描范圍
? @ControllerAdvice 約定了幾種可行的返回值,如果是直接返回 model 類的話,需要使用 @ResponseBody 進(jìn)行 json 轉(zhuǎn)換
o 返回 String,表示跳到某個(gè) view
o 返回 modelAndView
o 返回 model + @ResponseBody

@ControllerAdvice
public class GlobalExceptionHandler {

        @ExceptionHandler(RuntimeException.class)
        @ResponseBody
        public Map<String, Object> exceptionHandler() {
            //開(kāi)發(fā)中,一般都會(huì)講錯(cuò)誤日志記錄在日志中,全局捕獲異常使用AOP技術(shù),采用異常通知
            //如果每個(gè)方法都可能發(fā)生異常,每個(gè)方法上都加上try
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("errorCode", "500");
                    map.put("errorMsg", "全局捕獲系統(tǒng)錯(cuò)誤!");
                    return map;
        }

}

文章名稱:一.初識(shí)SpringBoot(入門(mén)級(jí)02)
當(dāng)前網(wǎng)址:http://jinyejixie.com/article32/joggpc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)企業(yè)建站、定制開(kāi)發(fā)、關(guān)鍵詞優(yōu)化虛擬主機(jī)、網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

微信小程序開(kāi)發(fā)
呼和浩特市| 通州区| 霍城县| 合水县| 广东省| 庐江县| 乃东县| 河南省| 卢湾区| 新宾| 洞头县| 肃宁县| 锡林浩特市| 东乡县| 商都县| 宜宾县| 朝阳区| 南陵县| 台南县| 青岛市| 保靖县| 沙雅县| 黎川县| 陆河县| 且末县| 大宁县| 灯塔市| 宁陵县| 平邑县| 班玛县| 开原市| 翼城县| 基隆市| 中江县| 巴南区| 遂昌县| 科尔| 筠连县| 霍山县| 图木舒克市| 甘泉县|