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

Spring靴,使用Thymeleaf时出现问题

苏乐童
2023-03-14

我使用的是NetBeans 8.1,我有一个SpringBoot项目,它具有以下依赖项:

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

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

它们都是在依赖项中正确下载的。

该项目有3个java类和一个扩展JpaRepository的接口

@Entity
public class Journal implements java.io.Serializable{

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String title;
private LocalDate created;
private String summary;

public Journal() {
}

public Journal(String title, LocalDate created, String summary) {
    this.title = title;
    this.created = created;
    this.summary = summary;
}
// getters and setters
}
@Controller
public class JournalController {

@Autowired
JournalRepository repo;

@RequestMapping("/")
public String index(Model model){
    model.addAttribute("journal", repo.findAll());
    return "index";
}

}
@SpringBootApplication
public class SpringBootJournalApplication {

@Bean
InitializingBean saveData(JournalRepository repo) {
    return () -> {
        repo.save(new Journal("text1", LocalDate.now(), "date1"));
        repo.save(new Journal("text2", LocalDate.now(), "date2"));
        repo.save(new Journal("text3", LocalDate.now(), "date3"));
        repo.save(new Journal("text4", LocalDate.now(), "date4"));
    };
}

public static void main(String[] args) {
    SpringApplication.run(SpringBootJournalApplication.class, args);
}
}
public interface JournalRepository extends JpaRepository<Journal, Long>{}

在src/main/资源项下-

<html lang="en-US" xmlns:th="http://www.thymeleaf.org">
<head></head>
<body>
    <div class="container">
        <h1>Spring Boot Journal</h1>
        <ul class="timeline">
            <div th:each="entry,status : ${journal}" >
                <li th:attr="class=${status.odd}?'timeline-inverted':''" >
                    <div class="tl-circ"></div>
                    <div class="timeline-panel">
                        <div class="tl-heading">
                            <h4> <span th:text="${entry.title}">TITLE</span> </h4>
                            <p><small class="text-muted"><i class="glyphicon glyphicon-time"></i>
                                    <span th:text="${entry.createdAsShort}">CREATED</span> </small></p>
                        </div>
                        <div class="tl-body">
                            <p> <span th:text="${entry.summary}">SUMMARY</span> </p>
                        </div>
                    </div>
                </li>
            </div>
        </ul>
    </div>
</body>

在html标签上,我有错误:本地名称为“xmlns: th不可序列化为XML 1.0的属性。如果我试图运行该项目并转到http://localhost:8080/页面,我有一个白标签错误页面,在netbean控制台中,我有org.springframework.expression.spel.SpelEvalue ation异常: EL1008E:在类型为“com.example.日志”的对象上找不到属性或字段“createdAsLong”——可能不是公共的?

共有1个答案

伯晨
2023-03-14

它自己说的错误已经足够了:classcom中没有这样的字段createdAsShort实例日志。根据你所展示的,你的课堂上肯定没有这样的领域。

 类似资料:
  • POM 应用程序 控制器 此外,我有模板文件夹中的资源文件夹和内部错误。html和index.html 当我访问localhost:8080/index时,会显示错误,而不是索引。我做错了什么?这真的是最简单的设置,它已经错了。。。

  • 我的ThymileAF模板中有一个AngularJS属性,看起来像这样: 当Thymeleaf尝试处理此模板时,我得到以下异常: Thymeleaf只是不能很好地处理

  • 问题内容: 我有独立的spring批处理工作。在JUNIT中运行时效果很好 和配置文件 The Main Class 当我注释掉contextconfiguration注释并通过启用@SpringApplicationConfiguration来启用spring-boot时(注意:我已经使用注释@EnableBatchProcessing启用了spring batch),并注释掉了由spring-

  • 我刚刚开始学习SpringMVC。我试图将一些数据从Thymeleaf表单保存到存储库,这扩展了CrudRepository。不幸的是,数据没有显示。 当我进入结果页面时,我看到使用的ID,但没有键入要形成的数据。哪里出了错? 这是控制器 `型号: 存储库: 表格摘录: 并从结果模板中提取:

  • 我有一个独立的spring批处理作业。这在JUNIT中工作得非常好 和配置文件 主要阶级 当我注释掉contextconfiguration注释并通过启用@SpringApplicationConfiguration(注意:我已使用注释@EnableBatchProcessing启用spring批处理)启用spring-boot,并注释掉spring-boot为spring批处理(如JobRepo