1.MessageHaveImageTag.java to judge whether the content has a custom tag class.
2.myland.tld custom file.
3.messageQueryList.jsp to display the page.
Display effect:
MessageHaveImageTag.java
package com.myland.framework.tags; import java.util.List; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspTagException; import javax.servlet.jsp.tagext.TagSupport; import org.apache.commons.lang3.StringUtils; import org.springframework.web.context.WebApplicationContext; import com.myland.framework.util.collections.ListUtil; import com.myland.jp.common.service.MessageImageService; import com.myland.pojo.MessageImage; /** * * @author lengzl * @email [email protected] * @create July 30, 2015 at 4:59:42 PM */ public class MessageHaveImageTag extends TagSupport{ private static final long serialVersionUID = -5234128142635788254L; /** * information id */ private String messageId ; /** * Returns 1 if there is an image, returns 0 if it does not exist */ public int doStartTag() throws JspException { try { WebApplicationContext appContext = (WebApplicationContext) pageContext.getServletContext().getAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); MessageImageService messageImageService = (MessageImageService) appContext.getBean("messageImageService"); String html = "0"; if(StringUtils.isNotBlank(messageId)){ List<MessageImage> messageImages = messageImageService.getMdListByPid(messageId); if(ListUtil.isNotEmpty(messageImages)){ html = "1"; } } pageContext.getOut().write(html);//The return value of the tag } catch(Exception e) { throw new JspTagException("An exception occurred when encapsulating editable tags"); } return EVAL_BODY_INCLUDE; } /** * */ public int doEndTag() throws JspException { return EVAL_PAGE; } public String getMessageId() { return messageId; } public void setMessageId(String messageId) { this.messageId = messageId; } }
myland.tld
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"> <taglib> <tlibversion>1.0</tlibversion> <jspversion>1.1</jspversion> <shortname>myland</shortname> <!-- Pagination tab --> <tag> <name>page</name> <tagclass>com.myland.framework.tags.PageTag</tagclass> <bodycontent>JSP</bodycontent> <attribute> <name>pagination</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>showType</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> </tag> <!-- Display basic information of system configuration--> <tag> <name>base</name> <tagclass>com.myland.framework.tags.BaseInfoTag</tagclass> <bodycontent>JSP</bodycontent> <attribute> <name>node</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <!-- Make the text editable label --> <tag> <name>edit</name> <tagclass>com.myland.framework.tags.EditTag</tagclass> <bodycontent>JSP</bodycontent> <attribute> <name>message</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>url</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>paramName</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>type</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <!-- permission label --> <tag> <name>adminx_auth</name> <tagclass>com.lecheng.framework.tags.AuthTag</tagclass> <bodycontent>JSP</bodycontent> <attribute> <name>action</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <!-- Get dictionary information tag --> <tag> <name>dic</name> <tagclass>com.myland.framework.tags.DicTag</tagclass> <bodycontent>JSP</bodycontent> <attribute> <name>code</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>name</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>value</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>defaultValue</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> </tag> <!-- Intercept string label --> <tag> <name>str</name> <tagclass>com.myland.framework.tags.StrTag</tagclass> <bodycontent>JSP</bodycontent> <attribute> <name>str</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>length</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>mark</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <name>markLength</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> </tag> <!-- Get the value of string type in the cache --> <tag> <name>cache</name> <tagclass>com.myland.framework.tags.CacheTag</tagclass> <bodycontent>JSP</bodycontent> <attribute> <name>cacheType</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>key</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <!-- list number--> <tag> <name>index</name> <tagclass>com.myland.framework.tags.PageIndexTag</tagclass> <bodycontent>JSP</bodycontent> <attribute> <name>qc</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>step</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <tag> <name>cookie</name> <tagclass>com.myland.framework.tags.CookieTag</tagclass> <bodycontent>JSP</bodycontent> <attribute> <name>name</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <!-- Judging whether there is a picture based on messageid. Used ★★ --> <tag> <name>isHaveMessageImage</name> <tagclass>com.myland.framework.tags.MessageHaveImageTag</tagclass> <bodycontent>JSP</bodycontent> <attribute> <name>messageId</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib>
messageQueryList.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ include file="/common/common.jsp" %> <script type="text/javascript" src="${pageContext.request.contextPath}/js/adminx/commonAll.js"></script> <script type="text/javascript"> $(document).ready(function(){ // The title is not available when entering the page, and the title is not empty when querying, if($.trim("${qc.conditionsObj.title}")!=""){ $("#title").val("${qc.conditionsObj.title}"); } }); </script> <div id="showMessage" class="ui_tb"> <table id="tab" class="table" cellspacing="0" cellpadding="0" width="100%" align="center" border="0"> <tr> <!-- <th>Created</th> --> <th nowrap="nowrap">Created time</th> <th nowrap="nowrap">Create title</th> <th nowrap="nowrap">Create content</th> <th nowrap="nowrap">操作</th> </tr> <c:choose> <c:when test="${empty messages}"> <tr> <td colspan="6" style="text-align: center">No related records</td> </tr> </c:when> <c:otherwise> <c:forEach items="${messages }" var="mes" varStatus="status"> <tr> <%-- <td>${mes.crtPerson}</td> --%> <td>${mes.crtTime }</td> <td>${mes.title }</td> <td> $ {month.count} <a href="javascript:view('${mes.id }','${mes.status }')"> <c:set scope="page" var="isHave"> <!-- Judgment of custom tags★ --> <myland:isHaveMessageImage messageId="${mes.id}"></myland:isHaveMessageImage> </c:set> <c:if test="${isHave==1}"> <img alt="" src="${pageContext.request.contextPath }/images/adminx/common/img.jpg" style="border: 0px;" width="15"/> </c:if> </a> </td> <td> <span class="chakan"> <%-- -You can see the audit when creating a new one--%> <c:if test="${mes.status == '0' }"> <a href="javascript:audit('${mes.id }')" class="edit">审核</a> </c:if> <a href="javascript:viewDetailInfo('${mes.id }')">回复明细</a> <%--,'${qc.pagination.pageNum}' --%> </span> </td> </tr> </c:forEach> </c:otherwise> </c:choose> </table> <br> <div><myland:page pagination="${qc.pagination}" showType="002"/></div> </div>