首页 > 其他 > 详细

使用IDEA创建SSM程序框架(五)

时间:2020-05-12 18:18:20      阅读:78      评论:0      收藏:0      [点我收藏+]

目的:

1.加入日志

2.加入shrio进行权限的判定

代码:

1.log参数文件

log4j.rootLogger=debug,stdout,info,debug,warn,error 
#console
log4j.appender.stdout.target=System.out
log4j.appender.stdout.Threshold = ERROR    
log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 
log4j.appender.stdout.layout.ConversionPattern= [%d{yyyy-MM-dd HH:mm:ss a}]:%p %l%m%n
#info log
log4j.logger.info=info
log4j.appender.info=org.apache.log4j.DailyRollingFileAppender 
log4j.appender.info.DatePattern=‘_‘yyyy-MM-dd‘.log‘
log4j.appender.info.File=d:/logs/info.log
log4j.appender.info.Append=true
log4j.appender.info.Threshold=INFO
log4j.appender.info.layout=org.apache.log4j.PatternLayout 
log4j.appender.info.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c >> Method: %l ]%n%p:%m%n
#debug log
log4j.logger.debug=debug
log4j.appender.debug=org.apache.log4j.DailyRollingFileAppender 
log4j.appender.debug.DatePattern=‘_‘yyyy-MM-dd‘.log‘
log4j.appender.debug.File=d:/logs/debug.log
log4j.appender.debug.Append=true
log4j.appender.debug.Threshold=DEBUG
log4j.appender.debug.layout=org.apache.log4j.PatternLayout 
log4j.appender.debug.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c >> Method: %l ]%n%p:%m%n
#warn log
log4j.logger.warn=warn
log4j.appender.warn=org.apache.log4j.DailyRollingFileAppender 
log4j.appender.warn.DatePattern=‘_‘yyyy-MM-dd‘.log‘
log4j.appender.warn.File=d:/logs/warn.log
log4j.appender.warn.Append=true
log4j.appender.warn.Threshold=WARN
log4j.appender.warn.layout=org.apache.log4j.PatternLayout 
log4j.appender.warn.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c >> Method: %l ]%n%p:%m%n
#error
log4j.logger.error=error
log4j.appender.error = org.apache.log4j.DailyRollingFileAppender
log4j.appender.error.DatePattern=‘_‘yyyy-MM-dd‘.log‘
log4j.appender.error.File = d:/logs/error.log 
log4j.appender.error.Append = true
log4j.appender.error.Threshold = ERROR 
log4j.appender.error.layout = org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss a} [Thread: %t][ Class:%c >> Method: %l ]%n%p:%m%n

2.pom.xml中加入

<slf4j.version>1.7.25</slf4j.version>
 <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${slf4j.version}</version>
    </dependency>

3.引用

private static org.apache.log4j.Logger log=org.apache.log4j.Logger.getLogger(LoginController.class);


        logger.info("home");
        logger.debug("home");
        logger.error("home");

4.查看设置目录下是否存在文件

