freemarker页面怎么取Boolean值

来源:百度知道 编辑:UC知道 时间:2024/06/17 07:43:11
后台有一个对象,对象有一个Boolean类型的属性。我想在页面上取到这个对象Boolean属性的值,我用${products.isNoMain}取不到。我该怎么取?请教高人!

Boolean类型不能使用isXxx需要使用getXxx,因为Freemarker使用java会对isXxx映射返回boolean基本型,但是freemarker不支持基本类型boolean,会抛异常。
freemarker中输出时可以使用这种方式输出${xxx?String("true","flase")}当xxx为true时显示字符串true,否则为字符串false,当然true,false字符串也可以换成其他字符串,比如yes和no。

ftl要访问的成员变量必须提供get属性器,不知道你写了没有

Action类里面要有products的属性器:
public Products getProducts() {
return products;
}

Products对象的类里面要有isNoMain的属性器:
public boolean getIsNoMain() {
return isNoMain;
}

这样在ftl里面访问${products.isNoMain}绝对是可以访问到的