1 概述
如下图,登录时间选择一个范围。
2 数据库表
表名:sys_logininfo。
字段:login_time。类型为datetime类型。
3 前台代码
F:\code\RuoYi-Vue-master\ruoyi-ui\src\views\monitor\logininfor\index.vue
搜索框里的登录日期:
<el-form-item label="登录时间"> <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" ></el-date-picker> </el-form-item>
展示的数据里的登录日期:
<el-table-column label="登录日期" align="center" prop="loginTime" sortable="custom" :sort-orders="['descending', 'ascending']" width="180"> <template slot-scope="scope"> <span>{{ parseTime(scope.row.loginTime) }}</span> </template> </el-table-column>
F:\code\RuoYi-Vue-master\ruoyi-ui\src\api\monitor\logininfor.js
export function list(query) { return request({ url: '/monitor/logininfor/list', method: 'get', params: query }) }
4 后台代码
控制器:F:\code\RuoYi-Vue-master\ruoyi-admin\src\main\java\com\ruoyi\web\controller\monitor\SysLogininforController.java
public TableDataInfo list(SysLogininfor logininfor) { startPage(); List<SysLogininfor> list = logininforService.selectLogininforList(logininfor); return getDataTable(list); }
实体类:F:\code\RuoYi-Vue-master\ruoyi-system\src\main\java\com\ruoyi\system\domain\SysLogininfor.java
/** 访问时间 */ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @Excel(name = "访问时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") private Date loginTime;
service接口类:F:\code\RuoYi-Vue-master\ruoyi-system\src\main\java\com\ruoyi\system\service\ISysLogininforService.java
public List<SysLogininfor> selectLogininforList(SysLogininfor logininfor);
service接口实现类:
/** * 查询系统登录日志集合 * * @param logininfor 访问日志对象 * @return 登录记录集合 */ @Override public List<SysLogininfor> selectLogininforList(SysLogininfor logininfor) { return logininforMapper.selectLogininforList(logininfor); }
mapper类:F:\code\RuoYi-Vue-master\ruoyi-system\src\main\java\com\ruoyi\system\mapper\SysLogininforMapper.java
/** * 查询系统登录日志集合 * * @param logininfor 访问日志对象 * @return 登录记录集合 */ public List<SysLogininfor> selectLogininforList(SysLogininfor logininfor);
XML:F:\code\RuoYi-Vue-master\ruoyi-system\src\main\resources\mapper\system\SysLogininforMapper.xml
<resultMap type="SysLogininfor" id="SysLogininforResult"> <id property="infoId" column="info_id" /> <result property="userName" column="user_name" /> <result property="status" column="status" /> <result property="ipaddr" column="ipaddr" /> <result property="loginLocation" column="login_location" /> <result property="browser" column="browser" /> <result property="os" column="os" /> <result property="msg" column="msg" /> <result property="loginTime" column="login_time" /> </resultMap> <select id="selectLogininforList" parameterType="SysLogininfor" resultMap="SysLogininforResult"> select info_id, user_name, ipaddr, login_location, browser, os, status, msg, login_time from sys_logininfor <where> <if test="ipaddr != null and ipaddr != ''"> AND ipaddr like concat('%', #{ipaddr}, '%') </if> <if test="status != null and status != ''"> AND status = #{status} </if> <if test="userName != null and userName != ''"> AND user_name like concat('%', #{userName}, '%') </if> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> AND login_time >= #{params.beginTime} </if> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> AND login_time <= #{params.endTime} </if> </where> order by info_id desc </select>
标签:逻辑,code,java,logininfor,登录,ruoyi,system,时间,RuoYi From: https://www.cnblogs.com/snow2021/p/17696176.html