['new'] 在 EL 表达式中是什么意思 ${pet['new']}

What does ['new'] mean in EL expression ${pet['new']}

在一个简单的 Spring MVC 应用程序中,我遇到了 strange design: pet ['new']. I haven't seen this construction before and need someone to explain the semantics of it. It likely refers to this class

第二行

<c:choose>
    <c:when test="${pet['new']}">
        <c:set var="method" value="post"/>
    </c:when>
    <c:otherwise>
        <c:set var="method" value="put"/>
    </c:otherwise>
</c:choose>

和控制器

@RequestMapping(value = "/owners/{ownerId}/pets/new", method = RequestMethod.GET)
public String initCreationForm(@PathVariable("ownerId") int ownerId, Map<String, Object> model) {
    Owner owner = this.clinicService.findOwnerById(ownerId);
    Pet pet = new Pet();
    owner.addPet(pet);
    model.put("pet", pet);
    return "pets/createOrUpdatePetForm";
}

Bean 'bar' 的 JavaBean 属性 'foo' 可以使用两种语法形式访问:bar.foobar['foo'] .他们在这里选择了第二个,以引用 new bean 属性,即引用 BaseEntity 中的 isNew() getter。

所以测试等同于Java代码

if (pet.isNew())