jsp:
<table border="1" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA"
align="center" style="margin-top: 8px">
<tr class="green">
<!-- s.id,u.name,s.card_type,s.phone,s.record_date -->
<th>記錄id</th>
<th>姓名</th>
<th>持卡類型</th>
<th>部門名稱</th>
<th>打卡時間</th>
<th>聯繫電話</th>
<th>記錄日期</th>
</tr>
<c:forEach items="${ swipeRecordList }" var="sw">
<tr>
<td>${sw.id }</td>
<td>${sw.user.username}</td>
<td>${sw.cardType }</td>
<td>${sw.department.dName }</td>
<td>${sw.swipeTime }</td>
<td>${sw.phone }</td>
<td>${sw.recordDate }</td>
</tr>
</c:forEach>
</table>
mapper.xml:
<select id="selectSwipeRecord" resultMap="BaseResultMaps">
select r.id,u.username ,r.card_type,d.d_name,r.swipe_time,r.phone,r.record_date
from 201705swipe_record r
inner join user u on r.phone=u.phone
inner join department d on u.department_id=d.d_id
</select>
<resultMap type="com.mole.attendance.po.SwipeRecord" id="BaseResultMaps">
<id column="id" property="id" jdbcType="INTEGER" />
<result column="cards_number" property="cardsNumber" jdbcType="VARCHAR" />
<result column="card_type" property="cardType" jdbcType="VARCHAR" />
<result column="swipe_time" property="swipeTime"
jdbcType="VARCHAR" />
<result column="phone" property="phone" jdbcType="VARCHAR" />
<result column="image" property="image" jdbcType="VARCHAR" />
<result column="record_date" property="recordDate" jdbcType="TIMESTAMP" />
<association property="user" javaType="com.mole.attendance.po.User">
<id column="id" property="id" jdbcType="INTEGER"></id>
<result column="username" property="username" jdbcType="VARCHAR"/>
</association>
<association property="department" javaType="com.mole.attendance.po.Department">
<id column="d_id" property="dId" jdbcType="INTEGER"></id>
<result column="d_name" property="dName" jdbcType="VARCHAR" />
</association>
</resultMap>
dao:
List<SwipeRecord> selectSwipeRecord();
pojo:
public class SwipeRecord {
private Integer id;
private String cardsNumber;
private String cardType;
private String swipeTime;
private String phone;
private String image;
private Date recordDate;
private User user;
private Department department;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCardsNumber() {
return cardsNumber;
}
public void setCardsNumber(String cardsNumber) {
this.cardsNumber = cardsNumber;
}
public String getCardType() {
return cardType;
}
public void setCardType(String cardType) {
this.cardType = cardType;
}
public String getSwipeTime() {
return swipeTime;
}
public void setSwipeTime(String swipeTime) {
this.swipeTime = swipeTime;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public Date getRecordDate() {
return recordDate;
}
public void setRecordDate(Date recordDate) {
this.recordDate = recordDate;
}
@Override
public String toString() {
return "SwipeRecord [id=" + id + ", cardsNumber=" + cardsNumber
+ ", cardType=" + cardType + ", swipeTime=" + swipeTime
+ ", phone=" + phone + ", image=" + image + ", recordDate="
+ recordDate + ", user=" + user + ", department=" + department
+ "]";
}
public SwipeRecord() {
super();
}
public SwipeRecord(Integer id, String cardsNumber, String cardType,
String swipeTime, String phone, String image, Date recordDate,
User user, Department department) {
super();
this.id = id;
this.cardsNumber = cardsNumber;
this.cardType = cardType;
this.swipeTime = swipeTime;
this.phone = phone;
this.image = image;
this.recordDate = recordDate;
this.user = user;
this.department = department;
}
serviceImpl:
@Override
public List<SwipeRecord> selectSwipeRecord() {
return swipeRecordDao.selectSwipeRecord();
}
controller:
@RequestMapping("/selectSwipeRecord")
public String selectSwipeRecord(HttpServletRequest request,ModelMap modelMap){
List<SwipeRecord> swipeRecords = swipeRecordService.selectSwipeRecord();
modelMap.addAttribute("swipeRecordList", swipeRecords);
return "listAllSwipe";
}