- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Spring boot 应用程序中使用 Microsoft SQL。我已经弄清楚了一切,现在我正在尝试将数据从 SQL 数据库传递到前端。但是,当我通过 thymeleaf 传递信息时,它不起作用。我有一个应用程序存储库以及一个实际传递数据的 DTO 类。尽管我不断收到同样的错误。很抱歉用这么多代码轰炸大家,但我已经尝试找到解决方案一段时间了,但仍然想不出解决方法。我相信它与 TestApp 类有关,但不确定在哪里。
错误:
org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'dtoTiername' cannot be found on object of type 'com.John.model.TestApp' - maybe not public or not valid?
应用程序存储库:
@Query("SELECT new com.John.model.TestApp(t.tiername, t.system) FROM AppSelectorTier t")
List<TestApp>getServerInfo();
服务层:
public List<TestApp> getServerInfo() {
List<TestApp> myList = appRepository.getServerInfo();
System.out.println(myList.size());
return myList;
}
Controller :
@RequestMapping("/edit")
public ModelAndView editTab(Model model) {
ModelAndView modelAndView = new ModelAndView();
List<TestApp>ary4 = new ArrayList<TestApp>();
try {
System.out.println("Hello Code");
ary4 = joinQueryService.getServerInfo();
modelAndView.setViewName("create");
} catch (Exception e) {
e.printStackTrace();
modelAndView.setViewName("test");
}
modelAndView.addObject("ary4",ary4);
return modelAndView;
}
HTML:
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Tiername</th>
<th>System</th>
</tr>
</thead>
<tbody>
<tr th:each="ary4 : ${ary4}">
<td th:text="${ary4.dtoTiername}"></td>
<td th:text="${ary4.dtoSystem}"></td>
</tr>
</tbody>
</table>
测试应用:
package com.John.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
public class TestApp implements java.io.Serializable {
private String dtoTiername;
private String dtoSystem;
private static final long serialVersionUID = 1L;
//Constructor
public TestApp(String dtoTiername, String dtoSystem) {
super();
this.dtoTiername = dtoTiername;
this.dtoSystem = dtoSystem;
}
//Default Constructor
public TestApp() {
}
//Getter
public String getName() {
return dtoTiername;
}
public String getSystem() {
return dtoSystem;
}
//Setter
public void setName(String dtoTiername) {
this.dtoTiername = dtoTiername;
}
public void setSystem(String dtoSystem) {
this.dtoSystem = dtoSystem;
}
}
实体:
package com.John.model;
import java.util.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "tier")
public class AppSelectorTier implements java.io.Serializable {
@Id
@Column(name = "tiername")
private String tiername;
@Column(name = "system")
private String system;
private static final long serialVersionUID = 1L;
//Constructor
public AppSelectorTier(String tiername, String system) {
super();
this.tiername = tiername;
this.system = system;
}
//Default Constructor
public AppSelectorTier() {
}
//Getter
public String getName() {
return tiername;
}
public String getSystem() {
return system;
}
//Setter
public void setName(String tiername) {
this.tiername = tiername;
}
public void setSystem(String system) {
this.system = system;
}
}
最佳答案
属性由 getter 和 setter 映射,因此您可以执行其中任一操作
第一:
保持 getter setter 与变量名称对齐
public class TestApp implements java.io.Serializable {
private String dtoTiername;
private String dtoSystem;
public String getDtoTiername() {
return dtoTiername;
}
public void setDtoTiername(String dtoTiername) {
this.dtoTiername = dtoTiername;
}
public String getDtoSystem() {
return dtoSystem;
}
public void setDtoSystem(String dtoSystem) {
this.dtoSystem = dtoSystem;
}
}
第二:
将 JSP 变量更改为
<tr th:each="ary4 : ${ary4}">
<td th:text="${ary4.name}"></td>
<td th:text="${ary4.system}"></td>
</tr>
关于java - Spring Boot中如何解决 "Exception evaluating SpringEL expression"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59231579/
我的 thymeleaf 模板有这样的问题。我得到: Exception evaluating SpringEL expression: "prod.itemName" (main:18) 来自这个表
我无法将值从集合传递到 html 页面。以前它在我添加集合以仅过滤日期列表之前起作用。如果有人可以提供帮助,我们将不胜感激。 :) 具有属性“日期”的 getter/setter 的实体/类: pub
我被困在我的项目中,我在网站的另一页上有一个看似相同的设置,但我无法让这个工作。 DemoApplication.java @GetMapping("/generate") public St
我正在使用 #strings.substr() 函数,它给出了以下错误: There was an unexpected error (type=Internal Server Error, stat
我正在尝试保存“员工”模型,而不为其分配任何“电话”模型(oneToOne 关系)。我有一个表单,在其中我通过添加以下内容来创建员工:名字、姓氏,然后是一个下拉列表,我可以从中选择要分配的电话。每当我
我在 Spring boot 应用程序中使用 Microsoft SQL。我已经弄清楚了一切,现在我正在尝试将数据从 SQL 数据库传递到前端。但是,当我通过 thymeleaf 传递信息时,它不起作
Book.java package pl.spring.guru.spring5webapp.model; import javax.persistence.*; import java.util.H
当我尝试在我的@Preauthorize 注释中使用“或”运算符时,出现以下错误。 java.lang.IllegalArgumentException: Failed to evaluate exp
所以我正在构建一个小型锻炼日志网络应用程序。截至目前,它应该做的就是拉出锻炼并显示锻炼名称。但thymeleaf似乎不知道exerciseName是什么。我的数据库中确实有一个带有锻炼名称的锻炼,但似
我正在开发一个简单的项目来实现 Spring 安全。当我尝试使用 Spring 和 Thymeleaf 的 Logout 链接时,问题就出现了。 1.pom.xml
我是 Spring Boot 新手,并尝试使用 JPA/JPQL 在两个不相关的实体(事务和项目)之间进行联接。但是在使用 thymeleaf 以表格格式显示它时出现以下错误: 2020-04-08
我从我的 ApplicationAdvice 类中获取 currentUser 并在用户登录时将其显示在每个页面上: @ModelAttribute("currentUser") public Tmt
我是一名优秀的程序员,十分优秀!