技术分享图片

 

 5.创建spring-shiro.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <!-- 缓存管理器 使用Ehcache实现 -->
    <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
        <property name="cacheManagerConfigFile" value="classpath:ehcache/ehcache-shiro.xml"/>
    </bean>

    <!-- 凭证匹配器 -->
    <bean id="credentialsMatcher" class="com.liuhy.ssm.credentials.RetryLimitHashedCredentialsMatcher">
        <!-- 使用Spring构造器注入cacheManager -->
        <constructor-arg ref="cacheManager"/>
        <!-- 指定散列算法名称 -->
        <property name="hashAlgorithmName" value="md5"/>
        <!-- 指定散列迭代的次数 -->
        <property name="hashIterations" value="2"/>
        <!-- 是否储存散列后的密码为16进制,需要和生成密码时的一样,默认是base64 -->
        <property name="storedCredentialsHexEncoded" value="true"/>
    </bean>

    <!-- Realm实现 -->
    <bean id="userRealm" class="com.liuhy.ssm.realm.UserRealm">
        <!-- 使用credentialsMatcher实现密码验证服务 -->
        <property name="credentialsMatcher" ref="credentialsMatcher"/>
        <!-- 是否启用缓存 -->
        <property name="cachingEnabled" value="true"/>
        <!-- 是否启用身份验证缓存 -->
        <property name="authenticationCachingEnabled" value="true"/>
        <!-- 缓存AuthenticationInfo信息的缓存名称 -->
        <property name="authenticationCacheName" value="authenticationCache"/>
        <!-- 是否启用授权缓存,缓存AuthorizationInfo信息 -->
        <property name="authorizationCachingEnabled" value="true"/>
        <!-- 缓存AuthorizationInfo信息的缓存名称 -->
        <property name="authorizationCacheName" value="authorizationCache"/>
    </bean>

    <!-- 会话ID生成器,用于生成会话的ID,使用JavaScript的UUID生成 -->
    <bean id="sessionIdGenerator" class="org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator"/>

    <!-- 会话Cookie模板 -->
    <bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
        <constructor-arg value="sid"/>
        <!-- 如果设置为true,则客户端不会暴露给服务端脚本代码,有助于减少某些类型的跨站脚本攻击 -->
        <property name="httpOnly" value="true"/>
        <property name="maxAge" value="-1"/><!-- maxAge=-1表示浏览器关闭时失效此Cookie -->
    </bean>
    <bean id="rememberMeCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
        <constructor-arg value="rememberMe"/>
        <property name="httpOnly" value="true"/>
        <property name="maxAge" value="2592000"/><!-- 30天 -->
    </bean>

    <!-- rememberMe管理器 -->
    <bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieRememberMeManager">
        <!-- cipherKey是加密rememberMe Cookie的密匙,默认AES算法 -->
        <property name="cipherKey" value="#{T(org.apache.shiro.codec.Base64).decode(‘4AvVhmFLUs0KTA3Kprsdag==‘)}"/>
        <property name="cookie" ref="rememberMeCookie"/>
    </bean>

    <!-- 会话DAO -->
    <bean id="sessionDAO" class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO">
        <!-- 设置session缓存的名称,默认就是shiro-activeSessionCache -->
        <property name="activeSessionsCacheName" value="shiro-activeSessionCache"/>
        <property name="sessionIdGenerator" ref="sessionIdGenerator"/>
    </bean>

    <!-- 会话验证调度器 -->
    <bean id="sessionValidationScheduler" class="org.apache.shiro.session.mgt.quartz.QuartzSessionValidationScheduler">
        <property name="sessionValidationInterval" value="1800000"/>
        <property name="sessionManager" ref="sessionManager"/>
    </bean>

    <!-- 会话管理器 -->
    <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
        <!-- 设置全局会话过期时间:默认30分钟 -->
        <property name="globalSessionTimeout" value="1800000"/>
        <!-- 是否自动删除无效会话 -->
        <property name="deleteInvalidSessions" value="true"/>
        <!-- 会话验证是否启用 -->
        <property name="sessionValidationSchedulerEnabled" value="true"/>
        <!-- 会话验证调度器 -->
        <property name="sessionValidationScheduler" ref="sessionValidationScheduler"/>
        <!-- 会话持久化sessionDao -->
        <property name="sessionDAO" ref="sessionDAO"/>
        <!-- 是否启用sessionIdCookie,默认是启用的 -->
        <property name="sessionIdCookieEnabled" value="true"/>
        <!-- 会话Cookie -->
        <property name="sessionIdCookie" ref="sessionIdCookie"/>
    </bean>

    <!-- 安全管理器 -->
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="realm" ref="userRealm"/>
        <property name="sessionManager" ref="sessionManager"/>
        <property name="cacheManager" ref="cacheManager"/>
        <!-- 设置securityManager安全管理器的rememberMeManger -->
        <property name="rememberMeManager" ref="rememberMeManager"/>
    </bean>

    <!-- 相当于调用SecurityUtils.setSecurityManager(securityManager) -->
    <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="staticMethod" value="org.apache.shiro.SecurityUtils.setSecurityManager"/>
        <property name="arguments" ref="securityManager"/>
    </bean>

    <!-- 基于Form表单的身份验证过滤器 -->
    <bean id="formAuthenticationFilter" class="org.apache.shiro.web.filter.authc.FormAuthenticationFilter">
        <!-- 这两个字段,username和password要和表单中定义的username和password字段名称相同,可以更改,但是表单和XML要对应 -->
        <property name="usernameParam" value="username"/>
        <property name="passwordParam" value="password"/>
        <property name="loginUrl" value="/login.jsp"/>
        <!-- rememberMeParam是rememberMe请求参数名,请求参数是boolean类型,true表示记住我 -->
        <property name="rememberMeParam" value="rememberMe"/>
    </bean>

    <!-- Shiro的Web过滤器 -->
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <!-- Shiro的安全管理器,所有关于安全的操作都会经过SecurityManager -->
        <property name="securityManager" ref="securityManager"/>
        <!-- 系统认证提交地址,如果用户退出即session丢失就会访问这个页面 -->
        <property name="loginUrl" value="/login.do"/>
        <!-- 登录成功后重定向的地址,不建议配置 -->
        <!--<property name="successUrl" value="/index.do"/>-->
        <!-- 权限验证失败跳转的页面,需要配合Spring的ExceptionHandler异常处理机制使用 -->
        <property name="unauthorizedUrl" value="/unauthorized.do"/>
        <property name="filters">
            <util:map>
                <entry key="authc" value-ref="formAuthenticationFilter"/>
            </util:map>
        </property>
        <!-- 自定义的过滤器链,从上向下执行,一般将`/**`放到最下面 -->
        <property name="filterChainDefinitions">
            <value>
                <!-- 静态资源不拦截 -->
                /static/** = anon
                /lib/** = anon
                /js/** = anon
                <!-- 登录页面不拦截 -->
                /login.jsp = anon
                /login.do = anon
                <!-- Shiro提供了退出登录的配置`logout`,会生成路径为`/logout`的请求地址,访问这个地址即会退出当前账户并清空缓存 -->
                /logout = logout
                <!-- user表示身份通过或通过记住我通过的用户都能访问系统 -->
                /index.jsp = user
                <!-- authc表示访问该地址用户必须身份验证通过,即Subject.isAuthenticated() == true -->
                /authenticated.jsp = authc
                <!-- `/**`表示所有请求,表示访问该地址的用户是身份验证通过或RememberMe登录的都可以 -->
                /** = user
            </value>
        </property>
    </bean>

    <!-- Shiro生命周期处理器-->
    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>

</beans>

 

6.创建ehcache文件夹加入ehcache-shiro.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
    <diskStore path="java.io.tmpdir"/>
    <defaultCache maxElementsInMemory="10000" eternal="false"
                  timeToIdleSeconds="900" timeToLiveSeconds="1800"
                  overflowToDisk="false"
                  memoryStoreEvictionPolicy="LFU" />
    <cache name="testEhcache"
           maxElementsInMemory="10000"
           eternal="false"
           overflowToDisk="false"
           timeToIdleSeconds="900"
           timeToLiveSeconds="1800"
           memoryStoreEvictionPolicy="LFU" />
</ehcache>

 

7.web.xml修改

  <!-- shiro配置 -->
  <filter>
    <filter-name>shiroFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
      <param-name>targetFilterLifecycle</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>shiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

 

9.加入UserRealm.java

package com.liuhy.ssm.realm;

import com.liuhy.ssm.model.User;
import com.liuhy.ssm.service.ILoginService;
import com.liuhy.ssm.service.IUserService;
import com.liuhy.ssm.utils.PasswordHelper;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.Permission;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class UserRealm extends AuthorizingRealm {

    @Autowired
    ILoginService loginService;

    @Autowired
    IUserService userService;

    @Autowired
    private PasswordHelper passwordHelper;

    /**
     * 权限校验
     * @param principals
     * @return
     */
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        System.err.println("doGetAuthorizationInfo");
        String username = (String) principals.getPrimaryPrincipal();
        SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
        Set<String> role = new HashSet<String>();
        authorizationInfo.setRoles(role);
        authorizationInfo.setStringPermissions(permission);
        return authorizationInfo;
    }

    /**
     * 身份校验
     * @param token
     * @return
     * @throws AuthenticationException
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        System.out.println("doGetAuthenticationInfo");
        String username = (String) token.getPrincipal();
        User user = userService.findByName(username);
        if (user == null) {
            throw new UnknownAccountException(); //没有找到账号
        }
        String struername=user.getUsername();
        String strpwd=user.getPassword();
        String str=user.getCredentialsSalt();
        String strname=getName();
        System.out.println(struername+"|"+strpwd+"|"+str+"|"+strname);
        SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
                struername, //用户名
                strpwd, //密码
                ByteSource.Util.bytes(str), //salt=username+salt
                strname //realm name
        );
        return authenticationInfo;
    }

    @Override
    public void clearCachedAuthorizationInfo(PrincipalCollection principals) {
        super.clearCachedAuthorizationInfo(principals);
    }

    @Override
    public void clearCachedAuthenticationInfo(PrincipalCollection principals) {
        super.clearCachedAuthenticationInfo(principals);
    }

    @Override
    public void clearCache(PrincipalCollection principals) {
        super.clearCache(principals);
    }

    public void clearAllCachedAuthorizationInfo() {
        getAuthorizationCache().clear();
    }

    public void clearAllCachedAuthenticationInfo() {
        getAuthenticationCache().clear();
    }

    public void clearAllCache() {
        clearAllCachedAuthenticationInfo();
        clearAllCachedAuthorizationInfo();
    }
}

 10.验证失败DefaultExceptionHandler.java

package com.liuhy.ssm.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.context.request.NativeWebRequest;

@ControllerAdvice
public class DefaultExceptionHandler {
    @ExceptionHandler({UnauthorizedException.class})
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    public String processUnauthenticatedException(NativeWebRequest request, UnauthorizedException e) {
        return "unauthorized";
    }
}

 11.RetryLimitHashedCredentialsMatcher.java

package com.liuhy.ssm.credentials;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.ExcessiveAttemptsException;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheManager;

import java.util.concurrent.atomic.AtomicInteger;

public class RetryLimitHashedCredentialsMatcher extends HashedCredentialsMatcher {

    private Cache<String, AtomicInteger> passwordRetryCache;
    public RetryLimitHashedCredentialsMatcher(CacheManager cacheManager){
        passwordRetryCache = cacheManager.getCache("passwordRetryCache");
    }
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        String username = (String) token.getPrincipal();
        AtomicInteger retryCount = passwordRetryCache.get(username);
        if(retryCount == null){
            retryCount = new AtomicInteger(0);
            passwordRetryCache.put(username,retryCount);
        }
        if(retryCount.incrementAndGet() > 5){
            throw new ExcessiveAttemptsException();
        }
        boolean matches = super.doCredentialsMatch(token,info);
        if(matches){
            passwordRetryCache.remove(username);
        }
        return matches;
    }
}

12LoginController.java

package com.liuhy.ssm.controller;

import com.liuhy.ssm.model.User;
import com.liuhy.ssm.service.ILoginService;
import com.liuhy.ssm.utils.PasswordHelper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.subject.Subject;
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;

@Controller
//@RequestMapping(value = "user")
public class LoginController {
    //默认输出路径
    private static org.apache.log4j.Logger logger=org.apache.log4j.Logger.getLogger(LoginController.class);
    @Autowired
    ILoginService loginService;
    @RequestMapping(value = "login")
    public String login( @RequestParam(value = "username", required = false) String username,
                         @RequestParam(value = "password", required = false) String password,
                         @RequestParam(value = "remember", required = false) String remember,
                         Model model) {
        System.out.println("login");
        System.out.println("登陆用户输入的用户名:" + username + ",密码:" + password);
//        username="admin";
//        password="123";
        String error = null;
        if (username != null && password != null) {
            //初始化
            Subject subject = SecurityUtils.getSubject();
            UsernamePasswordToken token = new UsernamePasswordToken(username, password);
            if (remember != null) {
                if (remember.equals("on")) {
                    token.setRememberMe(true);
                } else {
                    token.setRememberMe(false);
                }
            } else {
                token.setRememberMe(false);
                try {
                    subject.login(token);
                    System.out.println("用户是否登录:" + subject.isAuthenticated());
                    return "redirect:main.do";
                } catch (UnknownAccountException e) {
                    e.printStackTrace();
                    error = "用户账户不存在,错误信息:" + e.getMessage();
                } catch (IncorrectCredentialsException e) {
                    e.printStackTrace();
                    error = "用户名或密码错误,错误信息:" + e.getMessage();
                } catch (LockedAccountException e) {
                    e.printStackTrace();
                    error = "该账号已锁定,错误信息:" + e.getMessage();
                } catch (DisabledAccountException e) {
                    e.printStackTrace();
                    error = "该账号已禁用,错误信息:" + e.getMessage();
                } catch (ExcessiveAttemptsException e) {
                    e.printStackTrace();
                    error = "该账号登录失败次数过多,错误信息:" + e.getMessage();
                } catch (Exception e) {
                    e.printStackTrace();
                    error = "未知错误,错误信息:" + e.getMessage();
                }
            }
        }
        else{
            error = "请输入用户名和密码";
        }
        model.addAttribute("error", error);
        return "login";
    }

    @RequestMapping(value = "test")
    public String test() {
        System.out.println("test");
        logger.info("test");
        logger.debug("test");
        logger.error("test");
        return "test";
    }
}

13 IUserService.java

package com.liuhy.ssm.service;

import com.liuhy.ssm.model.User;
import org.apache.shiro.authz.Permission;


import java.util.List;

public interface IUserService{
        User findByName(String username);

}

  

14 UserServiceImpl.java

package com.liuhy.ssm.service.impl;

import com.liuhy.ssm.dao.UserDao;
import com.liuhy.ssm.model.User;
import com.liuhy.ssm.service.IUserService;
import org.apache.shiro.authz.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User findByName(String username) {
        return userDao.findByName(username);
    }
}

15 UserMapper.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.liuhy.ssm.dao.UserDao">
    <select id="loginDao" resultType="int">
        select count(*) from sysuser WHERE  username = #{user.username} and password = #{user.password}
    </select>
    <!-- 根据用户名查询-->
    <select id="findByName" parameterType="String" resultType="com.liuhy.ssm.model.User">
        SELECT * FROM sysuser WHERE username = #{username}
    </select>
</mapper>

 User.java

package com.liuhy.ssm.model;

/**
 * @author Administrator
 */
