Idea springboot构建Java web 项目

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

-------------------------------------------------

package com.example.demo;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(DemoApplication.class);
    }

}

-------------------------------------------------

package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
//@RequestMapping("/hello")
public class HelloController {

    @RequestMapping("/hello")
    public  String sayHi(Model model){
        model.addAttribute("msg","来吧,来吧相约酒吧。。。");
        return "hello";
    }
}


<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>成功界面</title>
</head>
<body>
    <h1>Success</h1>
    <h3>这是测试信息:${msg}</h3>
</body>

----------------------------------

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>hello</title>
    <%

        String path = request.getContextPath();
        String basePath = request.getScheme()+"://"+
                request.getServerName()+":"+request.getServerPort()+path+"/";

    %>
    <base href="<%=basePath%>" />
</head>
<body>
<h1>Hello!!!</h1>
<a href="<%=basePath%>/hello">点击我跳转到成功页面!!!</a>

</body>
</html>

----------------------------------

<?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_4_0.xsd"
         version="4.0">
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>
扫描二维码关注公众号,回复: 10678844 查看本文章
  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

下面打包部署实现:

发布了152 篇原创文章 · 获赞 78 · 访问量 50万+

猜你喜欢

转载自blog.csdn.net/qiuzhi__ke/article/details/105424735