zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    Leetcode(680) ;验证回文字符串 Ⅱ
    mysql常用操作语句
    组合索引问题
    php生成一维码以及保存-转载
    php后台实现页面跳转的方法-转载
    php操作表格(写)
    虚拟机复制后上网冲突的问题
    centos下安装nginx(转载)
    虚拟机与宿主机可以互相ping通,但是外网不能
    防火墙设置:虚拟机ping不通主机,但是主机可以ping通虚拟机(转载)
  • 原文地址:https://www.cnblogs.com/eclipse-/p/5914680.html
Copyright © 2011-2022 走看看