jquery easyui mybaties数据库显示datagrid、时间格式转换、查询功能

1.systemLogRecord.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!-- gr [email protected] 2014.6.20-->
<style type="text/css">
	#la{margin-left:10px;}
	#log_search{margin-left:10px;}
</style>
<script type="text/javascript" src="${ctx}/js/Municipal/systemLogRecord.js"></script>
	<div class="easyui-layout" data-options="fit:true"  style="width:100%;height:100%;">
	    <!-- 显示按钮-->
		<div id="log_north" data-options="region:'north'" style="height:30%">
			<form id="logFrom5">
				<table>
					<tr>
						<td nowrap><label id="la">用户名:</label>&nbsp;&nbsp;<input  id="operatoruser" name ="operatoruser"  class="easyui-validatebox" validType="reg[/^[a-zA-Z0-9\u4e00-\u9fa5]*$/,'不能包含特殊字符!']" onblur="this.value = checkcode(this.value)" style="width:120px;heigth:20px;border:1px solid #DAEEF5;"/></td>
						<td nowrap><label>施工许可证号:</label>&nbsp;&nbsp;<input  id="dataid" name ="dataid"  class="easyui-validatebox" validType="reg[/^[a-zA-Z0-9/[\]\u4e00-\u9fa5]*$/,'不能包含特殊字符!']" onblur="this.value = checkcode(this.value)" style="width:120px;heigth:20px;border:1px solid #DAEEF5;"/></td>
<!-- 						<td><input type="text" name="aa"></td> -->
						<td nowrap>
							<a id="log_search" href="javascript:logSearch()" class="easyui-linkbutton"  data-options="iconCls:'icon-search'" >查询</a>&nbsp;
						    <a href="javascript:logClear()" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" >清空</a>
<!-- 							<a href="javascript:deletelogUnit()" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" >删除</a> -->
						</td>
					</tr>
				</table>
			</form> 
		</div>
	    <div data-options="region:'center',iconCls:'icon-ok'">
		    <!-- 显示日志信息 -->
			<table id="log_Unit"></table>  
	    </div>
	</div>

 

2.systemLogRecord.js

