zoukankan      html  css  js  c++  java
  • Spring中数据绑定的两种方式(BeanWrapperImpl或者DataBinder)

    import org.apache.shiro.authc.AuthenticationToken;
    import org.springframework.beans.*;
    import org.springframework.validation.DataBinder;
    
    import java.util.HashMap;
    import java.util.Map;
    
    /**
    
     * <p>Version: 1.0
     */
    public class StatelessToken implements AuthenticationToken {
    
        private String username;
        private Map<String, ?> params;
        private String clientDigest;
    
        public StatelessToken(String username,  Map<String, ?> params, String clientDigest) {
            this.username = username;
            this.params = params;
            this.clientDigest = clientDigest;
        }
    
        public String getUsername() {
            return username;
        }
    
        public void setUsername(String username) {
            this.username = username;
        }
    
        public  Map<String, ?> getParams() {
            return params;
        }
    
        public void setParams( Map<String, ?> params) {
            this.params = params;
        }
    
        public String getClientDigest() {
            return clientDigest;
        }
    
        public void setClientDigest(String clientDigest) {
            this.clientDigest = clientDigest;
        }
    
        @Override
        public Object getPrincipal() {
           return username;
        }
    
        @Override
        public Object getCredentials() {
            return clientDigest;
        }
    
        public static void main(String[] args) {
    
        }
        public static void test1() {
            StatelessToken token = new StatelessToken(null, null, null);
            BeanWrapperImpl beanWrapper = new BeanWrapperImpl(token);
            beanWrapper.setPropertyValue(new PropertyValue("username", "hjzgg"));
            System.out.println(token.getUsername());
        }
    
        public static void test2() {
            StatelessToken token = new StatelessToken(null, null, null);
            DataBinder dataBinder = new DataBinder(token);
            Map<String, Object> params = new HashMap<>();
            params.put("username", "hjzgg");
            PropertyValues propertyValues = new MutablePropertyValues(params);
            dataBinder.bind(propertyValues);
            System.out.println(token.getUsername());
        }
    }
  • 相关阅读:
    Ubuntu学习
    MYSQL中group_concat有长度限制!默认1024
    关于Ubuntu中Could not get lock /var/lib/dpkg/lock解决方案
    PHP开发接口使用RSA进行加密解密方法
    WebSocket实战之————Workerman服务器的安装启动
    vim 命令图解
    ubuntu下安装Apache+PHP+Mysql
    Ubuntu 下Apache安装和配置
    android调试输出
    使用AsyncTask异步更新UI界面及原理分析
  • 原文地址:https://www.cnblogs.com/hujunzheng/p/7196998.html
Copyright © 2011-2022 走看看