zoukankan      html  css  js  c++  java
  • spring boot: 支持jsp,支持freemarker

    spring boot: 支持jsp,支持freemarker

    支持jsp:

    加入依赖

    <!--jsp-->
    		<dependency>
    			<groupId>org.apache.tomcat.embed</groupId>
    			<artifactId>tomcat-embed-jasper</artifactId>
    			<!--scope>provided</scope-->
    		</dependency>
    		<!--jsp-标签-->
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>jstl</artifactId>
    		</dependency>
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>javax.servlet-api</artifactId>
    			<scope>provided</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-tomcat</artifactId>
    		</dependency>
    

      

      

    yml配置

    spring:
          mvc:
             view:
                prefix: /WEB-INF/jsp/
                suffix: .jsp
    

      

    webapp/WEB-FIN/web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
             version="3.1">
    </web-app>
    

      

    支持freemarket

    依赖

    <!--freemarka-->
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-freemarker</artifactId>
    		</dependency>
    

      

    yml配置

    spring:
            freemarker:
        allow-request-override: false
        cache: false
        check-template-location: true
        charset: utf-8
        content-type: text/html
        expose-request-attributes: false
        expose-session-attributes: false
        expose-spring-macro-helpers: false
        suffix: .ftl
        template-loader-path: classpath:/templates
    

      

    web.xml

    可有可无

    注册controller文件,

    如果配置的是freemarker, 用@RestController ,模板输出就不能: return "模板"; 必须要 ModelAndView了

    @RequestMapping("/test")
        public String test()
        {
            return "seller/list";
        }
    

      

    改为:

    @RequestMapping("/test")
        public ModelAndView test()
        {
            return new ModelAndView ("seller/list"); 

    //如果不行,改为:
          return new ModelAndView ("seller/list.ftl");
    }

      

    否则就用@Controller注解

  • 相关阅读:
    在 Ubuntu 中运转 &micro;Torrent
    TestDisk & PhotoRec——两个数据规复软件
    Ext2 IFS For Windows
    Rainlendar-可定制的桌面日历
    Gimmix:一个新的 MPD 客户端播放器
    SuperSwitcher-桌面增强器械
    Audacity 1.2.6 & 1.3.2
    XChat 2.8.0
    Griffith:电影聚集筹划软件
    VLC media player 0.8.6a
  • 原文地址:https://www.cnblogs.com/achengmu/p/10007787.html
Copyright © 2011-2022 走看看