//gr [email protected] 2014.4.28
$(function() { 
	$('#log_Unit').datagrid({   
	    url:'/QXFL/logUnite.htm?type=1',
	    border : false,
		pagination : true,// 是否分页
		pageSize : 12,//条数
		pageList : [ 3, 6, 12, 24 ],//选择条数
//		fitColumns : true,//小自动适应格式
		fit : true,//大自动适应
		//分页end
//		sortName:'tbrq',//根据填报日期排序
//		sortOrder:desc,//定义排序顺序,可以是'asc'或者'desc'(正序或者倒序)。
		idField : 'logid',// 很重要 表明该列是一个唯一列。
//		checkOnSelect : true,
		selectOnCheck : true,//如果设置为true,单击一个复选框,将始终选择行。如果为false,不会选择行选中该复选框。
//		singleSelect : true,//设置为true将只允许选择一行。	
	    columns:[[   
//	        {
//	        	checkbox:true,//复选框
////		        hidden:true //默认不显示
//	        },
	        {
		        field:'operatoruser',
		        title:'用户名',
		        width:90
	        },{
		        field:'operatortype',
		        title:'操作类型',
		        width:160,
	        },{
		        field:'time1',
		        title:'时间',
		        width:130,
	        },{
		        field:'datatype',
		        title:'数据类型',
		        width:100,
	        },{
		        field:'executionresults',
		        title:'执行结果',
		        width:80,
	        },{
		        field:'dataid',
		        title:'施工许可证号',
		        width:130,
	        }
//	        ,{
//				field : 'logid',//建设单位法定代表人(必须用数据库属性表中有的字段,替换成按钮)
//				title : '删除',
//				width : 150,
//				formatter : function(value, rowData,
//						rowIndex) {										   
//					return '<img src="/QXFL/js/jquery-easyui-1.3.3/themes/icons/cancel.png" title="删除"  onclick="deleteSysLog();"/>';
//				}
//			} 
	    ]]   
	});  
});
//日志查询方法
function logSearch() {
	$('#log_Unit').datagrid('load',zy.serializeObject($('#logFrom5')));
} 
//清除方法
function logClear() {
//	 document.getElementById("shzt").value="全部";
//	 $('#jsgcszqx').combobox('setValue','全部区县');
//	 document.getElementById("GCMC").value="";
	 document.getElementById("operatoruser").value="";
	 document.getElementById("dataid").value="";
	 $('#log_Unit').datagrid('load', {});
}
//删除本行
//function deleteSysLog(value,rowIndex,rowData) {
//	
//}
//function deleteUserTowns(){
//	var selectedRows=$("#u_dgTowns").datagrid('getSelections');
//	var row = selectedRows[0];
//	if(selectedRows.length==0){
//		$.messager.alert("系统提示","请选择要删除的数据!");
//		return;
//	}
//	$.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗?",function(r){
//		if(r){
////			alert("真删啊"+row.name);
//			$.post('/QXFL/deleteUserTowns.htm?type=2&name='+row.name,function(data){
//				if(data == true) {
//		        	$.messager.alert('提示','删除成功!')
//		        	$('#u_dgTowns').datagrid('load', {});//刷新datagrid
//		        }else {
//		        	$.messager.alert('提示','删除失败!');
//		        }
//			},"json");
//		}else {
////			alert("删除取消");
//		}
//	});
//}
/*//责任单位用户-删除选中行
function deleteUserUnit(){
	var selectedRows=$("#u_dgUnit").datagrid('getSelections');
	var row = selectedRows[0];
	if(selectedRows.length==0){
		$.messager.alert("系统提示","请选择要删除的数据!");
		return;
	}
	$.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗?",function(r){
		if(r){
//			alert("真删啊"+row.name);
			$.post('/QXFL/deleteUserUnit.htm?type=5&name='+row.name,function(data){
				if(data == true) {
		        	$.messager.alert('提示','删除成功!')
		        	$('#u_dgUnit').datagrid('load', {});//刷新datagrid
		        }else {
		        	$.messager.alert('提示','删除失败!');
		        }
			},"json");
		}else {
//			alert("删除取消");
		}
	});
}*/

 3.UserControler

package org.bjits.controller;


import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.security.NoSuchAlgorithmException;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.bjits.dao.Permissions_qxjMapper;
import org.bjits.dao.Roles_permissions_qxjMapper;
import org.bjits.dao.Roles_qxjMapper;
import org.bjits.model.Roles_permissions_qxj;
import org.bjits.model.Permissions_qxj;
import org.bjits.model.Roles_qxj;
import org.bjits.model.Sgxkz_qxj;
import org.bjits.model.User;
import org.bjits.realm.CaptchaUsernamePasswordToken;
import org.bjits.service.UserService;
import org.bjits.util.CodeUtil;
import org.bjits.util.DataGrid;
import org.bjits.util.mail.emailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;


@Controller
//@RequestMapping("/UserControler")
public class UserControler extends BaseController{
	
	@Autowired
	private UserService userService;//用户的service接口
	
	@Autowired
	private Roles_qxjMapper roles_qxjMapper;//mybaities反向生成的roles_qxjMapper
	
	@Autowired
	private Permissions_qxjMapper permissions_qxjMapper;//权限
	
	@Autowired
	private Roles_permissions_qxjMapper roles_permissions_qxjMapper;//权限
/**
			 * 系统日志记录
			 */ 
			@RequestMapping(value = "/logUnite")
			//转码@ResponseBody
			public @ResponseBody DataGrid logUnite(HttpServletRequest request,HttpServletResponse response,@RequestParam("type")String type ) {
				String page = request.getParameter("page");//页数
				String rows = request.getParameter("rows");//每页显示几条
//				String sort = request.getParameter("sort");//排序
//				String order = request.getParameter("order");//升序降序
//				String name = request.getParameter("name");//主见查询用的
				String operatoruser = request.getParameter("operatoruser");//获取页面上的用户名文本框
				String dataid = request.getParameter("dataid");//获取施工许可证号
				int role = 4;//市级用户对应角色表id是4,先写死了。
				Map map = new HashMap();
				if(type.equals("1")) {//type为1 的时候是系统日志
					map.put("type", 1);
				}
				if(type.equals("2")) {//type为2的时候是用户日志
					map.put("type", 2);
				}
				if(operatoruser != null && !"".equals(operatoruser)) {
					map.put("operatoruser", "%"+operatoruser+"%");
				}
				if(dataid != null && !"".equals(dataid)) {
					map.put("dataid", "%"+dataid+"%");
				}
				DataGrid dg = (DataGrid)userService.getLogUnit(Integer.valueOf(page),Integer.valueOf(rows),role,map);//调用接口中的dataGrid方法
//				writeJson(dg, response);//返回给页面
				return dg;
			}
}

 4.UserService

