java學習

          java學習

           

          訪問tomcat時只輸入ip就可以訪問系統的方法

          1.在tomcat的service.xml中把端口改成80
          2.把自己的項目名稱改成ROOT,覆蓋tomcat的原ROOT項目,就可以了

          posted @ 2013-05-13 11:28 楊軍威 閱讀(186) | 評論 (0)編輯 收藏

          extjs下拉框點擊一行觸發事件,得到valueField和displayField的值

                      var combo = new Ext.form.ComboBox(
                                                                  {
                                                                      store : store,
                                                                      emptyText : '請選擇',
                                                                      mode : 'local',
                                                                      triggerAction : 'all',
                                                                      valueField : 'value',
                                                                      displayField : 'name',
                                                                      //autoScroll : true,
                                                                      //length : 4,
                                                                      //IdValue : 'name',
                                                                      listeners : {//選擇一行后觸發的事件
                                                                          'select' : function() {
                                                                      
                                                                      var url = combo
                                                                      .getValue();//得到valueField的值
                                                                      if (url != null
                                                                              && url != '') {
                                                                      
                                                                          loactionTo(
                                                                                  combo
                                                                                  .getRawValue(),//得到displayField的值
                                                                                  url);
                                                                          // typeForm.getForm().submit({});
                                                                      }
                                                                      }
                                                                      }

                                                                  });

          posted @ 2013-05-12 09:22 楊軍威 閱讀(2279) | 評論 (0)編輯 收藏

          Hibernate Fetch策略

          hibernate抓取策略(單端代理的批量抓取)
            保持默認,同fetch="select",如:
            <many-to-one name="classes" column="classesid" fetch="select"/>
            fetch="select",另外發送一條select語句抓取當前對象關聯實體或集合
            
            設置fetch="join",如:
            <many-to-one name="classes" column="classesid" fetch="join"/>
            fetch="join",hibernate會通過select語句使用外連接來加載其關聯實體或集合
            此時lazy會失效
            
            
            hibernate抓取策略(集合代理的批量抓取)
            保持默認,同fetch="select",如:
            <set name="students" inverse="true" cascade="all" fetch="select">
            fetch="select",另外發送一條select語句抓取當前對象關聯實體或集合
            
            設置fetch="join",如:
            <set name="students" inverse="true" cascade="all" fetch="join">
            fetch="join",hibernate會通過select語句使用外連接來加載其關聯實體或集合 此時lazy會失效
            
            設置fetch="subselect",如:
            <set name="students" inverse="true" cascade="all" fetch="subselect">
            fetch="subselect",另外發送一條select語句抓取在前面查詢到的所有實體對象的關聯集合
            
            hibernate抓取策略,,batch-size在<class>上的應用
            batch-size屬性,可以批量加載實體類,參見:Classes.hbm.xml
            <class name="Classes" table="t_classes" batch-size="3">
            
            hibernate抓取策略,batch-size在集合上的應用
            batch-size屬性,可以批量加載實體類,參見:Classes.hbm.xml
            <set name="students" inverse="true" cascade="all" batch-size="5">
            hibernate 會下先完發sql,再一次性的大數據 

          posted @ 2013-05-07 10:13 楊軍威 閱讀(187) | 評論 (0)編輯 收藏

          hibernate中實體類繼承,按照子類建表

          實體類父類:

          public class Animal {
           
           private int id;
           
           private String name;
           
           private boolean sex;

           public int getId() {
            return id;
           }

           public void setId(int id) {
            this.id = id;
           }

           public String getName() {
            return name;
           }

           public void setName(String name) {
            this.name = name;
           }

           public boolean isSex() {
            return sex;
           }

           public void setSex(boolean sex) {
            this.sex = sex;
           }
          }

          子類:

          public class Bird extends Animal {

           private int height;

           public int getHeight() {
            return height;
           }

           public void setHeight(int height) {
            this.height = height;
           }
          }


          public class Pig extends Animal {
           
           private int weight;

           public int getWeight() {
            return weight;
           }

           public void setWeight(int weight) {
            this.weight = weight;
           }
          }


          extends.hbm.xml文件:
          <hibernate-mapping package="com.hibernate">
           <class name="Animal" abstract="true">
            <id name="id">
             <generator class="assigned"/>
            </id>
            <property name="name"/>
            <property name="sex"/>
            <union-subclass name="Pig" table="t_pig">
             <property name="weight"/>
            </union-subclass>
            <union-subclass name="Bird" table="t_bird">
             <property name="height"/>
            </union-subclass>
           </class>
          </hibernate-mapping>
          數據庫表如下:

          posted @ 2013-05-07 09:46 楊軍威 閱讀(307) | 評論 (0)編輯 收藏

          hibernate中實體類繼承,分成若干表

          父類實體類:

          public class Animal {
           
           private int id;
           
           private String name;
           
           private boolean sex;

           public int getId() {
            return id;
           }

           public void setId(int id) {
            this.id = id;
           }

           public String getName() {
            return name;
           }

           public void setName(String name) {
            this.name = name;
           }

           public boolean isSex() {
            return sex;
           }

           public void setSex(boolean sex) {
            this.sex = sex;
           }
          }

          子類實體類:

          public class Bird extends Animal {

           private int height;

           public int getHeight() {
            return height;
           }

           public void setHeight(int height) {
            this.height = height;
           }
          }

          public class Pig extends Animal {
           
           private int weight;

           public int getWeight() {
            return weight;
           }

           public void setWeight(int weight) {
            this.weight = weight;
           }
          }

          extends.hbm.xml文件:
          <hibernate-mapping package="com.hibernate">
           <class name="Animal" table="t_animal">
            <id name="id">
             <generator class="native"/>
            </id>
            <property name="name"/>
            <property name="sex"/>
            <joined-subclass name="Pig" table="t_pig">
             <key column="pid"/>
             <property name="weight"/>
            </joined-subclass>
            <joined-subclass name="Bird" table="t_bird">
             <key column="bid"/>
             <property name="height"/>
            </joined-subclass>
           </class>
          </hibernate-mapping>
          在數據庫中表如下:

          posted @ 2013-05-07 09:37 楊軍威 閱讀(409) | 評論 (0)編輯 收藏

          hibernate中每棵繼承樹映射成一張表

          public class Animal {
           
           private int id;
           
           private String name;
           
           private boolean sex;

           public int getId() {
            return id;
           }

           public void setId(int id) {
            this.id = id;
           }

           public String getName() {
            return name;
           }

           public void setName(String name) {
            this.name = name;
           }

           public boolean isSex() {
            return sex;
           }

           public void setSex(boolean sex) {
            this.sex = sex;
           }
          }

          public class Bird extends Animal {

           private int height;

           public int getHeight() {
            return height;
           }

           public void setHeight(int height) {
            this.height = height;
           }
          }

          public class Pig extends Animal {
           
           private int weight;

           public int getWeight() {
            return weight;
           }

           public void setWeight(int weight) {
            this.weight = weight;
           }
          }

          在extends.hbm.xml文件:
          <hibernate-mapping package="com.hibernate">
           <class name="Animal" table="t_animal" lazy="false">
            <id name="id">
             <generator class="native"/>
            </id>
            <discriminator column="type" type="string"/>
            <property name="name"/>
            <property name="sex"/>
            <subclass name="Pig" discriminator-value="P">
             <property name="weight"/>
            </subclass>
            <subclass name="Bird" discriminator-value="B">
             <property name="height"/>
            </subclass>
           </class>
          </hibernate-mapping>
          理解如何映射
            因為類繼承樹肯定是對應多個類,要把多個類的信息存放在一張表中,必須有某種機制來區分哪些記錄是屬于哪個類的。
           這種機制就是,在表中添加一個字段,用這個字段的值來進行區分。用hibernate實現這種策略的時候,有如下步驟:
           父類用普通的<class>標簽定義
           在父類中定義一個discriminator,即指定這個區分的字段的名稱和類型
           如:<discriminator column=”XXX” type=”string”/>
           子類使用<subclass>標簽定義,在定義subclass的時候,需要注意如下幾點:
           Subclass標簽的name屬性是子類的全路徑名
           在Subclass標簽中,用discriminator-value屬性來標明本子類的discriminator字段(用來區分不同類的字段)
           的值Subclass標簽,既可以被class標簽所包含(這種包含關系正是表明了類之間的繼承關系),也可以與class標
           簽平行。 當subclass標簽的定義與class標簽平行的時候,需要在subclass標簽中,添加extends屬性,里面的值
           是父類的全路徑名稱。子類的其它屬性,像普通類一樣,定義在subclass標簽的內部。

          posted @ 2013-05-06 22:51 楊軍威 閱讀(220) | 評論 (0)編輯 收藏

          hibernate 中集合映射成表

          實體類是:

          public class CollectionMapping {
           
           private int id;
           
           private String name;
           
           private Set setValue;
           
           private List listValue;
           
           private String[] arrayValue;
           
           private Map mapValue;

           public int getId() {
            return id;
           }

           public void setId(int id) {
            this.id = id;
           }

           public String getName() {
            return name;
           }

           public void setName(String name) {
            this.name = name;
           }

           public Set getSetValue() {
            return setValue;
           }

           public void setSetValue(Set setValue) {
            this.setValue = setValue;
           }

           public List getListValue() {
            return listValue;
           }

           public void setListValue(List listValue) {
            this.listValue = listValue;
           }

           public String[] getArrayValue() {
            return arrayValue;
           }

           public void setArrayValue(String[] arrayValue) {
            this.arrayValue = arrayValue;
           }

           public Map getMapValue() {
            return mapValue;
           }

           public void setMapValue(Map mapValue) {
            this.mapValue = mapValue;
           }
          }

          在CollectionMapping.hbm.xml文件中:
          <hibernate-mapping>
           <class name="CollectionMapping" table="t_CollectionMapping">
            <id name="id">
             <generator class="native"/>
            </id>
            <property name="name"/>
            <set name="setValue" table="t_set_value">
             <key column="set_id"/>
             <element type="string" column="set_value"/>
            </set>
            <list name="listValue" table="t_list_value">
             <key column="list_id"/>
             <list-index column="list_index"/>
             <element type="string" column="list_value"/>
            </list>
            <array name="arrayValue" table="t_array_value">
             <key column="array_id"/>
             <list-index column="array_index"/>
             <element type="string" column="array_value"/>
            </array>
            <map name="mapValue" table="t_map_value">
             <key column="map_id"/>
             <map-key type="string" column="map_key"/>
             <element type="string" column="map_value"/>
            </map>
           </class>
          </hibernate-mapping>
          在數據庫中生成5個表

          posted @ 2013-05-06 22:22 楊軍威 閱讀(188) | 評論 (0)編輯 收藏

          hibernate中實體類中有其他普通類的引用,普通類的屬性在數據庫中是實體類的一個字段

          例如:
          普通類:

          public class Contact {
           
           private String email;
           
           private String address;
           
           private String zipCode;
           
           private String contactTel;

           public String getEmail() {
            return email;
           }

           public void setEmail(String email) {
            this.email = email;
           }

           public String getAddress() {
            return address;
           }

           public void setAddress(String address) {
            this.address = address;
           }

           public String getZipCode() {
            return zipCode;
           }

           public void setZipCode(String zipCode) {
            this.zipCode = zipCode;
           }

           public String getContactTel() {
            return contactTel;
           }

           public void setContactTel(String contactTel) {
            this.contactTel = contactTel;
           }
          }

          實體類:

          public class User {
           
           private int id;
           
           private String name;
           
           private Contact contact;
           
           public int getId() {
            return id;
           }

           public void setId(int id) {
            this.id = id;
           }

           public String getName() {
            return name;
           }

           public void setName(String name) {
            this.name = name;
           }

           public Contact getContact() {
            return contact;
           }

           public void setContact(Contact contact) {
            this.contact = contact;
           }
           
          }

          User.hbm.xml文件:
          <hibernate-mapping>
           <class name="User" table="t_user">
            <id name="id">
             <generator class="native"/>
            </id>
            <property name="name"/>
            <component name="contact">
             <property name="email"/>
             <property name="address"/>
             <property name="zipCode"/>
             <property name="contactTel"/>
            </component>
           </class>
          </hibernate-mapping>
          在數據庫中在t_user表中含有Contact類的屬性字段

          posted @ 2013-05-06 22:10 楊軍威 閱讀(551) | 評論 (0)編輯 收藏

          hibernate實體配置文件中主鍵生成策略

          <id name="id" column="user_id" length="32">
            <!-- 主鍵自動生成uuid -->
             <generator class="uuid"/>
            </id>
          <id name="id" column="user_id">
            <!-- 主鍵自動增長 -->
             <generator class="native"/>
            </id>
          <id name="id" column="user_id" length="32">
            <!-- 主鍵需要手動定義 -->
             <generator class="assigned"/>
            </id>

          posted @ 2013-05-06 21:32 楊軍威 閱讀(183) | 評論 (0)編輯 收藏

          dom4j解析xml文件

          1.先導入dom4j-1.6.1.jar包
          2.xml文件如下:

          <?xml version="1.0" encoding="UTF-8"?>
          <config>
           
           
           <action name="user" className="com.kaishengit.web.UserAction">
            <result name="success" type="forward">suc.jsp</result>
            <result name="error" type="redirect">404.jsp</result>
           </action>
           
           
           <action name="book" className="com.kaishengit.web.BookAction">
            <result name="success">book.jsp</result>
            <result name="error" type="redirect">bookerror.jsp</result>
           </action>
           
           <action name="person" className="com.kaishengit.web.PersonAction" method="del">
            <result name="ok">suc.jsp</result>
           </action>
           
           

          </config>

          3.解析測試類是:

          package com.kaishengit.test;

          import java.io.File;
          import java.net.URL;
          import java.util.List;

          import org.dom4j.Document;
          import org.dom4j.Element;
          import org.dom4j.io.SAXReader;

          public class Dom4jTest {

           public void readXML() {
            //拿到src文件夾里的xml配置文件
            URL url = getClass().getResource("/");
            System.out.println(url);
            String filePath = url.getFile() + "struts.xml";
            
            try {
             //創建讀取配置文件的對象
             SAXReader reader = new SAXReader();
             //開始讀取配置文件
             Document doc = reader.read(new File(filePath));
             //拿到根節點
             Element root = doc.getRootElement();
             
             //拿到根節點下的action接點數組
             List<Element> actions = root.elements("action");
             
             for(Element action : actions) {
              String name = action.attributeValue("name");
              String className = action.attributeValue("className");
              String method = action.attributeValue("method");
              System.out.println("name="+name);
              System.out.println("className="+className);
              System.out.println("method="+method);
              
              List<Element> results = action.elements("result");
              for(Element result : results) {
               String resultName = result.attributeValue("name");
               String resultType = result.attributeValue("type");
               String pageName = result.getText();
               
               System.out.println("name:" + resultName + "\tresultType:" + resultType + "\tpageName:" + pageName);
             
              }
              
              System.out.println("----------------------");
             }
             
             
            } catch (Exception e) {
             e.printStackTrace();
            }
            
           }
           
           
           
           public static void main(String[] args) {
            
            
            Dom4jTest d = new Dom4jTest();
            d.readXML();
            
            
            
           }
          }

          posted @ 2013-05-06 21:08 楊軍威 閱讀(1353) | 評論 (0)編輯 收藏

          僅列出標題
          共43頁: First 上一頁 18 19 20 21 22 23 24 25 26 下一頁 Last 

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 闽侯县| 蕉岭县| 金塔县| 萝北县| 汪清县| 旬邑县| 瓦房店市| 石楼县| 渝北区| 神木县| 金坛市| 南京市| 乌审旗| 怀宁县| 凌海市| 德化县| 大宁县| 古丈县| 乐业县| 兴宁市| 太湖县| SHOW| 陵川县| 稻城县| 五莲县| 大名县| 丰都县| 松阳县| 深水埗区| 滕州市| 民勤县| 台前县| 红河县| 响水县| 都匀市| 西盟| 永清县| 石狮市| 鄱阳县| 临颍县| 泸溪县|