如何在GWT Web应用程序中正确实现DAO? [英] How to correctly implement a DAO in a GWT web app?

查看:104
本文介绍了如何在GWT Web应用程序中正确实现DAO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要回答有关DAO和GWT的几个问题。
我正在GWT项目中实现DAO类,并且想在按下按钮时使用它,例如:(在.java GWT类内部)

I have a couple of questions to be answered relating DAOs and GWT. I'm implementing a DAO class in the GWT project and I want to use it when a button is pressed, like this: (inside the .java GWT class)

      lookUpButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
              lookup();
            }
          });  
    ...    ...     ...
       private void lookup() {
          PersonDao dao = new PersonDao();
          Person m = dao.getPerson(3); //hard-coded the pk of the person
          resultsFlexTable.setText(1, 0, m.toString());




  • 我在这里遇到两个问题,首先是可行的,当我编译项目时,出现错误,并且在浏览器中显示失败,请重试,并且我无法运行它。

    • I get two problems here, the first is practical, when I compile the project, I get an error and it just says "failed, try again" in my browser and I cannot run it.

      我的第二个问题是:在DWT类中使用DAO,因为它可以直接编译成AJAX,这真的是一个好习惯吗?还是我应该将请求发送到已声明DAO并自行执行数据访问的servlet?

      The second question I have is this: Is it really a good practice to use a DAO in a GWT class given that it compiles directly into AJAX? Or should I send a request to a servlet that has said DAO and performs the data access itself?

      GWT是否提供易于理解的功能(对于初学者)?以及访问MySQL数据库以获取数据的更好方法?

      Does GWT provide an easy to understand (for a beginner) and better way to access a MySQL database to get data?

      (上下文:我正在尝试构建一个基本的数据库搜索引擎,我需要从GWT小部件访问这些数据
      我正在学习Java Web开发,并且我已经了解了.jsp,Servlet和其他一些更基本的东西,例如DAO。 $ b对于大学来说,我必须作为一个最终项目来构建一个必须使用GWT框架的Web应用程序。)
      我已经尝试过该文档,但是我实在无法解决,我陷入了困境。

      (Context: I'm trying to build a basic search engine for a database and I need to access said data from a GWT widget. I'm learning Java web development, and I've learnt about .jsp, Servlets, and some more basic stuff like DAOs. For college, I have to build as a final project a web application which necessarily must be using the GWT Framework.) I've already tried the documentation but I cannot really get through this, I'm stuck.

      推荐答案

      这不是gwt的工作原理....您不能简单地在UI端编写DAO层调用,

      This is not how gwt will work .... you can not simply write DAO layer call at UI side,

      GWT分为3部分-编写代码

      GWT is divided into 3 parts - to write the code


      • 客户端-编写UI代码

      • Shared -编写将在客户端和服务器端
        用于ex-Model / Pojo类的共享代码

      • 服务器-编写服务/函数/ JDBC方法

      • Client - to write the UI code
      • Shared - to write shared code which will be used in client as well as server side for ex - Model/Pojo classes
      • Server - to write services / function / JDBC methods

      应该总是这样-

      网站上有很多示例应用程序和示例。

      There are so many sample applications and examples available over sites.

      这里有一个简单的示例- https://github.com/davisford/gwt-demo/tree/master/src/main/java/com/example

      There is one simple example here - https://github.com/davisford/gwt-demo/tree/master/src/main/java/com/example

      这篇关于如何在GWT Web应用程序中正确实现DAO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