package org.bjits.service;

import java.util.List;
import java.security.NoSuchAlgorithmException;
import java.util.Map;

import org.bjits.model.Log_qxj;
import org.bjits.model.Permissions_qxj;
import org.bjits.model.User;
import org.bjits.util.DataGrid;
import org.springframework.stereotype.Service;

@Service("UserService")
public interface UserService {
/**
	 * 系统操作日志
	 * @param page
	 * @param rows
	 * @param role
	 * @param map
	 * @return
	 */
	DataGrid getLogUnit(int page, int rows, int role, Map map);

}

 5.UserServiceImpl

package org.bjits.service.impl;

import java.security.NoSuchAlgorithmException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.bjits.dao.Flgcxxb_qxjMapper;
import org.bjits.dao.Log_qxjMapper;
import org.bjits.dao.Permissions_qxjMapper;
import org.bjits.dao.UserMapper; 
import org.bjits.dao.User_permissions_qxjMapper;
import org.bjits.model.Log_qxj;
import org.bjits.model.Permissions_qxj;
import org.bjits.model.Sgxkz_qxj;
import org.bjits.model.User;
import org.bjits.model.User_permissions_qxj;
import org.bjits.service.UserService;
import org.bjits.util.CodeUtil;
import org.bjits.util.DataGrid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("UserService")
public class UserServiceImpl implements UserService{
	@Autowired
	UserMapper userMapper;
	@Autowired
	Permissions_qxjMapper permissions_qxjMapper;
	@Autowired
	User_permissions_qxjMapper user_permissions_qxjMapper;
	@Autowired
	Log_qxjMapper log_qxjMapper;
	@Autowired
	Flgcxxb_qxjMapper flgcxxb_qxjMapper;
//系统操作用户日志
	@Override
	public DataGrid getLogUnit(int page, int rows, int role, Map map) {
		// TODO Auto-generated method stub
		DataGrid dg = new DataGrid();
		//开始记录数
		int start=(page-1)*rows;
		//结束记录数
		map.put("start", start);
		map.put("end", rows);
		map.put("role", role);
		List<Log_qxj> list=log_qxjMapper.getSysLogData(map);//根据角色id返回区县级用户列表
		for(Log_qxj log_qxj:list) {
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd");//格式化时间
			if(null != log_qxj.getTime()) {
				log_qxj.setTime1(df.format(log_qxj.getTime()));//属性中创建了一个虚拟的time1对象,将从数据库中获取的time值付给虚拟的time1传给页面,实现时间格式的转换
			}
		}
//		for(int i=0;i<list.size();i++) {
//			DateFormat df = new SimpleDateFormat("yyyy-MM-dd");//格式化时间
//			Log_qxj log_qxj = list.get(i);
//			if(null != log_qxj.getTime()) {
//				log_qxj.setTime1(df.format(log_qxj.getTime()));//属性中创建了一个虚拟的time1对象,将从数据库中获取的time值付给虚拟的time1传给页面,实现时间格式的转换
//			}
//		}
//		for(int i=0;i<list.size();i++) {
//			DateFormat df = new SimpleDateFormat("yyyy-MM-dd");//格式化时间
////			Log_qxj log_qxj = list.get(i);
//			if(null != list.get(i).getTime()) {
//				list.get(i).setTime1(df.format(list.get(i).getTime()));//属性中创建了一个虚拟的time1对象,将从数据库中获取的time值付给虚拟的time1传给页面,实现时间格式的转换
//			}
//		}
		int totals=log_qxjMapper.getSysLogCount(map);//分页获得总页数
		dg.setTotal(totals);//总记录数
		dg.setRows(list);//将集合付给DataGrid对象
	 	return dg;
	}
}

 6.Log_qxjMapper

