substring截取...和title鼠标移动到字段显示《c标签和el表达式(字段截取和判断)的使用》

引用C标签

<%@ taglib uri="htp://java.sun.com/jsp/jstl/core" prefix="c"%>  
<%@ taglib uri="htp://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="htp://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<!-- c:if判断-->
<c:if test="${fn:length(data.name)>15}"><span title='"${data.name}"'>
${fn:substring(data.name,0,15)}...
</span>
</c:if>

获取el表达式获取data.name的数据,判断字节长度如果大于15个字节,那么substring就截取0到15个字节,超过15个字节就用...显示,鼠标移动到显示字段显示title标签,该标签显示全部字段信息

关于jsp EL表达式<c:if>没有<c:else>解决方案

<c:if>没有<c:else>可以用<c:choose>来取代结构:  

<c:choose>  
   <c:when test="">    如果  
   </c:when>  
   <c:otherwise>  否则  
   </c:otherwise>  
</c:choose> 

例如上面的案例 <c:when> 如果 <c:otherwise> 否则

<c:choose>  
   <c:when test="${fn:length(data.name)>15}">
   	<span title='"${data.name}"'>
			${fn:substring(data.name,0,15)}...
	</span>
   </c:when>  
   <c:otherwise>
  	${data.name}
   </c:otherwise>  
</c:choose>

猜你喜欢

转载自blog.csdn.net/weixin_39559301/article/details/80974645