java Google Web Toolkit (GWT) 创建读取更新和删除 (CRUD) 应用程序的示例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4064419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
An example of a Google Web Toolkit (GWT) Create Read Update and Delete (CRUD) Application
提问by
Hello
Does anybody know of any examples of a Google Web Took (GWT) - based Create Read Update and Delete application.
That is, an application which uses the GWT to manipulate and display the contents of a database.
您好
有谁知道基于 Google Web Took (GWT) 的 Create Read Update 和 Delete 应用程序的任何示例。
即,使用 GWT 来操作和显示数据库内容的应用程序。
Thanks
谢谢
采纳答案by Carlos Tasada
GWT is a client side technology, so basically gives you only the UI. Any CRUD process would happen in the server side, which could be any J2EE code.
GWT 是一种客户端技术,所以基本上只给你 UI。任何 CRUD 过程都将发生在服务器端,可以是任何 J2EE 代码。
Anyway you can take a look to the StockWatcher Examplewhich gives you a good approach to your question (you need to implement the server side storage)
无论如何,您可以查看StockWatcher Example,它为您提供了解决问题的好方法(您需要实现服务器端存储)
Also take a look to the RequestFactorydocumentation
另请查看RequestFactory文档
Does it help you?
它对你有帮助吗?
回答by sap
There are not too many such examples online. But this is how I usually do it:
网上没有太多这样的例子。但这就是我通常这样做的方式:
Lets assume that you want to get all the contents of a certain table from the database:
假设您想从数据库中获取某个表的所有内容:
in GreentingService.java do following:
public interface GreentingServiceextends RemoteService { ArrayList getEverything(); }
in GreentingServiceSync.java do following:
public interface GreentingService { void getEverything(AsyncCallback callback); }
finally in GreentingServiceImpl do following:
public class GreentingServiceIMPL extends RemoteSericeServlet implments GreentingService { public ArrayList<String> getEverything() { String query="Select * from...."; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn=DriverManager.getConnection(url,user,password); Statement stmt = conn.createStatement(); //get stuff out of daatabase here and retun as an arraylist } }
this is how you will call this method and use the data: public Someclass implements EntryPoint { public void onModuleload() { SQLRunnerAsync sql = (SQLRunnerAsync) GWT.create(SQLRunner.class); AsyncCallback> callback = new AsyncCallback>(){
@Override public void onFailure(Throwable caught) { //do nothing } @Override public void onSuccess(ArrayList<String> result) { for(int i = 0; i < result.size(); i++) { } }}; sql.getEverything(callback);
............... }//onModulelOad }//class
在 GreentingService.java 中执行以下操作:
公共接口 GreentingServiceextends RemoteService { ArrayList getEverything(); }
在 GreentingServiceSync.java 中执行以下操作:
公共接口 GreentingService { void getEverything(AsyncCallback callback); }
最后在 GreentingServiceImpl 中执行以下操作:
public class GreentingServiceIMPL extends RemoteSericeServlet implments GreentingService { public ArrayList<String> getEverything() { String query="Select * from...."; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn=DriverManager.getConnection(url,user,password); Statement stmt = conn.createStatement(); //get stuff out of daatabase here and retun as an arraylist } }
这是您将如何调用此方法并使用数据: public Someclass 实现 EntryPoint { public void onModuleload() { SQLRunnerAsync sql = (SQLRunnerAsync) GWT.create(SQLRunner.class); AsyncCallback> callback = new AsyncCallback>(){
@Override public void onFailure(Throwable caught) { //do nothing } @Override public void onSuccess(ArrayList<String> result) { for(int i = 0; i < result.size(); i++) { } }}; sql.getEverything(callback);
...... }//onModulerOad }//类
Following is a great tutorial: http://altair.cs.oswego.edu/~tenberge/tenbergen.org/misc/DB-Access-in-GWT-The-Missing-Tutorial.pdf
以下是一个很棒的教程:http: //altair.cs.oswego.edu/~tenberge/tenbergen.org/misc/DB-Access-in-GWT-The-Missing-Tutorial.pdf
回答by Low Flying Pelican
This is a skeleton CRUD application, I this would be helpful for someone looking answer for the same question
这是一个框架 CRUD 应用程序,这对寻找同一问题答案的人会有所帮助
回答by kaefert
This is a web-based CRUD-Application that I've wrote for my employer over the last few years and now got permission to open-source it:
这是一个基于 Web 的 CRUD 应用程序,我在过去几年中为我的雇主编写,现在已获得开源许可:
https://github.com/fhcampuswien/atom
https://github.com/fhcampuswien/atom
It uses GWT for the front-end and Hibernate to persist the data in the backend. The data-structure only needs to be defined in one central place (the DomainObject classes), since both GUI and backend are written in a generic way that is not dependent on the data-structure.
它在前端使用 GWT,在后端使用 Hibernate 来持久化数据。数据结构只需要在一个中心位置(DomainObject 类)定义,因为 GUI 和后端都是以不依赖于数据结构的通用方式编写的。
I'd love to hear comments or answer questions about it if anybody finds the time to take a look.
如果有人有时间看一看,我很乐意听取评论或回答有关它的问题。