【显示信息】
准备,下载eighth.zip并导入到eclipse,下载地址http://pan.baidu.com/s/1c2GaAFA。
同时,请导入Limy插件,Limy(eclipse_plugin).zip。下载完成后解压到eclipse的dropins目录下即可以使用。下载地址http://pan.baidu.com/s/1o6spOJS。(eclipse_plugins\Limy(eclipse_plugin).zip)
1,新规messages.properties(请使用Limy编辑)
I0000001=没有检索到结果。
2,修改users.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" />
<title>Users</title>
<meta
content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'
name='viewport' />
<meta th:replace="head-cssjs" />
</head>
<body class="skin-blue">
<div class="wrapper">
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>Users</h1>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-md-12">
<form id="usersInputForm" th:object="${usersInputForm}"
method="post" class="form-horizontal">
<div th:if="${sysMsg} != null" class="col-md-4"></div>
<div th:if="${sysMsg} != null"
class="calloutcustomized callout-success col-md-8"
style="margin-top: -28px;">
<p th:text="${sysMsg}"></p>
</div>
<div id="maincontent" class="box box-primary"
style="overflow-y: auto; overflow-x: hidden;">
<div class="box-body">
<div class="form-group">
<div class="col-md-12">
<div class="row">
<div class="col-md-12">
<table class="table-condensed"
style="border: 0; margin: 0; cellSpacing: 0; cellPadding: 0;">
<tr>
<td class="col-md-2">用户名</td>
<td class="col-md-2"><input type="text"
class="form-control" id="username"
th:field="*{username}" maxlength="20" /></td>
<td class="col-md-2"></td>
<td class="col-md-2"></td>
<td class="col-md-2"></td>
<td class="col-md-2"></td>
</tr>
</table>
</div>
</div>
<div class="row">
<div class="col-md-12">
<table class="table-condensed"
style="border: 0; margin: 0; cellSpacing: 0; cellPadding: 0;">
<tr>
<td class="col-md-2">
<button id="doSearch" type="button"
class="btn btn-primary" style="width: 150px">検索</button>
</td>
<td class="col-md-2"></td>
<td class="col-md-2"></td>
<td class="col-md-2"></td>
<td class="col-md-2"></td>
<td class="col-md-2"></td>
</tr>
</table>
</div>
</div>
<div th:if="${page} != null and ${ph} != null " class="row">
<div class="col-md-12">
<p class="pageList">
检索结果 <span th:text="${page.totalElements}"></span>件 <span
class="prev"
th:attr="style=${ph.hiddenFirst} ? 'visibility:hidden'"><a
class="js-pagenation"
th:href="@{/sample/users/show(page=0,size=${page.size})}"
id="searchIdFirst"><<</a></span> <span class="prev"
th:attr="style=${ph.hiddenPrev} ? 'visibility:hidden'"><a
class="js-pagenation"
th:href="@{/sample/users/show(page=${page.number - 1},size=${page.size})}"><</a></span>
<span th:text="${page.number + 1}"></span> / <span
th:text="${page.totalPages}"></span> 页 <span class="next"
th:attr="style=${ph.hiddenNext} ? 'visibility:hidden'"><a
class="js-pagenation"
th:href="@{/sample/users/show(page=${page.number + 1},size=${page.size})}">></a></span>
<span class="next"
th:attr="style=${ph.hiddenLast} ? 'visibility:hidden'"><a
class="js-pagenation"
th:href="@{/sample/users/show(page=${page.totalPages - 1},size=${page.size})}">>></a></span>
</p>
</div>
</div>
<div class="box box-success"
th:attrappend="style=${page == null ? 'display: none;' : ''}">
<div class="col-md-12" style="width: 99%;">
<table id="searchResult"
class="table table-condensed table-striped table-hover">
<thead>
<tr>
<th class="col-md-1">No.</th>
<th class="col-md-1">username</th>
<th class="col-md-1">password</th>
<th class="col-md-1">rolename</th>
</tr>
</thead>
<tbody>
<tr th:each="content, iterStat : ${page}">
<td class="col-md-1" th:id="${iterStat.index}"
th:name="${iterStat.index}"
th:value="${iterStat.index}"
th:text="${iterStat.index} + 1"></td>
<td class="col-md-1"
th:id="'page['+${iterStat.index}+'].username'"
th:name="'page['+${iterStat.index}+'].username'"
th:value="${content.username}"
th:text="${content.username}"></td>
<td class="col-md-1"
th:id="'page['+${iterStat.index}+'].password'"
th:name="'page['+${iterStat.index}+'].password'"
th:value="${content.password}"
th:text="${content.password}"></td>
<td class="col-md-1"
th:id="'page['+${iterStat.index}+'].rolename'"
th:name="'page['+${iterStat.index}+'].rolename'"
th:value="${content.rolename}"
th:text="${content.rolename}"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div th:if="${page} != null and ${ph} != null " class="row">
<div class="col-md-12">
<p class="pageList">
检索结果 <span th:text="${page.totalElements}"></span>件 <span
class="prev"
th:attr="style=${ph.hiddenFirst} ? 'visibility:hidden'"><a
class="js-pagenation"
th:href="@{/sample/users/show(page=0,size=${page.size})}"
id="searchIdFirst"><<</a></span> <span class="prev"
th:attr="style=${ph.hiddenPrev} ? 'visibility:hidden'"><a
class="js-pagenation"
th:href="@{/sample/users/show(page=${page.number - 1},size=${page.size})}"><</a></span>
<span th:text="${page.number + 1}"></span> / <span
th:text="${page.totalPages}"></span> 页 <span class="next"
th:attr="style=${ph.hiddenNext} ? 'visibility:hidden'"><a
class="js-pagenation"
th:href="@{/sample/users/show(page=${page.number + 1},size=${page.size})}">></a></span>
<span class="next"
th:attr="style=${ph.hiddenLast} ? 'visibility:hidden'"><a
class="js-pagenation"
th:href="@{/sample/users/show(page=${page.totalPages - 1},size=${page.size})}">>></a></span>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
</div>
<!-- ./wrapper -->
<div th:replace="bottom-js"></div>
<script th:inline="javascript">
/*<![CDATA[*/
$(document).ready(function() {
var table = $('#searchResult').DataTable({
scrollY : "390px",
scrollX : true,
scrollCollapse : true,
paging : false,
searching : false,
});
new $.fn.dataTable.FixedColumns(table, {
leftColumns : 1
});
$('.js-pagenation').each(function() {
$(this).click(function() {
$('#usersInputForm').attr('action', $(this).attr('href'));
$(this).attr('href', '#');
$('#usersInputForm').submit();
});
});
$('#usersInputForm').focus();
$('#doSearch').bind(
'click',
function() {
$('#usersInputForm').attr("action",
/*[[@{/sample/users/doSearch}]]*/);
$('#usersInputForm').submit();
});
});
/*]]>*/
</script>
</body>
</html>
3,修改UsersController.java
package org.com.sample.controller;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.com.common.paging.PagenationHelper;
import org.com.sample.dataset.Users;
import org.com.sample.facade.UsersFacade;
import org.com.sample.form.UsersInputForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/sample/users")
public class UsersController {
private static final Logger logger = LoggerFactory.getLogger(UsersController.class);
private static final int DEFAULT_PAGEABLE_SIZE = 10;
@Autowired
UsersFacade usersFacade;
@Autowired
MessageSource messageSource;
@RequestMapping(value = "/show", method = { RequestMethod.GET, RequestMethod.POST })
public String selectAllUser(@PageableDefault(page = 0, size = DEFAULT_PAGEABLE_SIZE) Pageable pageable,
Model model) {
// List<Users> userList = usersFacade.selectByExample(new
// UsersExample());
Map<String, Object> map = new HashMap<String, Object>();
map.put("start_line", pageable.getOffset() + 1);
map.put("end_line", (pageable.getPageNumber() + 1) * pageable.getPageSize());
map.put("orderByClause", "username asc");
map.put("form", new UsersInputForm());
Page<Users> page = usersFacade.selectUserListForPaging(map, pageable);
PagenationHelper ph = null;
if (page != null) {
ph = new PagenationHelper(page.getNumber(), page.getSize(), page.getTotalPages());
} else {
model.addAttribute("sysMsg", messageSource.getMessage("I0000001", null, Locale.getDefault()));
}
model.addAttribute("page", page);
model.addAttribute("ph", ph);
return "sample/users/users";
}
@RequestMapping(value = "/doSearch", method = { RequestMethod.GET, RequestMethod.POST })
public String doSearch(UsersInputForm form, BindingResult result,
@PageableDefault(page = 0, size = DEFAULT_PAGEABLE_SIZE) Pageable pageable, Model model) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("start_line", pageable.getOffset() + 1);
map.put("end_line", (pageable.getPageNumber() + 1) * pageable.getPageSize());
map.put("orderByClause", "username asc");
map.put("form", form);
Page<Users> page = usersFacade.selectUserListForPaging(map, pageable);
PagenationHelper ph = null;
if (page != null) {
ph = new PagenationHelper(page.getNumber(), page.getSize(), page.getTotalPages());
} else {
model.addAttribute("sysMsg", messageSource.getMessage("I0000001", null, Locale.getDefault()));
}
model.addAttribute("page", page);
model.addAttribute("ph", ph);
return "sample/users/users";
}
@ModelAttribute
public UsersInputForm getUsersInputForm() {
return new UsersInputForm();
}
}
4, 启动项目,输入URL,http://localhost:8888/sample/users/show
输入检索条件进行检索。
代码下载地址
http://pan.baidu.com/s/1c2GaAFA,ninth.zip