public class User {
    public User(Long id, String username, String nickname, String password, String email, String avatar, String enable, String open_id, String wx_open_id, String createtime, String updatetime, String salt) {
        this.id = id;
        this.username = username;
        this.nickname = nickname;
        this.password = password;
        this.email = email;
        this.avatar = avatar;
        this.enable = enable;
        this.open_id = open_id;
        this.wx_open_id = wx_open_id;
        this.createtime = createtime;
        this.updatetime = updatetime;
        this.salt = salt;
    }

    //    CREATE TABLE `sys_user` (
//            `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
//	`username` VARCHAR(20) NULL DEFAULT NULL,
//	`nickname` VARCHAR(50) NULL DEFAULT NULL,
//	`password` VARCHAR(50) NULL DEFAULT NULL,
//	`avatar` VARCHAR(255) NULL DEFAULT NULL,
//	`email` VARCHAR(100) NULL DEFAULT NULL,
//	`enable` TINYINT(1) NULL DEFAULT ‘1‘,
//            `open_id` VARCHAR(32) NULL DEFAULT NULL COMMENT ‘qq登录api的openid‘,
//            `wx_open_id` VARCHAR(32) NULL DEFAULT NULL,
//	`createtime` DATETIME NULL DEFAULT NULL,
//	`updatetime` DATETIME NULL DEFAULT NULL,
//    PRIMARY KEY (`id`),
//    UNIQUE INDEX `username` (`username`) USING BTREE
//)
//    COLLATE=‘utf8_general_ci‘
//    ENGINE=InnoDB
//            AUTO_INCREMENT=1
//            ;
    private Long id;


