当前位置: 首页 > 知识库问答 >
问题:

带thymeleaf的Spring靴不起作用

闻人冷勋
2023-03-14

POM

<?xml version="1.0" encoding="UTF-8"?>
<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>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.6.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

应用程序

@SpringBootApplication
public class Application {


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

控制器

@Controller
@RequestMapping("/index")
public class IndexController {

    @RequestMapping("/")
    String index(){
        return "index";
    }


}

此外,我有模板文件夹中的资源文件夹和内部错误。html和index.html

当我访问localhost:8080/index时,会显示错误,而不是索引。我做错了什么?这真的是最简单的设置,它已经错了。。。

共有1个答案

长孙朝明
2023-03-14

问题出在您的IndexController类中。按照您声明的方式,您可以通过:<代码>http://localhost:8080/index/但不是本地主机:8080/index。这就是为什么在方法上有类注释和相同的注释。

url构造是某种分层-首先是Spring check类注释,然后是您的方法注释和构建的请求映射处理程序是:hostport"index""/"

 类似资料:
  • 我有以下thymeleaf html页面: 问题出在css样式表上。基本上Spring似乎找不到它,尽管我把文件放在 /resources/static/css/main.css 它返回错误(在日志中): 现在医生都说Spring Boot应该自动提供 /resources/static 这是我的网络配置: 出于某种原因,编辑器不让我插入Spring安全配置而不抱怨其格式不正确(IntelliJ、

  • 我想公开指标endpoint上的所有指标,但将其中一些发布到远程计量注册中心。 为此,我为指标endpoint提供了一个SimpleMeter注册表,并为远程仪表注册表(Datadog)添加了一个MeterRegister stryCustomizer,以添加一些MeterFilter以避免使用MeterFilter的DENY功能进行特定指标。例如: 但是,所有与jvm相关的指标在Datadog中

  • 我试图从一个应用程序(spring-boot应用程序)调用另一个应用程序(angularjs)上的RESTendpoint。应用程序正在下列主机和端口上运行。 REST应用程序,使用Spring Boot, HTML应用程序,使用angularjs, 处理程序所做的只是根据用户是否登录、身份验证失败或注销,写出类似的JSON响应。如下所示。 对我错过了什么或者做错了什么有什么想法吗?

  • 方法在我发出请求的另一个程序上执行: 邮递员中的结果:在此处输入图像描述 日志:2021-07-30 13:15:30.376警告4398---[nio-8080-exec-8]。W.S.M.S.DefaultHandlerExceptionResolver:解析[org.springframework.http.converter.HttpMessageNotreadableException:

  • 我对Spring靴不熟悉。我想在春靴中实现宽松的束缚。根据本文档https://docs . spring . io/spring-boot/docs/current/reference/html/boot-features-external-config . html # boot-features-external-config-relaxed-binding。它说,即使我们的名字中有破折号。