Basic implementation of Java EE

Source: Internet
Author: User

Java EE implementation, the most important is the idea, there is a realization of the logic and ideas will make the code implementation clearer

The approximate process is as follows: (note: Each step must have the corresponding package, so do not disorderly, more clear thinking)

1, build the database, build the table

2. Create an entity class, corresponding to the corresponding table in the database

property of the corresponding table in the entity class and the setter and getter methods of the property

The code is as follows:

3. Create the base class of DAO, an interface class Basedao

There are methods in the interface class to implement this interface while implementing the method inside

4. Create a DAO implementation class Basedaoimpl

When implementing the Basedao interface, a tool class is used Dbutil

Tool class Dbutil:

The code is as follows:

JDBC: is a file that is passed into the corresponding database

Content:

5. Create a specific table of DAO (is an interface that has method declarations in the interface)

For example: public int executeupdate (String sql, object[] param);

6. Creating a DAO implementation class for a specific table

The code is as follows:

7. Create an interface class for the business Logic layer (an interface with method declarations in the interface):

Format: Table Name Service

For example:

Public interface Masterservice {

Public Master Login (String loginid,string password);

}

8. The implementation class of the interface class to create the business logic layer

For example: The code is as follows:

public class Masterserviceimpl implements masterservice{

@Override
Public Master Login (string loginId, string password) {//implementation method
Masterdao masterdao=new Masterdaoimpl ();// Call the implementation class of the DAO class that corresponds to the table in the database and receive it with the corresponding table DAO
Return Masterdao.findmasterbyloginidandpassword (loginId, password);
}

}

9, finally create the test class, test

The code is as follows:

ImportJava.util.Scanner;ImportCom.beiwo.epet.entity.Master;ImportCom.beiwo.epet.service.MasterService;ImportCom.beiwo.epet.service.impl.MasterServiceImpl; Public classTestmasterdao {@Test Public voidTestlogin () {Masterservice Masterservice=NewMasterserviceimpl (); Scanner input=NewScanner (system.in); System.out.println ("Please enter user name:"); String loginId=input.nextline (). Trim ();//remove the spaces at both endsSystem.out.println ("Please enter your password:"); String Password=input.nextline (). Trim (); Master Master=masterservice.login (loginId, password); if(NULL!=Master) {System.out.println ("Successful Landing"); }Else{System.out.println ("Login Failed"); }                            }    }

1) The process of other tables in the database is basically consistent with the above process

2) implementations of other tables in DAO class, to implement the DAO class while inheriting the DAO's base class Basedao

Such as:

3) DAO Implementation Class invoke tool class Dbutil

The other table's DAO implementation class calls the corresponding table's entity class (property's Get, set method)

The implementation class of the service calls the implementation class of the DAO class (Received with the DAO class's object)

The test class invokes the service's implementation class (calling method)

  

Probably the process is this, there is no shortage of people ask for advice, leaving valuable advice!!!

Basic implementation of Java EE

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.