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();
     }

  • 相关阅读:
    CentOS7.6安装Kubernetes v1.15.1
    数据库三大范式
    linux
    linux
    linux
    linux
    Django contenttypes组件
    Django自带的用户认证
    Django rest framework(7) ---分页
    Django rest framework(6) ---序列化
  • 原文地址:https://www.cnblogs.com/liuCy/p/3362570.html
Copyright © 2011-2022 走看看