<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<pre><code>&lt;title&gt;普通用户管理系统 - 用户列表&lt;/title&gt;

&lt;!--全局CSS--&gt;
&lt;link href=&quot;/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;
&lt;link href=&quot;/css/bootstrap-dialog.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;link href=&quot;/css/bootstrapValidator.min.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;link href=&quot;/static/plugins/bootstrap_table/Content/bootstrap-table.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;!--全局JS--&gt;
&lt;script src=&quot;/js/jquery-2.1.4.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/js/bootstrap.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/static/plugins/bootstrap_table/Scripts/Bootstrap/ArbetTable.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/static/plugins/bootstrap_table/Scripts/Bootstrap/bootstrap-table.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/static/plugins/bootstrap_table/Scripts/Bootstrap/locale/bootstrap-table-zh-CN.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/static/plugins/layer/layer.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/static/plugins/laydate/laydate.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;!-- 对等js --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/static/js/main/userMgr/normalUser.js&quot;&gt;&lt;/script&gt;
</code></pre>
</head>
<body>
		<div id="position" class="Fixed_layer">
		   	<div class="controls-row" style="padding:20px;font-size:15px;font-weight: bold">
	   			邮箱地址:<input type="text" id="email" name="email" style="margin-left:5px;margin-right:10px" />
			   	昵称:<input type="text" id="nickName" name="email" style="margin-left:5px;margin-right:10px" />
			   	创建日期:<input type="text" id="createDate" name="email" style="margin-left:5px;margin-right:10px" autocomplete="off" />
			   	用户状态:
				   	<select style="margin-left:5px;" id="userState">
						<option  value ="0" selected = "selected">--- 启用 ---</option>
						<option  value ="1">--- 禁用 ---</option>
					</select>
<pre><code>		   	&lt;button class=&quot;btn btn-primary btn-sm glyphicon glyphicon-search&quot; name=&quot;userNormal_search&quot; style=&quot;margin-left:100px&quot; 
		   		onclick=&quot;userNormal_search()&quot;&gt;查询&lt;/button&gt;
			&lt;button class=&quot;btn btn-primary btn-sm glyphicon glyphicon-search&quot; name=&quot;userNormal_search&quot; style=&quot;margin-left:10px&quot; 
					onclick=&quot;shuaxin()&quot;&gt;刷新&lt;/button&gt;
		&lt;/div&gt;
		
		&lt;!-- 按钮功能组 --&gt;
		&lt;div class=&quot;controls controls-row&quot; style=&quot;padding: 15px; padding-left: 100px&quot;&gt;
			&lt;button class=&quot;btn btn-primary btn-sm glyphicon glyphicon-plus&quot; name=&quot;userNormal_add&quot; style=&quot;margin-left:10px;&quot; 
				onclick=&quot;userNormal_add()&quot;&gt;新增&lt;/button&gt;
			&lt;button class=&quot;btn btn-primary btn-sm glyphicon glyphicon-pencil&quot; name=&quot;userNormal_edit&quot; style=&quot;margin-left:10px;&quot; 
				onclick=&quot;userNormal_edit()&quot;&gt;修改&lt;/button&gt;
			&lt;button class=&quot;btn btn-primary btn-sm glyphicon glyphicon-minus&quot; name=&quot;userNormal_delete&quot; style=&quot;margin-left:10px;&quot;  
				onclick=&quot;userNormal_delete()&quot;&gt;删除&lt;/button&gt;
		&lt;/div&gt;
	&lt;/div&gt;

&lt;!-- 用户管理模块-普通用户 --&gt;
&lt;table id=&quot;userNormalTable&quot;&gt;&lt;/table&gt;
</code></pre>
</body>
	<script type="text/javascript">
		//日期和时间选择器
		laydate.render({
		  elem: '#createDate',
		  type: 'datetime'
		});
	</script>
