jsp中字段截取

jsp页面上截取

                <c:choose>
                                <c:when test="${fn:length(ad.remark) > 80}">
                                    <c:out value="${fn:substring(ad.remark, 0, 80)}..." />
                                </c:when>
                                <c:otherwise>
                                    <c:out value="${ad.remark}"/>
                                </c:otherwise>
                            </c:choose>

js中截取

  function subTextContent(textContent, len){
        if(textContent != null && textContent != undefined)
        {
            var tLen = textContent.length;
            if(tLen <= len)
            {
                return textContent;
            }
            else
            {
                return  textContent.substring(0, len) + "...";
            }
        }
        return "";
    }

后台截取


          for(ArticleEntity articleEntity : categoryList){
                    String content = articleEntity.getTextContent();
                    if(content !=null  && content.length()>70){

                        articleEntity.setTextContentSub(content.substring(0,70)+"...");
                    }else {
                        articleEntity.setTextContentSub(content);
                    }
                }

原文地址:https://www.cnblogs.com/xuerong/p/5694326.html