<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    2011年11月16日

    (轉(zhuǎn)貼)數(shù)據(jù)庫(kù)連接(內(nèi)連接,外連接,交叉連接)

    數(shù)據(jù)庫(kù)連接分為:內(nèi)連接,外連接(左、右連接,全連接),交叉連接
    文章地址 : http://www.zxbc.cn/html/20080527/51189.html
    轉(zhuǎn)載 
    內(nèi)連接:把兩個(gè)表中數(shù)據(jù)對(duì)應(yīng)的數(shù)據(jù)查出來(lái) 
    外連接:以某個(gè)表為基礎(chǔ)把對(duì)應(yīng)數(shù)據(jù)查出來(lái)(全連接是以多個(gè)表為基礎(chǔ)) 
    student表 
    no name 
    1     a 
    2     b 
    3     c 
    4     d 
    grade表 
    no grade 
    1     90 
    2     98 
    3     95 
    內(nèi)連接 inner join(查找條件中對(duì)應(yīng)的數(shù)據(jù),no4沒(méi)有數(shù)據(jù)不列出來(lái)) 
    語(yǔ)法:select * from student inner join grade on student.no = grade.no 
    結(jié)果 
    student.no name grade.no grade 
    1             a             1         90 
    2             b             2         98 
    3             c             3         95 
    左連接(左表中所有數(shù)據(jù),右表中對(duì)應(yīng)數(shù)據(jù)) 
    語(yǔ)法:select * from student left join grade on student.no = grade.no 
    結(jié)果: 
    student.no name grade.no grade 
    1                 a         1         90 
    2                 b         2         98 
    3                 c         3         95 
    4                 d     
    右連接(右表中所有數(shù)據(jù),左表中對(duì)應(yīng)數(shù)據(jù)) 
    語(yǔ)法:select * from student right join grade on student.no = grade.no 
    結(jié)果: 
    student.no name grade.no grade 
    1                 a         1         90 
    2                 b         2         98 
    3                 c         3         95 
    全連接 
    語(yǔ)法:select * from student full join grade on student.no = grade.no 
    結(jié)果: 
    no name grade 
    1     a     90 
    2     b     98 
    3     c     95 
    4     d 
    1     a     90 
    2     b     98 
    3     c     95 
    注:access 中不能直接使用full join ,需要使用union all 將左連接和右連接合并后才可以

    交叉連接
    將兩個(gè)表所有行組合,連接后的行數(shù)為兩個(gè)表行數(shù)的乘積(笛卡爾積)
    語(yǔ)法,借用上面的例子應(yīng)該是
    select * from student cross join grade

    行數(shù)應(yīng)該為12行 :
    no name grade 
    1     a     90 
    2     b     98 
    3     c     95 
    4     d  
    1     a     90 
    2     b     98 
    3     c     95 
    4     d 
    1     a     90 
    2     b     98 
    3     c     95 
    4     d 

    posted @ 2011-11-30 17:24 AK47 閱讀(498) | 評(píng)論 (0)編輯 收藏

    JAXB向Xml非根節(jié)點(diǎn)添加一個(gè)或多個(gè)屬性

    JAXB 向Xml非根節(jié)點(diǎn)添加一個(gè)或多個(gè)屬性,直接上代碼,關(guān)于JAXB的相關(guān)注解可查閱JAVA API。

    原創(chuàng)文章,轉(zhuǎn)載請(qǐng)注明出處。http://www.tkk7.com/kangdy/archive/2011/11/23/364635.html

    code1: colors類  根節(jié)點(diǎn)
    code1
    package com.kangdy.test;

    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;

    @XmlRootElement(name = "Colors")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Colors {
        
        @XmlElement(name = "red",nillable=true)
        private Red red;
        
        @XmlElement(name = "blue",nillable=true)
        private Blue blue;

        public Red getRed() {
            return red;
        }

        public Blue getBlue() {
            return blue;
        }

        public void setRed(Red red) {
            this.red = red;
        }

        public void setBlue(Blue blue) {
            this.blue = blue;
        }
    }

    code2:  Red類  子節(jié)點(diǎn)
    code2package com.kangdy.test;

    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlAttribute;
    import javax.xml.bind.annotation.XmlRootElement;

    @XmlRootElement(name = "red")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Red {
        
        private String value;
        
        @XmlAttribute(name = "att1")
        private String att;
        
        public String getValue() {
            return value;
        }
        
        public void setValue(String value) {
            this.value = value;
        }

        public String getAtt() {
            return att;
        }

        public void setAtt(String att) {
            this.att = att;
        }
        
    }


    code3:  類 Blue 子節(jié)點(diǎn)
    code3
    package com.kangdy.test;

    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlAttribute;
    import javax.xml.bind.annotation.XmlRootElement;

    @XmlRootElement(name = "blue")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Blue {
        private String value;
        
        @XmlAttribute(name = "att2")
        private String att2;
        
        @XmlAttribute(name = "att1")
        private String att;
        
        public String getAtt() {
            return att;
        }

        public void setAtt(String att) {
            this.att = att;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public String getAtt2() {
            return att2;
        }

        public void setAtt2(String att2) {
            this.att2 = att2;
        }
    }

    code4: main類
    code4
    package com.kangdy.test;

    import java.io.StringWriter;

    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Marshaller;

    public class Jaxbtest {
        public static void main(String[] args) throws Exception {

            StringWriter writer = new StringWriter();
            JAXBContext jc = JAXBContext.newInstance(Colors.class);
            Marshaller ma = jc.createMarshaller();
            ma.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            
            Colors colors = new Colors();
            Red red = new Red();
            red.setAtt("att-red");
            red.setValue("red");
            Blue blue = new Blue();
            blue.setValue("blue");
            blue.setAtt("att-blue");
            blue.setAtt2("blue-att2");
            colors.setRed(red);
            colors.setBlue(blue);
            
            ma.marshal(colors, writer);
            System.out.println(writer.toString());

        }
    }

    運(yùn)行結(jié)果:
    結(jié)果
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Colors>
        <red att1="att-red">
            <value>red</value>
        </red>
        <blue att1="att-blue" att2="blue-att2">
            <value>blue</value>
        </blue>
    </Colors>

    posted @ 2011-11-23 14:33 AK47 閱讀(10146) | 評(píng)論 (4)編輯 收藏

    (轉(zhuǎn)載)關(guān)于paramsPrepareParamsStack

    原帖地址:
    http://hi.baidu.com/%CC%AB%C6%BD%D1%F31986/blog/item/110b13b1384e805e08230259.html
    轉(zhuǎn)貼

    paramsPrepareParamsStack在Struts 2.0中是一個(gè)很奇妙的interceptor stack,以至于很多人疑問(wèn)為何不將其設(shè)置為默認(rèn)的interceptor stack。paramsPrepareParamsStack主要解決了ModelDriven和Preparable的配合問(wèn)題,從字面上理解來(lái)說(shuō), 這個(gè)stack的攔截器調(diào)用的順序?yàn)椋菏紫萷arams,然后prepare,接下來(lái)modelDriven,最后再params。Struts 2.0的設(shè)計(jì)上要求modelDriven在params之前調(diào)用,而業(yè)務(wù)中prepare要負(fù)責(zé)準(zhǔn)備model,準(zhǔn)備model又需要參數(shù),這就需要在 prepare之前運(yùn)行params攔截器設(shè)置相關(guān)參數(shù),這個(gè)也就是創(chuàng)建paramsPrepareParamsStack的原因。流程如下:
       1. params攔截器首先給action中的相關(guān)參數(shù)賦值,如id  
       2. prepare攔截器執(zhí)行prepare方法,prepare方法中會(huì)根據(jù)參數(shù),如id,去調(diào)用業(yè)務(wù)邏輯,設(shè)置model對(duì)象
       3. modelDriven攔截器將model對(duì)象壓入value stack,這里的model對(duì)象就是在prepare中創(chuàng)建的
       4. params攔截器再將參數(shù)賦值給model對(duì)象
       5. action的業(yè)務(wù)邏輯執(zhí)行 依據(jù)此stack,一個(gè)action的代碼通常如下

    public class UserAction extends ActionSupport implements ModelDriven, Preparable {
        private User user;
        private int id;
        private UserService service; // user business service

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

        /**
         * create a new user if none exists, otherwise load the user with the
         * specified id
         */
        public void prepare() throws Exception {
            if (id == 0) {
                user = new User();
            } else {
                user = service.findUserById(id);
            }
        }

        public Object getModel() {
            return user;
        }

        /**
         * create or update the user and then view the created user
         */
        public String update() {
            if (id == 0) {
                service.create(user);
            } else {
                service.update(user);
            }
            return "redirect";
        }

        /**
         * delete the user and go to a default home page
         */
        public String delete() {
            service.deleteById(id);
            return "home";
        }

        /**
         * show the page allowing the user to view the existing data
         */
        public String view() {
            return "view";
        }

        /**
         * show the page allowing the user to view the existing data and change the
         * values
         */
        public String edit() {
            return "input";
        }

    在上述代碼中,edit和view都不需要根據(jù)id再為界面準(zhǔn)備數(shù)據(jù),因?yàn)閜repare方法已經(jīng)準(zhǔn)備好了model,這些方法很簡(jiǎn)單。對(duì)于update 方法,prepare首先會(huì)從數(shù)據(jù)庫(kù)中加載數(shù)據(jù),然后params攔截器會(huì)將參數(shù)值付給model,在update直接更新就可以,不會(huì)出現(xiàn)數(shù)據(jù)被亂更新 的情況。象Hibernate框架,會(huì)判斷哪些字段更新了,然后進(jìn)行更新,性能也不會(huì)損失。
    通過(guò)paramsPrepareParamsStack可以讓流程更明確,代碼更簡(jiǎn)潔,也更利于大家的交流。

    posted @ 2011-11-16 15:39 AK47 閱讀(447) | 評(píng)論 (0)編輯 收藏

    <2011年11月>
    303112345
    6789101112
    13141516171819
    20212223242526
    27282930123
    45678910

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿

    隨筆分類

    隨筆檔案

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 日韩亚洲AV无码一区二区不卡 | 一二三四在线播放免费观看中文版视频 | 中文在线免费不卡视频| 国产91久久久久久久免费| 亚洲中文字幕久久久一区| 五月婷婷在线免费观看| 亚洲精品日韩中文字幕久久久| 免费看男人j放进女人j免费看| 亚洲午夜久久久久久久久久| 国产特黄特色的大片观看免费视频| 亚洲伊人久久大香线蕉AV| 美女被cao免费看在线看网站| 亚洲av乱码一区二区三区| 在线观看免费高清视频| 亚洲国产aⅴ成人精品无吗| 又粗又硬免费毛片| 好吊色永久免费视频大全| 亚洲精品色午夜无码专区日韩| 91成人免费福利网站在线| 亚洲bt加勒比一区二区| 青娱乐免费在线视频| 亚洲AV无码一区二区大桥未久| 免费一级成人毛片| 永久免费av无码网站yy| 久久精品国产亚洲AV忘忧草18 | 亚洲男人第一无码aⅴ网站| 男女拍拍拍免费视频网站| 亚洲一区二区三区电影| 精品国产一区二区三区免费看| 日韩在线观看免费完整版视频| 亚洲午夜久久久久久久久久| 黄色网址免费大全| 添bbb免费观看高清视频| 日韩人妻一区二区三区免费| 亚洲AV无码成人专区| 亚洲av中文无码| 久久久精品2019免费观看| 亚洲精品无码久久久久APP| 久久久久一级精品亚洲国产成人综合AV区| 国产午夜无码精品免费看| 亚洲熟妇丰满xxxxx|