1、displaytag如何实现获取到每行的id字段的值。
使用封装好的框架,有时候,对于一个知识点不熟悉,可能会浪费你大把的时间,我使用displaytag主要是使用它的分页技术,但是客户提出的需求,是获取到每行的id,然后选择一个用户名称(用户id),将他们关联操作,其实业务很简单,但是获取到你想要的这一行,一开始确实难为着我了,后来才发现,很简单。
代码如下所示:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="display" uri="http://displaytag.sf.net"%>
<%
//获取绝对路径路径
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath %>" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>图书管理-图书查询</title>
<link href="resource/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="resource/table/bootstrap-table.min.css">
<link type="text/css" rel="stylesheet" href="resource/select2/css/select2.min.css">
<script type="text/javascript" src="resource/js/jquery.min.js"></script>
<script type="text/javascript" src="resource/js/bootstrap.min.js"></script>
<script src="resource/table/bootstrap-table.min.js"></script>
<script type="text/javascript" src="resource/select2/js/select2.js"></script> <style type="text/css"> tr th{text-align:center;}
tr td{text-align:center;}
</style>
<script type="text/javascript">
$(document).ready(function(){
$("#clickIt").click(function(){
alert("sorry,此类图书数量为0,不可借阅......");
});
}); //启动之前,先查询出地方前置库信息,然后将地方前置库的信息传递到实例数据表中
$(function(){
var url = "system/book/userAjax";
$.ajax({
type : 'POST',
url : url,
dataType : 'json',
//traditional : true,
//async : false,
success : function(data) {
//console.log(data.list);
var result = data.list;
for(var i=;i<result.length;i++){
//console.log(result[i].userAccount);
$("#userNameCategory").append("<option value='"+ result[i].userId +"'>" + result[i].userAccount + "</option>");
}
}
})
}); function borrowBooksFunction(bookIds){
//关键点在于获取到图书的编号
console.log(bookIds);
//关键点,管理员通过借阅这本书给学生,将这本书的bookId给某个学生
$("#setBookId").val(bookIds);
} </script>
</head>
<body>
<div>
<ul class="breadcrumb" style="margin: 0px;">
<li>系统管理</li>
<li>图书管理</li>
<li>图书查询</li>
</ul>
</div>
<form action="${basePath }system/book/select" method="post" class="form-inline">
<div class="row alert alert-info" style="margin: 0px; padding: 5px;">
<div class="form-group">
<label>条件:</label>
<select name="condition" class="form-control">
<option value="bookName" ${condition == 'bookName'?'selected':'' }>图书名称</option>
<option value="bookAuthor" ${condition == 'bookAuthor'?'selected':'' }>图书作者</option>
<option value="bookType" ${condition == 'bookType'?'selected':'' }>图书类别</option>
</select>
<input type="text" name="content" value="${result }" class="form-control" placeholder="请输入查询条件" />
</div>
<input type="submit" class="btn btn-danger" value="查询">
<a href="system/book/insert" class="btn btn-success">
添加图书
</a>
</div>
<div class="row" style="padding: 15px;">
<display:table name="${list }" id="bookIds" pagesize="" requestURI="system/book/select" class="table table-hover table-striped table-bordered">
<display:column property="bookId" title="图书编号"></display:column>
<display:column property="bookName" title="图书名称"></display:column>
<display:column property="bookAuthor" title="图书作者"></display:column>
<display:column property="bookPrice" title="图书价格"></display:column>
<display:column property="bookType" title="图书类型"></display:column>
<display:column property="bookPublish" title="图书出版社"></display:column>
<display:column property="bookSum" title="图书总数"></display:column>
<!-- 如果是管理员,具有借书,还书,修改,删除功能的权限 -->
<c:if test="${userMark == '管理员' }">
<display:column paramId="bookId" paramProperty="bookId" title="借书">
<!-- 按钮触发模态框 -->
<a href="" id="borrowBooks" onclick="borrowBooksFunction(<c:out value='${bookIds.bookId}'></c:out>)" data-toggle="modal" data-target="#myModal"> 借书
</a>
</display:column>
<display:column href="system/book/update" paramId="bookId" paramProperty="bookId" title="修改" value="修改"></display:column>
<display:column href="system/book/delete" paramId="bookId" paramProperty="bookId" title="删除" value="删除"></display:column>
</c:if> </display:table>
</div>
</form> <form action="${basePath }system/book/adminBorrow" method="post" class="form-horizontal setWidth">
<!-- 模态框(Modal) -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
用户信息
</h4>
</div>
<div class="modal-body">
<input type="hidden" name="bookId" id="setBookId" value=""/>
<select class="form-control width175" id="userNameCategory" name="userId">
<option value=''>-- 请选择 --</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭
</button>
<!-- <button type="button" class="btn btn-primary">
提交
</button> -->
<input type="submit" class="btn btn-success" value="提交" />
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>
</form> </body>
</html>
效果如下所示:
2、关键点操作如下所示:
然后如下所示:
然后完成你想要实现的效果:
打完收工
待续......