框架:springmvc+mybatis
Java代码
@RequestMapping( method = { RequestMethod.POST, RequestMethod.GET } )
public String getPartnerConsultList( @RequestParam( value = "page", defaultValue = "1" ) int pageNumber,
@RequestParam( value = "page.size", defaultValue = PageUtil.PAGE_SIZE ) int pageSize, Model model,
HttpServletRequest request ) {
//根据页面传过来的数据转换成对象
PageCondition<PartnerConsult> pgc = ReflectionFromParamUtil.getPaginationObject( request, PartnerConsult.class );
//根据条件查询数据库
List<PartnerConsult> partnerConsults = prConsultService.findByCondition( pgc.getObj(),
new PageBounds( pageNumber, pageSize ) );
if( partnerConsults != null && partnerConsults.size() > 0 ) {
PageList<PartnerConsult> pageList = (PageList<PartnerConsult>)partnerConsults;
Paginator paginator = pageList.getPaginator();
model.addAttribute( "pageList", pageList );
model.addAttribute( "paginator", paginator );
}
model.addAttribute( "obj", pgc.getObj() );
model.addAttribute( "parentMenu", "operation" );
model.addAttribute( "childMenu", "partnerConsult" );
return "partnerConsult/list";
}
JSP:
<form id="presidentsForm" name="presidentsForm" action="${ctx}/acct/partnerConsult"
method="post" class="form-inline">
<div align="right">
<div class="form-group">
<input type="text" class="form-control" placeholder="姓名" name="name"
value="${obj.name }">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="公司名称" name="companyName"
value="${obj.companyName }">
</div>
<div class="form-group">
<select name="companyScale" class="form-control">
<c:if test="${!empty obj.companyScale }">
<option value="${obj.companyScale }">${obj.companyScale }</option>
</c:if>
<option value = "">公司规模</option>
<option value = "1~20人">1~20人</option>
<option value = "21~50人">21~50人</option>
<option value = "51~100人">51~100人</option>
<option value = "101~300人">101~300人</option>
<option value = "301~1000人">301~1000人</option>
<option value = "1001~5000人">1001~5000人</option>
<option value = "5000~50000人">5000~50000人</option>
</select>
</div>
<input class="btn btn-info" type="submit" value="查询" />
</div>
<table id="contentTable"
class="table table-striped table table-hover table-bordered table-condensed table-responsive">
<thead>
<tr>
<th><input type="checkBox" id="selectAll"></th>
<th>姓名</th>
<th>联系方式</th>
<th>公司名称</th>
<th>公司地址</th>
<th>公司规模</th>
<!-- <th>支付类型</th> -->
<th>公司描述</th>
<th>建议</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${pageList}" var="pageList">
<tr>
<td><input type="checkBox" name="checkBoxing" id="${pageList.id}"
value="${pageList.id}"></td>
<td><a title="${pageList.name }">${fn:substring(pageList.name,0,10)}..</a></td>
<td>
<span class="glyphicon glyphicon-phone-alt" title="${pageList.mobilePhone}" style="cursor:pointer;"></span>
<span class="glyphicon glyphicon-earphone" title="${pageList.phone}" style="cursor:pointer;"></span>
<span class="glyphicon glyphicon-envelope" title="${pageList.email}" style="cursor:pointer;"></span>
</td>
<td>
${pageList.companyName}
</td>
<td>${pageList.companyAddress}</td>
<td>${pageList.companyScale}</td>
<td><a title="${pageList.companyIntro }">${fn:substring(pageList.companyIntro,0,10)}..</a></td>
<td>
<a title="${pageList.suggest }">${fn:substring(pageList.suggest,0,10)}..</a></td>
<td>
<a href="${ctx}/acct/partnerConsult/details/${pageList.id}"><img src="${ctx}/images/acct/modify.jpg" title="详情" class="operate" ></a>
<a href="${ctx}/partnerConsult/delete/${pageList.id}" onclick="{if(confirm('确定要删除记录吗?')){return true;}return false;}"><img src="${ctx}/images/acct/delete.png" title="删除" class="operate" ></a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
<c:if test="${empty pageList}">
<div class="box_center">
<div class="left_img fl"><img src="${ctx}/images/personalinformation/adygao.png" /></div>
<div class="right_part fr">
<p class="font_weight">抱歉,没有找到符合条件的内容!</p>
<ul class="list_tip">
<li>建议您:</li>
<li>1.适当减少筛选条件,获得更多结果</li>
<li>2.尝试其他关键字</li><li>3.立即创建相应内容</li>
</ul>
</div>
</div>
</c:if>
<div style="text-align: right;">
<tags:paginationSort paginator="${paginator}" searchFormId="presidentsForm" />
</div>
</form>
XML
<select id="findByCondition" resultMap="BaseResultMap" parameterType="com.qiqi.chineseml.entity.PartnerConsult">
select
<include refid="Base_Column_List" />
from partner_consult
<where>
<if test="name!=null">
and name like "%"#{name,jdbcType=VARCHAR}"%"
</if>
<if test="companyName!=null">
and company_name = #{companyName,jdbcType=VARCHAR}
</if>
<if test="companyScale!=null">
and company_scale = #{companyScale,jdbcType=VARCHAR}
</if>
</where>
</select>
本文介绍了如何使用Spring MVC和MyBatis框架实现伙伴咨询列表的分页查询和详细展示,包括前端表单输入、数据库查询及分页逻辑、以及JSP页面的渲染。

557

被折叠的 条评论
为什么被折叠?