package org.bjits.dao;

import java.util.List;
import java.util.Map;

import org.bjits.model.Log_qxj;
import org.bjits.model.User;

public interface Log_qxjMapper {
    int insert(Log_qxj record);

    int insertSelective(Log_qxj record);

	List<Log_qxj> getSysLogData(Map map);//系统日志返回dataGrid

	int getSysLogCount(Map map);//系统日志放回dataGrid总数

}

 7.Log_qxjMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.bjits.dao.Log_qxjMapper" >
  <resultMap id="BaseResultMap" type="org.bjits.model.Log_qxj" >
    <result column="logid" property="logid" jdbcType="BIGINT" />
    <result column="operatoruser" property="operatoruser" jdbcType="VARCHAR" />
    <result column="operatortype" property="operatortype" jdbcType="VARCHAR" />
    <result column="time" property="time" jdbcType="TIMESTAMP" />
    <result column="datatype" property="datatype" jdbcType="VARCHAR" />
    <result column="executionresults" property="executionresults" jdbcType="VARCHAR" />
    <result column="dataid" property="dataid" jdbcType="VARCHAR" />
  </resultMap>
  <insert id="insert" parameterType="org.bjits.model.Log_qxj" >
    insert into log_qxj ( operatoruser, operatortype, 
      time, datatype, executionresults, 
      dataid)
    values ( #{operatoruser,jdbcType=VARCHAR}, #{operatortype,jdbcType=VARCHAR}, 
      #{time,jdbcType=TIMESTAMP}, #{datatype,jdbcType=VARCHAR}, #{executionresults,jdbcType=VARCHAR}, 
      #{dataid,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="org.bjits.model.Log_qxj" >
    insert into log_qxj
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="logid != null" >
        logid,
      </if>
      <if test="operatoruser != null" >
        operatoruser,
      </if>
      <if test="operatortype != null" >
        operatortype,
      </if>
      <if test="time != null" >
        time,
      </if>
      <if test="datatype != null" >
        datatype,
      </if>
      <if test="executionresults != null" >
        executionresults,
      </if>
      <if test="dataid != null" >
        dataid,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="logid != null" >
        #{logid,jdbcType=BIGINT},
      </if>
      <if test="operatoruser != null" >
        #{operatoruser,jdbcType=VARCHAR},
      </if>
      <if test="operatortype != null" >
        #{operatortype,jdbcType=VARCHAR},
      </if>
      <if test="time != null" >
        #{time,jdbcType=TIMESTAMP},
      </if>
      <if test="datatype != null" >
        #{datatype,jdbcType=VARCHAR},
      </if>
      <if test="executionresults != null" >
        #{executionresults,jdbcType=VARCHAR},
      </if>
      <if test="dataid != null" >
        #{dataid,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <!--  转义框架<![CDATA[]]> -->
  <select id="getSysLogData" parameterType="map" resultMap="BaseResultMap">
  	select * from log_qxj l1 where 1=1 
  		<if test="operatoruser != null" >
        and l1."operatoruser"like #{operatoruser} 
        </if>
        <if test="dataid != null" >
        and l1."dataid"like #{dataid}
        </if>
  		<if test="type == 1">
        	<![CDATA[and l1."dataid"<>'']]>
        </if>
  		<if test="type == 2">
        	<![CDATA[and l1."dataid"='']]>
        </if>
	  	order by l1."logid" desc
	  	limit #{end} offset #{start} 
  </select>
  <select id="getSysLogCount" parameterType="map" resultType="int">
  	select count (*) from log_qxj l1 where 1=1 
  	    <if test="operatoruser != null" >
        and l1."operatoruser"like #{operatoruser} 
        </if>
        <if test="dataid != null" >
        and l1."dataid"like #{dataid}
        </if>
        <if test="type == 1">
        	<![CDATA[and l1."dataid"<>'']]>
        </if>
  		<if test="type == 2">
        	<![CDATA[and l1."dataid"='']]>
        </if>
  </select>
</mapper>

 

你可能感兴趣的:(jquery easyui)