How does jsp JSTL call the method of the object?

It seems that JSP can't adjust the method of the object, and some colleagues also say that it can't. But I seem to have used it before. Just tried it. The result is very convenient to call.

Usually in jsp pages. You can point it out directly by using the attributes of a user object, such as user.name
. But in general there is a private String name attribute.

What if not? ? Then we write a method. This method must be like getXxxx, which is the same as the get method of the property. You can click directly. for example:

/**
	 * 身份证号码,解密
	 * 
	 * @author oumin
	 * @date : 2018年2月27日
	 * @return
	 */
	@Transient
	public String getCardIdDecrypt() {
		if (StringUtils.isNotBlank(this.cardId)) {
			return IdCardEncryptUtil.decrypt(this.cardId);
		}
		return null;

	}

The call in JSp is user.cardIdDecrypt.

It can be used the same as any other template.

for example:

request.setAttribute("CommUtil", new CommUtil());

该对象里面有一个方法:
public static String test(String a) {
		return "xxx" + a;
	}


JSP 页面这样使用 

		<title> ${CommUtil.test('aa') } </title>

测试时候,可以 显示出  xxxaa 的 。


或者这样 传其他对象值也可以
<title>  ${sysconfig.title}  和   ${CommUtil.test(sysconfig.title) } </title>


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324440604&siteId=291194637