描述:会议开始日期小于当前日期,会议状态变成关闭并显示CLOSED,并且变更按钮变为灰色,不可操作。反之显示OPEN,变更按钮可操作。
展示效果:
JSP界面:获取status的值,判断值为1,则页面上显示CLOSED,否则显示OPEN。并且判断按钮的样式。
<table id="table_id_example" class="display table table-striped">
<thead>
<tr>
<th>ID</th>
<th>会議名称</th>
<th>会議開始日</th>
<th>申込開始日</th>
<th>申込終了日</th>
<th>会議の状態</th>
<th></th>
</tr>
</thead>
<tbody id="gai">
<c:forEach items="${select}" var="item" varStatus="status">
<tr>
<td id="idd${status.index}">${item.meetingid}</td>
<td>${item.meetingname}</td>
<td><fmt:formatDate value="${item.meetingstarttime}" pattern="yyyy/MM/dd" /></td> <%--type="time" timeStyle="medium"--%>
<td><fmt:formatDate value="${item.meetingstartdate}" pattern="yyyy/MM/dd"/></td>
<td><fmt:formatDate value="${item.mettingenddate}" pattern="yyyy/MM/dd"/></td>
<td id="status">${item.status eq "1"?"CLOSED":"OPEN"}</td>
<%-- ${messStr.IMAGEID eq "" || messStr.IMAGEID == null ? messStr.imageid :messStr.IMAGEID}--%>
<td style="text-align:center;">
<c:if test="${ item.status eq '0'}">
<button class="label label-table label-success"style="border:1px solid #91c957;border-radius:4px;width:80px;">
<a href="/meetingupdate?id=${item.meetingid}" style="color:#fff;">变更</a>
</button>
</c:if>
<c:if test="${ item.status eq '1'}">
<button class="label label-table label-success"style="border:0px solid #91c957;border-radius:4px;width:80px;background-color:rgba(145,201,87,0.4)">
<a href="#" style="color:#fff;" >变更</a>
</button>
</c:if>
</td>
</tr>
</c:forEach>
</tbody>
</table>
Controller层:
@Controller
public class MeetingShowController {
@Autowired
MeetingShowService meetingShowService;
@RequestMapping("/meetingshow")
public ModelAndView meetingShow() {
ModelAndView modelandview = new ModelAndView("meetinglist_show");
List<MeetingShowDto> meetingShowSelect = meetingShowService.meetingShowSelect();
/*
Map<Integer,String> map = new HashMap<>();
Map<Integer,String> map1 = new HashMap<>();
for(int i=0;i<meetingShowSelect.size();i++){
System.out.println(meetingShowSelect.get(i));
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
DecimalFormat dd=new DecimalFormat("0000");
String str = df.format(meetingShowSelect.get(i).getMeetingstarttime());
Date str1 = new Date();//获取当前日期
String str2=df.format(str1);
if(str.compareTo(str2)<0)//会议结束
{
String id =meetingShowSelect.get(i).getMeetingid();
map.put(i,id);
}
else if(str.compareTo(str2)==0)//会议进行中
{
String id =meetingShowSelect.get(i).getMeetingid();
map1.put(i,id);
}
else{ //会议结束
System.out.println("会议结束"+str);
}
}
modelandview.addObject("close",map);
modelandview.addObject("ing",map1);*/
modelandview.addObject("select", meetingShowSelect);
return modelandview;
}
Service层:
@Service
public class MeetingShowService {
@Autowired
MeetingShowDao meetingShowDao;
public List<MeetingShowDto> meetingShowSelect() {
return meetingShowDao.meetingShowSelect();
}
}
Dao层:
@Component
public interface MeetingShowDao {
List<MeetingShowDto> meetingShowSelect();
}
Mapper.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.smt.societymeeting.dao.MeetingShowDao">
<resultMap id="SelectAll" type="com.smt.societymeeting.dto.MeetingShowDto">
<id property="meetingid" column="MEETINGID"></id>
<result property="meetingname" column="MEETINGNAME"></result>
<result property="meetingintroduce" column="MEETINGINTRODUCE"></result>
<result property="meetingstartdate" column="MEETINGSTARTDATE"></result>
<result property="mettingenddate" column="METTINGENDDATE"></result>
<result property="meetingstarttime" column="MEETINGSTARTTIME"></result>
<result property="typeselect" column="TYPESELECT"></result>
<result property="status" column="sta"></result>
<!-- <association property="typeselect" resultMap="Selectapplication"></association>-->
</resultMap>
<resultMap id="Selectapplication" type="com.smt.societymeeting.dto.ApplicationDto">
<id property="applicationid" column="APPLICATIONID"></id>
<result property="applicationtype" column="APPLICATIONTYPE"></result>
<result property="applicationname" column="APPLICATIONNAME"></result>
<result property="ative" column="sta"></result>
</resultMap>
<select id="meetingShowSelect" resultMap="SelectAll" >
SELECT * ,
IF
(DATE_FORMAT(MEETINGSTARTTIME,'%Y-%m-%d')<![CDATA[ <= ]]>DATE_FORMAT(NOW(),'%Y-%m-%d'),"1","0") AS sta
FROM meeting
</select>
</mapper>
mapper-config文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<typeAlias alias="ApplicationDto" type="com.smt.societymeeting.dto.ApplicationDto"/>
<typeAlias alias="MeetingShowDto" type="com.smt.societymeeting.dto.MeetingShowDto"/>
</typeAliases>
<typeHandlers>
<typeHandler handler="com.smt.societymeeting.framework.typeHandler.LocalDateTimeTypeHandler"/>
</typeHandlers>
<mappers>
<mapper resource="com/smt/societymeeting/dao/MeetingShow-mapper.xml"/>
</mappers>
</configuration>