    private String username;
    private String nickname;
    private String password;
    private String email;
    private String avatar;
    private String enable;
    private String open_id;
    private String wx_open_id;
    private String createtime;
    private String updatetime;

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    private String salt; //盐


    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getEnable() {
        return enable;
    }

    public void setEnable(String enable) {
        this.enable = enable;
    }

    public String getOpen_id() {
        return open_id;
    }

    public void setOpen_id(String open_id) {
        this.open_id = open_id;
    }

    public String getWx_open_id() {
        return wx_open_id;
    }

    public void setWx_open_id(String wx_open_id) {
        this.wx_open_id = wx_open_id;
    }

    public String getCreatetime() {
        return createtime;
    }

    public void setCreatetime(String create_time) {
        this.createtime = create_time;
    }

    public String getUpdatetime() {
        return updatetime;
    }

    public void setUpdatetime(String updatetime) {
        this.updatetime = updatetime;
    }

    public String getCredentialsSalt() {
        return username + salt;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username=‘" + username + ‘\‘‘ +
                ", nickname=‘" + nickname + ‘\‘‘ +
                ", password=‘" + password + ‘\‘‘ +
                ", email=‘" + email + ‘\‘‘ +
                ", avatar=‘" + avatar + ‘\‘‘ +
                ", enable=‘" + enable + ‘\‘‘ +
                ", open_id=‘" + open_id + ‘\‘‘ +
                ", wx_open_id=‘" + wx_open_id + ‘\‘‘ +
                ", createtime=‘" + createtime + ‘\‘‘ +
                ", updatetime=‘" + updatetime + ‘\‘‘ +
                ", salt=‘" + salt + ‘\‘‘ +
                ‘}‘;
    }
}

  

16目录结构

技术分享图片

 

17.执行

技术分享图片

 

 

技术分享图片

 

 

 

  

 

使用IDEA创建SSM程序框架(五)

原文:https://www.cnblogs.com/liuhy-hrb/p/12874370.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!