mybatis组合模糊+分页查询

时间:2022-05-18 02:48:28

//组合模糊查询就是这么简单

<select id="findAllJiemu" parameterType="java.util.Map" resultMap="ImNoticeJiemu">
SELECT A.*,(select f.names from pt_userinfo f where f.ids = ( select r.userinfoids from pt_user r where r.ids = A.createuser )) as createname ,(select f.names from pt_userinfo f where f.ids = ( select r.userinfoids from pt_user r where r.ids = A.updateuser )) as updatename FROM IM_NOTICE_JIEMU A WHERE A.COMPANYCODE=#{companycode,jdbcType=VARCHAR}
<if test="status!='' and status!=null"><![CDATA[AND A.status = #{status}]]></if>
<if test="content!=null and content!=''"><![CDATA[AND A.content like #{content}]]></if>    
order by a.createtime desc
</select>

组合模糊dao
public Page<ImNoticeJiemu> findAllJiemu(Param param,Map<String,Object> map){
try {
return super.getPage(param, "com.kinglo.pojo.ImNoticeJiemu.findAllJiemu", map);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

action类

@RequestMapping("/findallJiemu.do")
public void findallJiemu(){
String userId=this.getParamNotNnll("userId2");
Map<String, Object> cemap = new HashMap<String, Object>();
cemap.put("id",userId);
User u = los.findeuser(cemap);
String qz=u.getCompanyCode();
Map<String, Object> map = new HashMap<String, Object>();
map.put("companycode",qz);
map.put("status",getParam("fstatus2"));
map.put("content","%"+(getParam( "fcontent2")==null?"":getParam("fcontent2"))+"%");
Param param=new Param(getPageNumber(),getMaxResult());
// Page<ImNoticeJiemu> page=imNoticeService.findAllNotice(param, map);
Page<ImNoticeJiemu> page=jiemuService.findAllJiemu(param, map);
JSONObject json=JSONObject.fromObject(page, JsonConfigDate.getCountSql());
this.outJSONDataString(json.toString());
}

//分页
var initPage2 = function(pageIndex2, maxResult2, queryStr2) {
var page2 = new Page("../../NoticeJiemu/findallJiemu.do", 'tab_2', showHTML2);
page2.init(pageIndex2, maxResult2, queryStr2);
};

var showHTML2 = function(data) {
if (data.totalPages == 0) {
$(".jmgg").html("");
$(".jmgg").html("<tr style='color:red;text-align:center'><td colspan='9'>没有找到您要查询的数据!</td></tr>");
} else {
var type = {"0" : "启用","1" : "禁用"};
var html = "";
$(data.list).each(function(id, item) {
html += "<tr>";
html += "<td>" + (id+1) + "</td>";
html += "<td>" + type[item.status] + "</td>";
html += "<td>" + item.content + "</td>";
html += "<td>" + item.createname + "</td>";
html += "<td>" + item.createtime+ "</td>";
html += "<td>" + item.updatename + "</td>";
html += "<td>" + item.updatetime+ "</td>";
html += "<td><a style='cursor:pointer' fid2="+item.id+" class='updatekeyword2'>修改</a><a style='cursor:pointer' did2="+item.id+" class='deletekeyword2'>删除</a></td>";
html += "</tr>";
});
$(".jmgg").html(html);
}
};

<div class="box" id="box_jiemu" style="display: none;">
<div class="hr"
style="height: 3px; margin-top: 3px; background: #0393D6"></div>
<div class="con">
<div class="scroll">
<div class="search">
<form id="blackListForm2">
<input type="hidden" name="userId2" id="userId2"/>
<table border="0" cellpadding="0" cellspacing="0"
style="width: 100%;">
<colgroup>
<col width="34%" />
<col width="30%" />
<col width="18%" />
<col width="18%" />
</colgroup>
<tbody style="padding: 0px 10px">
<tr style="background: #F0EEEE; height: 60px">

<td>
状态
<select name="fstatus2">
<option value="">请选择</option>
<option value="0">启用</option>
<option value="1">禁用</option>
</select>
</td>
<td>
内容
<input type="text" name="fcontent2" width="90px" />
</td>
<td>
<a href="javascript:;" class="btn" id="query2">查询</a>
<a href="javascript:;" class="btn" id="reset">重置</a>
</td>
</tr>
</tbody>
</table>
</form>
</div>
<div class="edit-list">
<a href="javascript:;" onclick="showBlackList2()" class="btn">添加</a>
</div>
<div class="tables"
style="min-height: 285px; height: auto !important; height: 285px;">
<table width="100%">
<col width="16%">
<col width="16%">
<col width="16%">
<col width="16%">
<col width="16%">
<col width="16%">
<col width="16%">
<col width="16%">
<thead>
<tr>
<th>
序号
</th>
<th>
状态
</th>
<th>
内容
</th>
<th>
创建人
</th>
<th>
创建时间
</th>
<th>
修改人
</th>
<th>
修改时间
</th>
<th>
操作
</th>
</tr>
</thead>
<tbody class="tbody jmgg"></tbody>
</table>
</div>
</div>
<div style="clear: both;"></div>
<div class="page tab_2" style="height: 40px">

</div>
</div>
</div>