从 JSTL 访问方法
只是想知道是否有一种方法可以在不创建自定义标记库的情况下访问我的类中的方法。
例子 我有一个提供 4 个方法的类:hasDisplay()、hasCreate()、hasDelete() 和 hasEdit() - 所有这些都只返回一个布尔值。
从我的 jsp 中,我只想
<c:if test="{ar.hasEdit}"></c:if>
但这仅适用于 getter 和 setter 方法,对吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不想编写自己的标签,您可以为提供“beanish”接口的对象提供一个装饰器。所以你用 isHasEdit() 包装 hasedit() ,这样你的 jsps 就可以保持干净并且仍然使用所需的语法,但你最终会得到“脏”包装器。
我会选择自定义标签库。事情没那么复杂。
If you don't want to write your own tags you could provide a decorator for the object that provides a "beanish" interface. So you wrap hasedit() with isHasEdit() that way cou can keep your jsps clean and still use the desired syntax, but you end up with "dirty" wrappers.
I'd go for a custom taglib. It's not that complicated.
正确,JSP EL 只能访问 bean 属性。其他任何东西都需要自定义标签库。虽然还不够好,但已经有了。
Correct, JSP EL can only access bean properties. Anything else needs a custom taglib. It's not good enough, but there it is.