SSM多表联查(注解/配置文件)
第一步:实体类
public class Contract {
private Integer cid;
private Integer lid;
private Integer hid;
private Integer ccash;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date ccreatetime;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date cstarttime;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date cendtime;
private Float ctotalmoney;
private Integer cstatus;
private Integer ctype;
private House house;
private Lessee lessee;
get,set,tostring,无参,有参就省略了!
第二步:Mapper.xml
<resultMap id="getAllMore" type="com.zhiyou100.entity.Contract" >
<id column="cid" property="cid" jdbcType="INTEGER" />
<result column="lid" property="lid" jdbcType="INTEGER" />
<result column="hid" property="hid" jdbcType="INTEGER" />
<result column="ccash" property="ccash" jdbcType="INTEGER" />
<result column="ccreateTime" property="ccreatetime" jdbcType="TIMESTAMP" />
<result column="cstartTime" property="cstarttime" jdbcType="TIMESTAMP" />
<result column="cendTime" property="cendtime" jdbcType="TIMESTAMP" />
<result column="ctotalmoney" property="ctotalmoney" jdbcType="REAL" />
<result column="cstatus" property="cstatus" jdbcType="INTEGER" />
<result column="ctype" property="ctype" jdbcType="INTEGER" />
<association property="house" column="hid" select="com.zhiyou100.mapper.HouseMapper.selectByPrimaryKey"/>
<association property="lessee" column="lid" select="com.zhiyou100.mapper.LesseeMapper.selectByPrimaryKey"/>
</resultMap>
第三步:Mapper.java
/**查询全部租赁合同并分页*/
@Select("select * from contract limit #{startIndex},#{pageSize}")
@ResultMap("getAllMore")
List<Contract> getContractAllByLimit(Info<Contract> contractInfo);
第四步:list.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>公寓管理系统 - 房屋信息管理</title>
<link rel="stylesheet" href="<c:url value="/css/main.css"/> ">
<link rel="stylesheet" href="<c:url value="/font-awesome/css/font-awesome.css"/>">
</head>
</head>
<body>
<div class="box">
<h3>租赁合同管理</h3>
<div class="actions">
<div>
<a class="btn btn-primary" href="<c:url value="/view/contract/add.jsp"/>">添加租赁合同</a>
</div>
</div>
<table class="list">
<tr>
<th>序号</th>
<th>租户姓名</th>
<th>房屋地址</th>
<th>押金</th>
<th>签署时间</th>
<th>开始时间</th>
<th>结束时间</th>
<th>总金额</th>
<th>状态</th>
<th>付款方式</th>
<th>操作</th>
</tr>
<c:forEach items="${list.list}" var="i" >
<tr>
<td>${i.cid}</td>
<td>${i.lessee.lname}</td>
<td>${i.house.haddress}</td>
<td>${i.ccash}</td>
<td>${i.ccreatetime.toLocaleString()}</td>
<td>${i.cstarttime.toLocaleString()}</td>
<td>${i.cendtime.toLocaleString()}</td>
<td>${i.ctotalmoney}</td>
<td>
<c:choose>
<c:when test="${i.cstatus==1 }">
有效
</c:when>
<c:otherwise>
无效
</c:otherwise>
</c:choose>
</td>
<td>${i.ctypeStr}</td>
<td>
<a class="fa fa-university" title="详情" href="<c:url value="/contract/getOneByCid.action?cid=${i.cid}"/>"></a>
<a class="fa fa-paint-brush" title="编辑" href="<c:url value="/contract/updateOneByCid.action?cid=${i.cid}"/>"></a>
<a class="fa fa-trash" title="删除" href="<c:url value="/contract/deleteOneByCid.action?cid=${i.cid}"/>" onclick="confirmDelete(1)"></a>
</td>
</tr>
</c:forEach>
</table>
<div class="pager-info">
<div>共有 ${list.count} 条记录,第 ${list.pageNumber}/${list.pageTotal} 页 </div>
<div>
<ul class="pagination">
<li class="paginate_button previous disabled }">
<a href="<c:url value="/contract/contractall.action?pageNumber=${list.pageNumber - 1}"/>">上一页</a>
</li>
<c:forEach var="i" begin="1" step="1" end="${list.pageTotal}">
<li class="paginate_button active"><a href="<c:url value="/contract/contractall.action?pageNumber=${i}"/>">${i}</a></li>
</c:forEach>
<li class="paginate_button next disabled">
<a href="<c:url value="/contract/contractall.action?pageNumber=${list.pageNumber+1}"/>">下一页</a>
</li>
</ul>
</div>
</div>
</div>
<script src="<c:url value="/bootstrap/js/jquery.js"/>"></script>
<script src="<c:url value="/bootstrap/js/bootstrap.js"/>"></script>
<script>
function confirmDelete(id){
if (confirm("确定要删除码?")) {
alert('发送删除请求,刷新页面(不要异步)');
}
return false;
}
</script>
</body>
</html>