• spring boot 1.4.1 with jsp file sample


    <!--pom.xml-->
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.cn</groupId>
        <artifactId>test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>test</name>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.4.1.RELEASE</version>
        </parent>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-jasper</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
    
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>
    #src/main/java/application.properties
    server.port=8080 
    server.tomcat.uri-encoding=UTF-8
    server.tomcat.access-log-enabled=true
    
    server.tomcat.basedir=./
    spring.mvc.view.prefix=/WEB-INF/jsp/
    spring.mvc.view.suffix=.jsp
    //Application.java
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.web.support.SpringBootServletInitializer;
    
    /**
     * Hello world!
     *
     */
    @SpringBootApplication
    public class Application extends SpringBootServletInitializer{
        
        public static void main(String[] args) throws Exception {
            SpringApplication.run(Application.class, args);
        }
    }
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    public class IndexController {
        @RequestMapping(value="/")
        //@ResponseBody
        public String indexPage(Model model){
            model.addAttribute("say", "hello world");
            return "index";
        }
    
    }
    <!--src/main/webapp/WEB-INFO/jsp/index.jsp-->
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
        ${say}
    </body>
    </html>
  • 相关阅读:
    《Java程序性能优化》之设计优化
    使用Java内存映射(Memory-Mapped Files)处理大文件
    创建型模式之Singleton模式
    Web服务器原理及简单实现
    Web性能测试中的几个关键指标
    SELECT的解析顺序及慢查询优化
    从几个方向进行Web渗透测试
    使用C# (.NET Core) 实现观察者模式 (Observer Pattern) 并介绍 delegate 和 event
    RxJS -- Subscription
    ASP.Net Core项目在Mac上使用Entity Framework Core 2.0进行迁移可能会遇到的一个问题.
  • 原文地址:https://www.cnblogs.com/eclipse-/p/5914680.html
Copyright © 2020-2023  润新知