JSTL 字符串长度判断并截取

来源:互联网 发布:又是一个甲午年 知乎 编辑:程序博客网 时间:2024/04/30 04:43

应用场景:

如新闻列表展现时,超过长度的新闻截取前几个文字,后边的用 ... 表示。如下图所示:



参考代码:

<c:forEach items="${newslist}" var="news" varStatus="vs"><li><a href="${ctx}/news/newsQueryById.html?id=${news.id}"><span>${fn:substring(news.writetime,0,10)}</span><c:if test="${fn:length(news.title)>'13'}">${fn:substring(news.title,0,13)}...</c:if><c:if test="${fn:length(news.title)<='13'}">${news.title}</c:if></a></li></c:forEach>


0 0
原创粉丝点击