<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 注解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 { boolean hump() default true; String name() default ""; } @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) @Documented public @interface Table { String value(); } ~~~ ## 應用 ~~~ package com.ntqingniao.annotation; import java.util.Date; @Table("t_sys_account") public class Account { @Column(name="ID") private Integer id; @Column private String name; @Column(name="PASSWOR") private String password; @Column(hump=true) private Date createTime; private String desc; } ~~~ ## 解析注解數據 ~~~ package com.ntqingniao.annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Date; public class Client2 { public static void main(String[] args) throws Exception { Account account = new Account(); account.setId(10); account.setName("Tom"); account.setPassword("123456"); account.setCreateTime(new Date()); Student stu = new Student(); stu.setId(12); stu.setName("helen"); stu.setPassword("aaaaaa"); stu.setDesc("hello,helen"); stu.setCreateTime(new Date()); System.out.println(gerInsertSql(account)); System.out.println(gerInsertSql(stu)); // insert into t_sys_account(ID,NAME,PASSWORD,CREATE_TIME) values(10, // "Tom", "123456", "20170711"); } public static String gerInsertSql(Object account) throws Exception { String sql = "insert into "; String values = ""; Class<?> c = null; c = account.getClass(); Table table = c.getAnnotation(Table.class); String tableName = table.value(); sql += tableName + "("; Field[] fields = c.getDeclaredFields(); for (Field field : fields) { Column column = field.getAnnotation(Column.class); String columnName = field.getName(); if (null != column) { // 首先判斷hump屬性是否為true columnName = Client3.toHump(columnName); // 否則取name屬性值 String cn = column.name(); if (null != cn && !cn.trim().equals("")) { columnName = cn; } else { // 如果name屬性值為空,則取字段名 } sql += columnName + ","; // 獲取字段的屬性值,并拼寫到values變量中 Method getMethod = c.getMethod("get" + Client3.captureName(field.getName())); Object obj = getMethod.invoke(account); values += Client3.changeToSql(obj) + ","; } } sql = sql.substring(0, sql.length() - 1) + ")" + " values(" + values.substring(0, values.length() - 1) + ")"; return sql; } } ~~~
                  <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>

                              哎呀哎呀视频在线观看