filter实现访问时间段限制

先说一下,访问时间段的控制。

Visit_end_date    time    0    0    -1    0    0    0    0        0                    0    0
Visit_start_date    time    0    0    -1    0    0    0    0        0                    0    0
两个时间。  time 类型,也就是 时分秒。早上08:00:00    20:00:00这种格式

然后就是控制,弄个开关方便开发:

package com.unicom.sh.pom.filter;
@WebFilter(filterName = "sessionFilter", urlPatterns = "/*")
public class SessionFilter implements Filter, Serializable

我这边的类是直接拦截所有,可以看到。

 如果是on 就控制:直接上mapper.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="com.unicom.sh.pom.service.dao.EmplUserVisitdateMapper">
  <resultMap id="BaseResultMap" type="com.unicom.sh.pom.service.domain.EmplUserVisitdate">
    <result column="ID" jdbcType="INTEGER" property="id" />
    <result column="Visit_start_date" jdbcType="TIME" property="visitStartDate" />
    <result column="Visit_end_date" jdbcType="TIME" property="visitEndDate" />
  </resultMap>
  <select id="selectTime" resultMap="BaseResultMap">
    SELECT * from EMPL_USER_VisitDate t
    <![CDATA[
    where t.Visit_start_date >= curtime() and t.Visit_end_date <= curtime()
    ]]>
  </select>
</mapper>

这样就可以控制登录时间了,不在时间段不让登录。

/**
 *  不在登陆时间段内
 */
TIME_ERROR(888);

猜你喜欢

转载自blog.csdn.net/qq_39930369/article/details/86621217