Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/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
Jsp ['new']在EL表达式${pet['new']}中是什么意思_Jsp_Spring Mvc_El - Fatal编程技术网

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

Jsp ['new']在EL表达式${pet['new']}中是什么意思,jsp,spring-mvc,el,Jsp,Spring Mvc,El,在一个简单的SpringMVC应用程序中,我遇到了一个:pet['new']。我以前没有见过这种结构,需要有人解释它的语义。它可能是指 第二线 <c:choose> <c:when test="${pet['new']}"> <c:set var="method" value="post"/> </c:when> <c:otherwise> <c:set var="metho

在一个简单的SpringMVC应用程序中,我遇到了一个:pet['new']。我以前没有见过这种结构,需要有人解释它的语义。它可能是指

第二线

<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.foo或bar['foo']。他们在这里选择了第二个,以引用新bean属性,即BaseEntity中的isNew getter

因此,测试相当于Java代码

if (pet.isNew())

你能在问题中加上一些例子来避免人们四处打猎吗?哇,我甚至注意到了一个新方法。非常感谢您的解释。如果能解释为什么作者使用${pet['new']}而不是${pet.new},答案会更好。@BalusC我同意,但我没有确定的答案。我在规范中的保留字列表中没有找到新的。因此,要么我错过了它,要么某个服务器实现与pet.new有问题,并使用pet['new']来规避它,要么作者认为它会导致问题,并预料到它。如果你有解释,请随意编辑我的答案。