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查询数据,不需要专门创建实体类和配置文件:
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;
}
}
异步调用类CRUDServiceAsync.java:
package client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface CRUDServiceAsync {
void getStudent(AsyncCallback async);
}
最后,在src目录下创建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>
分享到:
相关推荐
【标题】"班费管理系统IEDA+Jsp+Tomcat+Servlet.zip" 是一个基于Java Web技术开发的项目,主要用于管理班级财务。该项目利用了IntelliJ IDEA(简称IEDA)作为集成开发环境,JSP(JavaServer Pages)作为动态网页技术...
标题 "Spring+Mybatis+mysql简单的Student增删改查" 提到的是一个使用Spring MVC、MyBatis和MySQL数据库实现的基础Web应用示例,主要涵盖了数据操作的核心功能:增(添加)、删(删除)、改(修改)和查(查询)。...
该项目为通过IDEA使用Hibernate框架,详细制作过程见文章:https://blog.csdn.net/qq_37400312/article/details/105027562 数据库默认并不是本地数据库,所以运行的时候记得去hibernate.cfg.xml改为所用的数据库...
3. 安装并配置MySQL数据库,创建对应的数据库和表结构。 4. 导入源码项目到IDE(如Eclipse、IntelliJ IDEA)中。 5. 配置Web服务器的部署路径和数据库连接信息。 6. 在Web服务器上部署并启动项目,通过浏览器访问。 ...
对于Java开发来说,使用IntelliJ IDEA(简称IEDA)这样的集成开发环境(IDE)进行 HelloWorld 代码的编写,能快速帮助新手熟悉开发环境的使用。下面我们将详细讲解如何在IEDA中创建和运行一个 HelloWorld 程序。 ...
阻塞IO模式就是一个客户端连接到服务端,服务端就为每个新的客户端 Socket 创建一个新的 Thread。 Netty的书我帮你看!---什么是Netty 什么是Socket?Socket就是你想用Java代码API去组织数据,指定协议去通讯,很烦!...
在图书馆信息管理系统中,MySQL用于创建和管理图书、读者和管理员的相关表,如图书信息表(包括书名、作者、出版社等)、读者信息表(包括姓名、身份证号、借阅历史等)以及管理员信息表(用于记录管理员登录信息和...
- **DES**: Data Encryption Standard,一种古老的对称加密算法,已被AES取代,但仍在某些场景下使用。 - **AES**: Advanced Encryption Standard,现代对称加密的标准,速度快,安全性高,广泛应用于各种加密系统...
通过内嵌的Tomcat服务器、自动配置和起步依赖,Spring Boot使得创建独立的、生产级别的基于Spring的应用变得极其简单。 首先,Spring Boot的核心特性之一是“约定优于配置”。这意味着在很多情况下,开发者不需要...
Source Insight 4.0 仿IEDA Darcula 主题,配色非常赞!!!!!!
可以用于java开发工具IDEA的破解,简单小巧,绝对好用!
IEDA常用快捷键一览表
"demo_memcache_ieda"项目是一个很好的学习资源,通过对比spymemcached和XMemcached这两个客户端,开发者可以了解如何在Java项目中集成并使用Memcached,从而优化应用性能,实现高效的数据缓存。
文档包含了ieda所有的常用快捷键,在开发的过程中方便、便捷
Java IEDA的基础导图.xmind
JDK11和IEDA的安装与配置教程
最新intellij ieda golang 插件2013-11-27日编译
例如,查询界面可能由一个JSP页面实现,用户可以在其中输入职位或姓名,提交后,这个页面会发送请求到对应的Servlet,Servlet处理完查询后,再将结果显示回这个JSP页面。 运行环境方面,IntelliJ IDEA是一个强大的...
保姆级JDK和IEDA的详细安装步骤,您值得拥有,帮助您可以更好的入门java
开发者会使用SQL语句来操作数据库,如插入、更新、查询和删除数据。 4. **表单提交和验证**: 在登录页面,用户输入的账号和密码通过HTTP POST请求提交到服务器,服务器端的JSP或Servlet会验证这些信息。这涉及到...