Spring 弹簧控制器404

Spring 弹簧控制器404,spring,spring-boot,spring-mvc,Spring,Spring Boot,Spring Mvc,我正在使用thymeleaf开发一个简单的servlet,它通过按下按钮来更改文本 问题是,当我在Spring工具套件4.4中以Spring应用程序的形式运行它时,它可以正常工作,但当将它编译为servlet并将其上载到tomcat服务器时,会出现以下错误: 代码如下: MainController.java package com.example.demo; import org.springframework.stereotype.Controller; import

我正在使用thymeleaf开发一个简单的servlet,它通过按下按钮来更改文本

问题是,当我在Spring工具套件4.4中以Spring应用程序的形式运行它时,它可以正常工作,但当将它编译为servlet并将其上载到tomcat服务器时,会出现以下错误:

代码如下:

MainController.java

 package com.example.demo;

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

    @Controller
    public class MainController {


    @GetMapping("/saludo")
    public String saludo(Model model) {
    model.addAttribute("saludo", "bondia");
    return "index"; 
    }

    @GetMapping("/nosaludo")
    public String nosaludo(Model model) {
    model.addAttribute("saludo", "no te salud");
    return "index"; 
    }

    @GetMapping("/despido")
    public String despido(Model model) {
    model.addAttribute("saludo", "Adeu");
    return "index"; 
    }
    }
ServletInicializer.java

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(CreantServletApplication.class);
    }

}
index.html

<html xmlns:th="http://www.thymeleaf.org">
    <head>
    </head>
    <body>
            <form action="./saludo">
                <input type="submit" value="Saludar">
            </form>
            <form action="./nosaludo">
                <input type="submit" value="No saludar">
            </form>
            <form action="./despido">
                <input type="submit" value="Despedirse">
            </form>
            <h1 th:text="${saludo}">Text que es modificara</h1>
    </body>
</html>

修改后的文本

请发布完整的请求url。如果使用war文件在Tomcat中部署它,则需要向url添加上下文根

默认为:

http://<host><port>/<war-name-without-file-type>/saludo
http:////saludo

请发布完整的请求url。如果使用war文件在Tomcat中部署它,则需要向url添加上下文根

默认为:

http://<host><port>/<war-name-without-file-type>/saludo
http:////saludo