<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 注解Annotation 特別在系統框架的搭建過程中,往往需要很多的配置文件,比如數據源、IOC、AOP、框架本身的映射(如 Hibernate 表與字段),需要的配置文件會導致系統越來越復雜,而且維護很不方便,一旦配置文件出錯,很容易導致系統無法運行。 在 JDK1.5 以后,引入了注解 Annotation 技術,極大的方便了配置化的編程,很多的技術和框架都使用了技術,如 Servlet/Filter/Spring/SpringMVC/Hibernate/Nutz。 ## 定義 ~~~ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.METHOD}) @Documented public @interface Column { String name() default ""; } @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) @Documented public @interface Table { String value(); } ~~~ ## 應用 ~~~ package com.dodoke.annotation; @Table("T_SYS_ACCOUNT") public class Account { @Column(name = "ID1") private Integer id; @Column private String name; @Column(name = "PASSWOR1") private String password; private String desc; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getDesc() { return desc; } public void setDesc(String desc) { this.desc = desc; } } ~~~ ## 解析注解數據 ~~~ package com.dodoke.annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; public class Client { public static void main(String[] args) throws Exception { Account account = new Account(); account.setName("Tom"); account.setPassword("123456"); System.out.println(gerInsertSql(account)); // INSERT INTO t_sys_account(NAME1,PASSWORD1) values("Tom", "123456"); } public static String gerInsertSql(Object account) throws Exception { String sql = "INSERT INTO "; // 賬號account對應Class對象 Class<?> c = null; c = account.getClass(); // 獲取表格名稱 Table table = c.getAnnotation(Table.class); String tableName = table.value(); sql += tableName + "("; String fs = ""; String vs = ""; Field[] fields = c.getDeclaredFields(); for (Field field : fields) { // 獲取表中字段名 Column column = field.getAnnotation(Column.class); // 獲取類中屬性名 String columnName = field.getName(); if (null != column) { String cn = column.name(); // 如果name屬性值為空,則取字段名 if (null != cn && !cn.trim().equals("")) { columnName = cn; } String methodName = "get" + upperFirst(field.getName()); Method getMethod = c.getMethod(methodName); String v = (String) getMethod.invoke(account); if (null != v) { fs += columnName + ","; vs += "'" + v + "',"; } } } if (!fs.isEmpty()) { fs = fs.substring(0, fs.length() - 1); } if (!vs.isEmpty()) { vs = vs.substring(0, vs.length() - 1); } sql += fs + ") VALUES(" + vs + ");"; return sql; } private static String upperFirst(String str) { if (null != str && str.length() > 0) { return str.substring(0, 1).toUpperCase() + str.substring(1); } return ""; } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看