Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SpringMVC注释-javax.el.PropertyNotFoundException:Property';isOnline';在type it.besmart.models.Luce上找不到-但有_Java_Spring Mvc - Fatal编程技术网

SpringMVC注释-javax.el.PropertyNotFoundException:Property';isOnline';在type it.besmart.models.Luce上找不到-但有

SpringMVC注释-javax.el.PropertyNotFoundException:Property';isOnline';在type it.besmart.models.Luce上找不到-但有,java,spring-mvc,Java,Spring Mvc,大家早上好 我的应用程序使用Spring MVC,运行良好。。然后我在表中添加了一个新字段,更新了我的模型,但标题中出现了错误。 我只在列表视图中,在细节页面中得到错误,使用相同的语法,它可以工作 我的模型 @Entity @Table(name="luci", catalog="SMARTPARK", uniqueConstraints = @UniqueConstraint(columnNames = "id_luce")) public class Luce implements java

大家早上好

我的应用程序使用Spring MVC,运行良好。。然后我在表中添加了一个新字段,更新了我的模型,但标题中出现了错误。 我只在列表视图中,在细节页面中得到错误,使用相同的语法,它可以工作

我的模型

@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;
}

}
然后在控制器中,我有一个简单的

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

        return path + "/luci";
    }
@RequestMapping(value={path},method=RequestMethod.GET)
公共字符串列表点(ModelMap模型){
List luce=luceService.showLights();
model.addAttribute(“luce”,luce);
返回路径+“/luci”;
}
直到今天早上还有效。。。 视图部分是

<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.numeroLuce}
${light.nomeLuce}
${light.client.nomeClient}
我刚刚添加了
light.isOnline==true
部分,得到了错误。
只是说,在另一个视图中,我有单个灯光的详细信息,它可以工作。

问题在于bean方法
isOnline()

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

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

编辑


根据JavaBean变量命名规范,将布尔字段的名称更改为
online
,然后
isOnline()
方法将正常工作。

问题在于bean方法
isOnline()

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

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

编辑


根据JavaBean变量命名规范,将布尔字段的名称更改为
online
,然后
isOnline()
方法将正常工作。

问题在于测试表达式

<c:when test="${light.isOnline == true}" 
这将查找属性
isOnline
,因为它是
boolean
而不是
boolean
,它将调用类中的
isIsOnline
方法。如果你不想,你需要显式地调用这个方法,如果这是可行的取决于你使用的EL版本

<c:when test="${light.isOnline()}"

问题在于您的测试表达式

<c:when test="${light.isOnline == true}" 
这将查找属性
isOnline
,因为它是
boolean
而不是
boolean
,它将调用类中的
isIsOnline
方法。如果你不想,你需要显式地调用这个方法,如果这是可行的取决于你使用的EL版本

<c:when test="${light.isOnline()}"

do
test=${light.online}
你不需要更多了。你可以从light.isOnline==true改为light.isOnline eq-truedo
test=${light.online}
你不需要更多了。你可以从light.isOnline==true改为light.isOnline eq-true你基本上是建议停止遵守JavaBean规范。属性名为
online
而不是
isOnline
@M.Deinum:仔细检查,属性名为isOnline而不是online。您是对的,没有注意到,但是它仍然会失败,因为它是一个
boolean
,所以它会变成
isIsOnline
而不是
getIsOnline
,后者适用于
boolean
而不是
boolean
。是的,另一个更好的解决方案是将属性名改为online而不是isOnline。我仍然不同意,它也适用于布尔型。我猜它检查并附加get和is以获得结果。如果方法名为getIsOnline(),它将不会遵循JavaBean规范,但它仍然可以正常工作。属性名为
online
而不是
isOnline
@M.Deinum:仔细检查,属性名为isOnline而不是online。您是对的,没有注意到,但是它仍然会失败,因为它是一个
boolean
,所以它会变成
isIsOnline
而不是
getIsOnline
,后者适用于
boolean
而不是
boolean
。是的,另一个更好的解决方案是将属性名改为online而不是isOnline。我仍然不同意,它也适用于布尔型。我猜它检查并附加get和is以获得结果。如果方法名为getIsOnline(),它将不会遵循JavaBean规范,但仍然可以正常工作。请仔细阅读。该属性名为isOnline而非online。请仔细阅读。