</html>
//初始化参数
var id;
var email;
var nickName;
var userState;
var createDate;
<p>//初始化表格的列
userNormal_initColumn = function () {
var columns = [
{field: 'selectItem', radio: true, visible: true},
{title: 'id', field: 'id', visible: true, align: 'center', valign: 'middle'},
{title: '邮箱地址', field: 'email', visible: true, align: 'center', valign: 'middle', sortable: true},
{title: '昵称', field: 'nickName', visible: true, align: 'center', valign: 'middle', sortable: true},
{title: '用户状态', field: 'userState', align: 'center', valign: 'middle', sortable: true,
formatter: function (value, row, index) {
if(value == 0){
return &quot;启用&quot;;
}
else{
return &quot;禁用&quot;;
}
}},
{title: '创建日期', field: 'createDate', align: 'center', valign: 'middle', sortable: true},</p>
<pre><code>];
return columns;
</code></pre>
<p>};</p>
<p>/**</p>
<ul>
<li>检查是否选中
*/
userNormal_check = function () {
//获得row数组
var rows = $(&quot;#userNormalTable&quot;).bootstrapTable('getSelections');
if (rows.length == 0) {
return false;
} else {
return true;
}
};</li>
</ul>
<p>//删除
userNormal_delete = function () {
if(userNormal_check()){
//获得当前选中行对象
var rows = $(&quot;#userNormalTable&quot;).bootstrapTable('getSelections');
//获得选中id
var id = rows[0].id;
//发送ajax执行删除
$.ajax({
url:&quot;/user/remove&quot;,
type:&quot;POST&quot;,
data:{&quot;id&quot;:id},
success:function(data){
//成功操作
if(data == true){
layer.msg(&quot;删除成功&quot;);
$(&quot;#userNormalTable&quot;).bootstrapTable('refresh');
}
//失败操作
else{
layer.msg(&quot;删除失败&quot;);
}
},
dataType:&quot;json&quot;
});
}
else{
layer.msg(&quot;请先选中至少一条记录!&quot;);
}
};</p>
<p>//添加
userNormal_add = function(){
var index = layer.open({
type: 2,
title: '添加用户',
area: ['500px', '460px'], //宽高
fix: false, //不固定
maxmin: true,
content:  '/static/page/main/userMgr/normalUser_add.jsp'
});
this.layerIndex = index;
}</p>
<p>//修改
userNormal_edit = function(){
if(userNormal_check()){
//获得当前选中行对象
var rows = $(&quot;#userNormalTable&quot;).bootstrapTable('getSelections');
//获得参数
var id = rows[0].id;
var nickName = rows[0].nickName;
var userState = rows[0].userState;
var createDate = rows[0].createDate;
var index = layer.open({
type: 2,
title: '修改用户',
area: ['500px', '490px'], //宽高
fix: false, //不固定
maxmin: true,
content:  '/static/page/main/userMgr/normalUser_edit.jsp',
data:{
id:id,
nickName:nickName,
userState: userState,
createDate:createDate
},
});
this.layerIndex = index;
}
else{
layer.msg(&quot;请先选中至少一条记录!&quot;);</p>
<pre><code>}
</code></pre>
<p>}</p>
<p>//收集参数
function collectParam(){
email = $(&quot;#email&quot;).val();
nickName = $(&quot;#nickName&quot;).val();
createDate = $(&quot;#createDate&quot;).val();
userState = $(&quot;#userState&quot;).val();
}
/<em>//收集参数
function collectParam(){
email = $(&quot;#email&quot;).val();
if(email == &quot;&quot;){
email = null;
}
nickName = $(&quot;#nickName&quot;).val();
if(nickName == &quot;&quot;){
nickName = null;
}
createDate = $(&quot;#createDate&quot;).val();
if(createDate == &quot;&quot;){
createDate = null;
}
userState = $(&quot;#userState&quot;).val();
if(userState == &quot;&quot;){
userState = null;
}
}</em>/</p>
<p>//BootStrap查询
function userNormal_search() {
//收集参数
collectParam();
var opt = {
url: &quot;/user/queryCondition&quot;,
silent: true,//静态刷新
query:{//传入url里的参数
email: email,
nickName: nickName,
createDate: createDate,
userState: userState,
}
};
$(&quot;#userNormalTable&quot;).bootstrapTable('refresh',opt);</p>
<p>};
function shuaxin() {
location.reload();
}
$(function(){
var column =  userNormal_initColumn();
$(&quot;#userNormalTable&quot;).bootstrapTable({
contentType: &quot;application/x-www-form-urlencoded&quot;,
url: '/user/queryList',
method: 'post',				//ajax方式,post还是get
//toolbar: &quot;#toolbar&quot;,		//顶部工具条
striped: true,     			//是否显示行间隔色
cache: false,      			//是否使用缓存,默认为true
sortable: true,      		//是否启用排序
sortOrder: &quot;desc&quot;,     		//排序方式
pagination: true,			//启用分页
pageNumber: 1,      			//初始化加载第一页,默认第一页
pageSize: 5,      			//每页的记录行数(<em>)
pageList: [5, 10, 15,'All'],  	//可供选择的每页的行数(</em>)
queryParamsType: 'limit', 	//默认值为 'limit' ,在默认情况下 传给服务端的参数为:offset,limit,sort
queryParams:{&quot;param&quot;:&quot;testData&quot;},  	// 向后台传递的自定义参数
sidePagination: &quot;client&quot;,   //分页方式:client客户端分页,server服务端分页(*)
search: false,      		//是否显示表格搜索,此搜索是客户端搜索,不会进服务端
strictSearch: true,			//设置为 true启用 全匹配搜索,否则为模糊搜索
showColumns: false,     		//是否显示所有的列
showRefresh: false,     		//是否显示刷新按钮
minimumCountColumns: 2,    	//最少允许的列数
clickToSelect: true,    	//是否启用点击选中行
searchOnEnterKey: true,		//设置为 true时,按回车触发搜索方法,否则自动触发搜索方法//pagination: true,			//是否显示分页条
height: 365,				//底部栏高
/<em>customSearch:customSearch,//自定义搜索,比如只搜索ID字段</em>/
icons: {
refresh: 'glyphicon-repeat',
toggle: 'glyphicon-list-alt',
columns: 'glyphicon-list'
},
iconSize: 'outline',
columns:column,//列数组
});
/<em>function customSearch(data, text) {
//获得当前选中行对象
var rows = $(&quot;#userNormalTable&quot;).bootstrapTable('getSelections');
//返回参数
return data.filter(function (rows) {
return (rows[0].id+&quot;&quot;).indexOf(text) &gt; -1
})
}</em>/
});
为什么查询出来的createDate值为2023-04-09 01:34:35.0,为什么多出来个.0,怎么修改内容:这是因为在Java中,日期时间类型的值会被转换为带有小数点的数字类型,例如在Java中日期时间类型的值2023-04-09 01:34:35会被转换为一个long类型的数字,而在JavaScript中无法直接表示long类型的数字,因此在传输过程中会被转换为带有小数点的数字类型。</p>
<p>要解决这个问题,可以在前端代码中对日期时间类型的值进行格式化处理,去掉小数点后的部分。例如,在页面中添加以下代码:</p>
<p>//格式化日期时间类型的值
function formatDate(value) {
if (value != null) {
var date = new Date(value);
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
return year + &quot;-&quot; + month + &quot;-&quot; + day + &quot; &quot; + hour + &quot;:&quot; + minute + &quot;:&quot; + second;
} else {
return &quot;&quot;;
}
}</p>
<p>然后在页面中调用该函数对日期时间类型的值进行格式化处理,例如:</p>
<p>{title: '创建日期', field: 'createDate', align: 'center', valign: 'middle', sortable: true,
formatter: function (value, row, index) {
return formatDate(value);
}
}</p>
<p>这样就可以去掉日期时间类型的值中的小数点部分,只显示日期时间。</p>
普通用户管理系统 - 用户列表

原文地址: https://www.cveoy.top/t/topic/ngCE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录