描述:根据会议申请开始日期,会议申请结束日期,会议开始日期和回忆状态进行检索。多条件检索,或者单条件检索,如果都为空,则检索全部。然后回显到页面上,可清空条件在此搜索。
页面展示:
JSP页面:进到展示一览画面搜素框前的内容为空不显示,搜索框输入内容,提交点击搜索后回显刚输入的内容。清空:清空全部输入框的内容。
<form action="/search" method="get" style="width:98.5%;margin:0 auto;">
<div class="panel-body" style="padding-top:0px;margin-top:0px;">
<div class="pad-btm form-inline" style="padding-bottom:0px;">
<div class="row" >
<div class="col-sm-6 table-toolbar-left" style="width:100%;padding-top:25px;">
<div style="width:100%;">
<div style="width:20%;float:left;">
<label style="float:left;height:25px;line-height:25px;">会議開始日:</label>
<div class="col-sm-6" style="float:left;width:65%;">
<input type="text" class="form-control input-lg" id="datetimepicker4a" name="meetingstarttime" style="height:25px;width:100%;" value="${backshow[0]}">
</div>
</div>
<div style="width:20%;float:left;">
<label style="float:left;height:25px;line-height:25px;">申込開始日:</label>
<div class="col-sm-6" style="float:left;width:65%;">
<input type="text" class="form-control input-lg" id="datetimepicker3" name="meetingstartdate" style="height:25px;width:100%;" value="${backshow[1]}">
</div>
</div>
<div style="width:20%;float:left;">
<label style="float:left;height:25px;line-height:25px;">申込終了日:</label>
<div class="col-sm-6" style="float:left;width:65%;">
<input type="text" class="form-control input-lg" id="datetimepicker4" name="mettingenddate" style="height:25px;width:100%;" value="${backshow[2]}">
</div>
</div>
<div style="width:20%;float:left;">
<label style="float:left;height:25px;line-height:25px;">会議の状態</label>
<div class="col-sm-6" style="float:left;width:65%;">
<span id="spp" style="display:none;">${backshow[3]}</span>
<select id="sta" name="sta" style="height:25px;width:100%;">
<option value =""></option>
<option value ="CLOSE">CLOSE</option>
<option value="OPEN">OPEN</option>
</select>
</div>
</div>
<div style="width:20%;float:left;text-align: right;">
<button class="btn btn-info" type="submit" style="width:80px;height:25px;line-height:10px;margin-right:15px;">検索</button>
<button type="button" class="btn btn-warning" onclick="res()" style="width:80px;height:25px;line-height:10px;">クリア</button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<script type="text/javascript">
window.onload=function xuan()
{
var sta = $("#spp").text();
if(sta=="1")
{
$("#sta").find("option:eq(1)").attr("selected",true);
}
else if(sta=="0")
{
$("#sta").find("option:eq(2)").attr("selected",true);
}
else
{
$("#sta").find("option:eq(0)").attr("selected",true);
}
}
function res()
{
document.getElementById("datetimepicker4a").value=null;
document.getElementById("datetimepicker3").value=null;
document.getElementById("datetimepicker4").value=null;
document.getElementById("sta").options[0].selected = true;
}
</script>
Controller层:
@Controller
public class MeetingShowController {
@Autowired
MeetingShowService meetingShowService;
@RequestMapping("/search")
public ModelAndView search(HttpServletRequest request, HttpServletResponse response)
{
ModelAndView modelandview = new ModelAndView("meetinglist_show");
String meetingstarttime =request.getParameter("meetingstarttime");
String meetingstartdate =request.getParameter("meetingstartdate");
String mettingenddate =request.getParameter("mettingenddate");
String sta =request.getParameter("sta");
String sta1;
if(sta.equals("CLOSE"))
{
sta1="1";
}
else if(sta.equals("OPEN"))
{
sta1="0";
}
else
{
sta1="";
}
Map<String,Object> map = new HashMap<>();
map.put("meetingstarttime",meetingstarttime);
map.put("meetingstartdate",meetingstartdate);
map.put("mettingenddate",mettingenddate);
map.put("sta",sta1);
List<MeetingShowDto> seach = meetingShowService.search(map);
List<String> backshow = new ArrayList<>();
backshow.add(meetingstarttime);
backshow.add(meetingstartdate);
backshow.add(mettingenddate);
backshow.add(sta1);
modelandview.addObject("select", seach);
modelandview.addObject("backshow", backshow);
return modelandview;
}
}
Service层:
@Service
public class MeetingShowService {
@Autowired
MeetingShowDao meetingShowDao;
public List<MeetingShowDto> search(Map<String,Object> map) {
return meetingShowDao.search(map);
}
}
Dao层:
@Component
public interface MeetingShowDao {
List<MeetingShowDto> search(Map<String, Object> map);
}
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="search" resultMap="SelectAll">
SELECT * FROM (SELECT * ,
IF
(DATE_FORMAT(MEETINGSTARTTIME,'%Y-%m-%d')<![CDATA[ <= ]]>DATE_FORMAT(NOW(),'%Y-%m-%d'),"1","0") AS sta
FROM meeting) as tt
<where>
<if test="meetingstarttime!=null and meetingstarttime!=''">
and tt.MEETINGSTARTTIME <![CDATA[ <= ]]> #{meetingstarttime}
</if>
<if test="meetingstartdate!=null and meetingstartdate!=''">
and tt.meetingstartdate <![CDATA[ <= ]]> #{meetingstartdate}
</if>
<if test="mettingenddate!=null and mettingenddate!=''">
and tt.mettingenddate <![CDATA[ <= ]]> #{mettingenddate}
</if>
<if test="sta!=null and sta!=''">
and tt.sta <![CDATA[ = ]]> #{sta}
</if>
</where>
</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>