zoukankan      html  css  js  c++  java
  • 11

     public static String getHql() throws Exception {
      // 获得 Person类上 run方法上的注解
      // 反射获得run方法
      Class personClass = Person.class;

      Field[] fieldlist = personClass.getDeclaredFields();
      StringBuffer hqlSel = new StringBuffer("select ");
      StringBuffer hqlFrom = new StringBuffer(" from ");
      String name, asName;
      String[] nameSpilt;
      Set<String> fromVals = new HashSet();
      for (Field f : fieldlist) {
       MyAnnotation1 myAnnotation1 = f.getAnnotation(MyAnnotation1.class);
       if (myAnnotation1 != null) {
        asName = " as " + f.getName();
        name = myAnnotation1.value();
        nameSpilt = name.split("\.");
        if (nameSpilt.length == 2) {
         fromVals.add(nameSpilt[0]);
        }
        hqlSel.append(name).append(asName).append(",");
       }
      }
      hqlSel.delete(hqlSel.length() - 1, hqlSel.length());

      for (String fromVal : fromVals) {
       hqlFrom.append(fromVal).append(",");
      }
      hqlFrom.delete(hqlFrom.length() - 1, hqlFrom.length());
      hqlSel.append(hqlFrom);
      System.out.println(hqlSel);
      return hqlSel.toString();
     }

  • 相关阅读:
    3、生成证书请求文件
    2、申请苹果App ID
    登录iOS Dev Center
    SQL Server 合并行
    asp 月末 月初
    linux
    ASP数组全集,多维数组和一维数组[转]
    oracle 秒
    oracle 存储过程 包 【转】
    linux
  • 原文地址:https://www.cnblogs.com/liuCy/p/3362570.html
Copyright © 2011-2022 走看看