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

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

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

    CRUD.gwt.xml:

    <module>

        <inherits name='com.google.gwt.user.User'/>

        <entry-point class='client.CRUD'/>

        <servlet path="/CRUD/CRUDService" class="server.CRUDServiceImpl"/>
    </module>

    EntryPoint:CRUD.java,使用VerticalPanel 來顯示List:

    package client;

    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.*;
    import com.google.gwt.user.client.rpc.AsyncCallback;

    public class CRUD implements EntryPoint {
        VerticalPanel main = new VerticalPanel();
        FlexTable lb = new FlexTable();
        public void onModuleLoad() {
            main.add(lb);
            RootPanel.get().add(main);
                  CRUDService.App.getInstance().getStudent(new AsyncCallback(){

                      public void onFailure(Throwable caught) {
                          //To change body of implemented methods use File | Settings | File Templates.
                      }

                      public void onSuccess(Object result) {
                        Student s[] = ( Student[])result ;
                          for (int i=0;i<=s.length;i++){
                         lb.setText(i,0,s[i].id);
                              lb.setText(i,1,s[i].name);
                              lb.setText(i,2,s[i].email);                          
                          }
                      }
                  }) ;
        }
    }

    ENTITY:Student.java:

    package client;

    import com.google.gwt.user.client.rpc.IsSerializable;

    public class Student implements IsSerializable {
        public String id,name,email;
        public Student(){
           
        }
        public Student(String id,String name,String email) {
        this.id=id;
        this.name=name;
        this.email=email;   
        }
    }

    SERVICE:CRUDService.java:

    package client;

    import com.google.gwt.user.client.rpc.ServiceDefTarget;
    import com.google.gwt.user.client.rpc.RemoteService;
    import com.google.gwt.core.client.GWT;

    public interface CRUDService extends RemoteService {

         Student[] getStudent()     ;

        public static class App {
            private static CRUDServiceAsync ourInstance = null;

            public static synchronized CRUDServiceAsync getInstance() {
                if (ourInstance == null) {
                    ourInstance = (CRUDServiceAsync) GWT.create(CRUDService.class);
                    ((ServiceDefTarget) ourInstance).setServiceEntryPoint(GWT.getModuleBaseURL() + "CRUD/CRUDService");
                }
                return ourInstance;
            }
        }
    }


    SERVICEImpl:CRUDServiceImpl.java,這里使用直接連接hibernate的方法用native sql查詢數(shù)據(jù),不需要專門創(chuàng)建實體類和配置文件:

    package server;

    import com.google.gwt.user.server.rpc.RemoteServiceServlet;
    import client.CRUDService;
    import client.Student;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Hibernate;
    import org.hibernate.cfg.Configuration;
    import java.util.List;
    import java.util.Iterator;

    public class CRUDServiceImpl extends RemoteServiceServlet  implements CRUDService {
        private static final SessionFactory sessionFactory;      
        static {
                try {
                    sessionFactory = new Configuration().configure().buildSessionFactory();
                } catch (Throwable ex) {
                    System.err.println("Initial SessionFactory creation failed." + ex);
                    throw new ExceptionInInitializerError(ex);
                }
            }

            public static SessionFactory getSessionFactory() {
                return sessionFactory;
            }

        public List ListStudent(){
           Session session =  getSessionFactory().getCurrentSession() ;
            session.beginTransaction();
             List ls = session.createSQLQuery("select * from t_student")
            .addScalar("id", Hibernate.LONG)
            .addScalar("name", Hibernate.STRING)
            .addScalar("email", Hibernate.STRING).list();
            session.getTransaction().commit();
            return ls;
        }

        public int CountStudent(){
           Session session =  getSessionFactory().getCurrentSession() ;
            session.beginTransaction();
             List ls = session.createSQLQuery("select count(*) from t_student").list();
            session.getTransaction().commit();
            return Integer.parseInt(ls.iterator().next().toString());
        }

            public Student[] getStudent(){
                 Student[] student = new Student[this.CountStudent()];
                int i = 0;
              for(Iterator it = this.ListStudent().iterator();it.hasNext();i++) {
                 Object[] ob = (Object[] )it.next();
                    student[i]=new Student(ob[0].toString(),ob[1].toString(),ob[2].toString());
              }
                 return student;
              }

    }


    異步調(diào)用類CRUDServiceAsync.java:

    package client;

    import com.google.gwt.user.client.rpc.AsyncCallback;

    public interface CRUDServiceAsync {
        void getStudent(AsyncCallback async);
    }

    最后,在src目錄下創(chuàng)建hibernate.cfg.xml,這里使用mysql:

    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
      <session-factory>
    <property name="connection.driver_class">
      com.mysql.jdbc.Driver
     </property>
     <property name="connection.url">
      jdbc:mysql://localhost:3306/mysql
     </property>
     <property name="connection.username">root</property>
     <property name="connection.password">root</property>

     <!-- JDBC connection pool (use the built-in) -->
     <property name="connection.pool_size">1</property>

     <!-- SQL dialect -->
     <property name="dialect">
      org.hibernate.dialect.MySQLDialect
     </property>

     <!-- Enable Hibernate's automatic session context management -->
     <property name="current_session_context_class">thread</property>

     <!-- Disable the second-level cache  -->
     <property name="cache.provider_class">
      org.hibernate.cache.NoCacheProvider
     </property>

     <!-- Echo all executed SQL to stdout -->
     <property name="show_sql">true</property>

     <!-- Drop and re-create the database schema on startup -->
     <property name="myeclipse.connection.profile">mysql for j</property>
      </session-factory>
    </hibernate-configuration>

    posted on 2008-11-06 07:28 lzj520 閱讀(557) 評論(0)  編輯  收藏 所屬分類: Ajax個人學(xué)習(xí)日記HibernateGWT
    主站蜘蛛池模板: 国产精品无码亚洲精品2021| 最新亚洲春色Av无码专区| 未满十八私人高清免费影院| 亚洲AV无码成人精品区在线观看 | 国产精品玖玖美女张开腿让男人桶爽免费看| 亚洲免费在线观看视频| 亚洲性色高清完整版在线观看| 亚洲网站免费观看| 2020天堂在线亚洲精品专区| 一级毛片免费不卡| 亚洲精品成人网站在线观看| 免费91麻豆精品国产自产在线观看| 午夜亚洲www湿好大| 亚洲免费电影网站| 色综合久久精品亚洲国产| 亚洲第一黄片大全| 三年片免费高清版| 亚洲黄色在线观看| 免费无码又黄又爽又刺激| 黑人粗长大战亚洲女2021国产精品成人免费视频 | 久久久久亚洲AV片无码下载蜜桃| 免费视频爱爱太爽了| 亚洲免费综合色在线视频| 亚洲乱码国产一区网址| 国产精品免费观看调教网| 亚洲制服丝袜第一页| 免费久久精品国产片香蕉| 在线免费观看伊人三级电影| 亚洲人成在线免费观看| 亚洲av无码国产精品色在线看不卡| 免费无码又爽又刺激一高潮| 亚洲国产视频网站| 亚洲A丁香五香天堂网| 3344永久在线观看视频免费首页| 亚洲精品无码少妇30P| 亚洲人成精品久久久久| 丁香花在线观看免费观看| 国产区在线免费观看| 亚洲xxxx18| 亚洲国产第一站精品蜜芽| 日韩免费高清视频网站|