gpt4 book ai didi

java - Spring mvc 注释 - javax.el.PropertyNotFoundException : Property 'isOnline' not found on type it. besmart.models.Luce - 但有

转载 作者:太空宇宙 更新时间:2023-11-04 13:10:38 24 4
gpt4 key购买 nike

大家早上好...

我的 Spring MVC 应用程序运行良好。我在表中添加了一个新字段,更新了我的模型,但我在标题中收到错误。我仅在 ListView 、详细信息页面中收到错误,使用相同的语法,它有效...

我的模型

@Entity
@Table(name="luci", catalog="SMARTPARK", uniqueConstraints = @UniqueConstraint(columnNames = "id_luce"))
public class Luce implements java.io.Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;
private int idLuce;
private Integer numeroLuce;
private String nomeLuce;
private String descrizione;
private boolean stato;
private Client client;
private boolean isOnline;


public Luce(){}

public Luce(int idLuce, Integer numeroLuce, String nomeLuce, String descrizione, boolean stato, Client client, boolean isOnline){
this.idLuce = idLuce;
this.numeroLuce = numeroLuce;
this.nomeLuce = nomeLuce;
this.client = client;
this.descrizione = descrizione;
this.stato = stato;
this.isOnline = isOnline;
}

@NotNull
@Id
@GeneratedValue
@Column(name="id_luce", unique = true, nullable = false)
public int getIdLuce() {
return idLuce;
}

public void setIdLuce(int idLuce) {
this.idLuce = idLuce;
}


@NotNull
@Column(name="numero_luce", unique = true, nullable = false)
public Integer getNumeroLuce() {
return numeroLuce;
}

public void setNumeroLuce(Integer numeroLuce) {
this.numeroLuce = numeroLuce;
}

@NotEmpty
@Size(max=50)
@Column(name="nome_luce", unique = true, nullable = false)
public String getNomeLuce() {
return nomeLuce;
}

public void setNomeLuce(String nomeLuce) {
this.nomeLuce = nomeLuce;
}

@ManyToOne
@JoinColumn(name="client")
public Client getClient() {
return this.client;
}

public void setClient(Client client) {
this.client = client;
}

@Size(max=255)
@Column(name="descrizione")
public String getDescrizione() {
return descrizione;
}

public void setDescrizione(String descrizione) {
this.descrizione = descrizione;
}


@Column(name="stato")
public boolean isStato() {
return stato;
}

public void setStato(boolean stato) {
this.stato = stato;
}

@Column(name="is_online")
public boolean isOnline() {
return isOnline;
}

public void setOnline(boolean isOnline) {
this.isOnline = isOnline;
}

}

然后在 Controller 中我有一个简单的

@RequestMapping(value = { path }, method = RequestMethod.GET)
public String listSpots(ModelMap model) {
List<Luce> luce = luceService.showLights();
model.addAttribute("luce", luce);

return path + "/luci";
}

直到今天早上都有效...... View 部分是

<c:forEach items="${luce}" var="light">
<tbody>
<tr>
<td><div class="list-field">${light.numeroLuce}</div></td>
<td><div class="list-field">${light.nomeLuce}</div></td>
<td><div class="list-field">${light.client.nomeClient}</div></td>
<td><span class="text-success">

<c:choose>
<c:when test="${light.stato == true}" ><span class="glyphicon glyphicon-ok-sign"></span></c:when>
<c:otherwise><span class="text-danger"><span class="glyphicon glyphicon-remove-sign"></span></span></c:otherwise>
</c:choose>
</span></td>
<td><span class="text-success">
<c:choose>
<c:when test="${light.isOnline == true}" ><span class="glyphicon glyphicon-ok-sign"></span></c:when>
<c:otherwise><span class="text-danger"><span class="glyphicon glyphicon-remove-sign"></span></span></c:otherwise>
</c:choose>
</span></td>
<td class="actions"><a class="pull-right" href="<c:url value='/lights/${light.idLuce}' />"><span class="glyphicon glyphicon-edit"></span></a></td>
</tr>
</c:forEach>

我刚刚添加了 light.isOnline == true 部分,并收到了错误。只是说,在另一个 View 中我有单个灯的细节,并且它有效..

最佳答案

问题出在 bean 方法 isOnline() 上。

将方法名称更改为 - getIsOnline(),它应该可以正常工作。

当您使用表达式语言时,它会自动附加 get 并将变量的第一个字符大写以获取 getter 方法。您的 bean 中没有 getIsOnline() 方法以及此错误的原因。

编辑:

根据 java bean 变量命名规范,将 boolean 字段的名称更改为 online,然后 isOnline() 方法就可以正常工作。

关于java - Spring mvc 注释 - javax.el.PropertyNotFoundException : Property 'isOnline' not found on type it. besmart.models.Luce - 但有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33996379/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com