zoukankan      html  css  js  c++  java
  • JAVA代理的使用

    目的:根据配置信息封装mybatis的example。

    1.要先进行字段的格式封装:首字母大写的驼峰式命名

    2.遍历封装后的字段。使用代理获取值还有获取example封装

        public MAcChannelSpotBoExample getExampleByVo(MAcChannelSpotVo vo) {
            /**
             *  获取去重字段,并封装成list结构
             */
            MAcSpotRemDeplicateBo ruleBo =  mAcSpotRemDeplicateBoMapper.selectByPrimaryKey(vo.getRuleId());
            String[] removeDeplicates = ruleBo.getRemoveDeplicate().split(",");
            removeDeplicates = insert(removeDeplicates, "RULE_ID");
            List<String> removeDeplicateLows = new ArrayList();
            for(String s : removeDeplicates) {
                String ss = s.toLowerCase();
                String [] str = ss.split("_");
                StringBuffer newS = new StringBuffer();
                for(int i=0; i<str.length; i++) {
                    newS.append(str[i].substring(0,1).toUpperCase()+str[i].substring(1));
                }
                removeDeplicateLows.add(newS.toString());
            }
    
            /**
             *  根据去重字段+ruleId,动态封装 example
             */
            MAcChannelSpotBoExample example = new MAcChannelSpotBoExample();
            MAcChannelSpotBoExample.Criteria criteria = example.createCriteria();
            if(StringUtils.isNotBlank(vo.getChannelSpotId())) {
                criteria.andChannelSpotIdNotEqualTo(vo.getChannelSpotId());
            }
            Method[] m = criteria.getClass().getMethods();
            Method[] m2 = vo.getClass().getMethods();
            try {
                for (String str : removeDeplicateLows) {
                    for (int i = 0; i < m2.length; i++) {
                        if (("get" + str).toLowerCase().equals(m2[i].getName().toLowerCase())) {
                            Object value2 = m2[i].invoke(vo);
                            for(int j = 0; j < m.length; j++){
                                if(("and"+str + "EqualTo").toLowerCase().equals(m[j].getName().toLowerCase())){
                                    m[j].invoke(criteria, value2);
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                LOG.error(e);
            }
            return example;
        }
  • 相关阅读:
    gridview填加双击事件
    后台找前台服务器控件,客户端控件方法
    ie缓存是什么 和 清除ie缓存方法
    js 去掉空格的方法
    SQL 用户sa登录失败,该用户与可信sql server连接无关联
    (转)C#里面比较时间大小三种方法
    sql UNION 和 UNION ALL 的区别
    windows 计划任务 打开窗口
    mysql 优化8种方式
    javascript小括号表达式
  • 原文地址:https://www.cnblogs.com/linhongwenBlog/p/13555156.html
Copyright © 2011-2022 走看看