/**
* @author Mr.deng
* @since 2016-5-14
* @version 1.0
* Easy to read with Notepad open
* Welcome to correct the mistake, write down your own opinion
*/
Project Description: User login can manage the management of their own correspondence records.
Project dependent software: MySQL eclipse.
Project-dependent technologies: Javase, JDBC, swing components
1. Architecture: 3-tier architecture
1. Presentation layer: 1. Users can only operate on themselves and their contacts (private permissions)
2. Using the Java GUI image interface:
1. Login to register the main page interface
2. Registration page
3. Function page: Press the upper and lower 3 layer interface layout:
1. On: Welcome window
2. In: Display the user all Address book information details
3. Next: User-to-Address contacts action button
2. Business layer: 1. Background personnel actions for all users (Administrator privileges)
2. Using Java to write a daemon: Writing interfaces and implementing class implementation classes by calling the persistence layer-written interface implementation functions
3. Persistence layer: 1.java programmers implement various operations by writing source code (creator)
2. Using the JDBC Connection database to save data
3. Use the configuration file to connect to JDBC, if the database is modified. Only need to modify the configuration file does not need to modify the source code
Implementation: 3-tier architecture each layer is connected via an interface (dependency)
1. Presentation Layer---Business layer: 1. Interface: Usersservice,contactsservice
2. Implementation class: Usersserviceimpl,contactsserviceimpl
Effect: Data or operations obtained by the presentation layer are passed into the business layer
Business layer Process: 1. Calling the interface of the persistence layer
2. Creating an Interface Object
3. Invoking methods on the interface object for data manipulation
Principle: 1. Interface only defines method body, no implementation details, cannot create object directly
The 2.ContactDaoImpl class is an implementation class that overrides all the methods of an interface and has implementation details
3. Instantiate the interface by creating an implementation class object. Interface can invoke all the methods of the implementation class and operate
Contactdao ctd = new Contactdaoimpl ();
2. Business Layer---persistence layer: 1. Interface: Usersdao
2. Implementation class: Usersdaoimpl
Action: Perform various operations on the data and put it into the database
Principle: 1. Contacts and user objects exist with the invocation of the method, and the end object of the method call disappears.
2. Objects exist in memory, and the database can be stored on the object by JDBC connection.
3. Persistence Layer---Presentation layer: All features of the persistence layer depend on the data obtained by the presentation layer
There is no point in the existence of a data persistence layer
Without the functionality of the persistence layer, the presentation layer doesn't make any sense.
2. Package naming specification:
1. Persistence layer: 1.com.lovo.contacts.bean: The entity package holds all the entity objects, Users,contactsdetail follows the JavaBean specification, implements the serialization interface serializable
2.com.lovo.contacts.dao: Interface Pack holds all interfaces for the persistence layer
3.com.lovo.contacts.dao.impl: Implementation class holds all classes that implement the DAO package interface
4.com.lovo.contacts.util: Toolkit stores all the tools required for persistent layer code, such as files, Dbutil
2. Business layer: 1.com.lovo.contacts.service: Business Layer Package stores all business layer interfaces Usersservice,contactsservice
2.com.lovo.contacts.service.impl: Implementation class package holds all implementation classes that implement the business layer package interface
3. Presentation layer: Com.lovo.contacts.gui: Graphical Interface Pack for all UI classes
4.javabean specification: 1. public class
2. Privatization of properties
3. Provision of public get,set methods
4. Method of construction without parameters
5. Implementation of the serialization interface serializable
Summary: 1. Naming normalization ensures that the project is understandable and easy to manage. Projects are written by multiple programmers to make a good naming specification and structure easy to change for synchronization
2. Each project has its own naming convention, broadly consistent
3. Parties block Code Flow: 1. Get database connection: Connection con = dbutil.getconnection
2. Writing SQL statements, using question marks to prevent SQL injection
3. Create a precompiled Processing object: PreparedStatement pstmt = con.prepardstatement (sql);
4. Change the value of a question mark
5. Execute the SQL statement:
1. Increase: 1. (SQL, Preparedstatement.return_generated_keys) to keep the primary key from growing,
2. Get the value on the object, set it to the corresponding field in the database
3. Get the database result set and decide to set the ID of the first object to 1, and multiple objects to self-grow
4. Close the connection
2. Check: 1. query all field values into the result set, condition id=? and Status=1 1 means that there is
2. Create a new Contactdetail object,
3. Set the corresponding value of the result set to the Contactdetail object
4. Close the connection
3. Delete: The 1.status field represents the state of the table, which is only available to the user when the query statement is Status=1.
2. Set Status=0 users cannot query this table. Tombstone: The data still exists, but the user cannot query. Physical deletion: Data disappears from the database
3. Updating the database
4. Close the connection
4. Change: 1. The user passes in the Contactdetail object, and some fields have a modified value.
2. Get the value of the Contactdetail object
3. Overwrite the value of each field in the Contactdetail field in the database
4. Close the connection
Extended:
1. Custom exceptions: 1. Define the properties and methods of the exception class inheritance exception
2. Construction method with parameter and non-parameter
Public namenotfoundexception () {}
Public namenotfoundexception (String message) {super (message);}
3. Judgment statement If the user name is incorrect throw new Namenotfoundexception ("User name does not exist");
2.try{}finally{} function: Ensures that an exception within a try block can execute the contents of a finally block
Summary: 1. Changes to the data in the database need to be updated. Query does not need
2. Analyze the function to clarify the thinking, and then write the process notes. Finally populate the code with the process comments.
3. The parameter list is based on the return type. Write code flexibly, original AIM
4. Time Conversion:
1.util.date---sql.date:
1. Gets the number of milliseconds on the contact object, if not the number of milliseconds to get the system time, the ternary operator: condition? Expression 1 (true): Expression 2 (False)
Long time = detail.getcreatetime () = = null? System.currenttimemillis (): Detail.getcreatetime (). GetTime ();
2. Call the Sql.date class with the parameter construction method to pass the time in milliseconds to the time that the SQL packet was fetched
New Date (Time))
2.sql.date---util.date:
1. Gets the number of milliseconds for the sql.date, passing it as a parameter to the constructor class of the Util.date
New Java.util.Date (Rs.getdate ("D.createtime"). GetTime ())
5. Attribute object: 1.sql User table is a 1-to-many relationship with the detail table, and can have multiple contacts
2. Put a user object in the Contactdetail class and connect the user class to the Contactdetail class
User.getid () = Contactdetail.getuser (). GetID ()
Implementing the Java User class and the Contactdetail Class 1-to-many relationship
Sql.userid----Contact.user
1. Create a User Object
2. Set the UserID to the user object
3. Analysis of the user's set method parameter is the user object, and the created object is passed into the user's Set method
6. Two-dimensional array: Define method in Business layer getallcontact return type: object[][] parameter: Useid
1. Get a collection of Contactdetail objects
list<contactdetail> list = Cd.querycontactlistbyuser (userId);
2. Define the array length, the first field indicates the number of Address book entities, and the 2nd field indicates the number of information in the Address Book
object[][] datas = new Object[list.size ()][8];
3. Loop the array loop once the first parenthesis +1, the 2nd bracket is placed in the Address book information
for (int i = 0; i < list.size (); i++) {
Contactdetail detail = List.get (i);
Datas[i][0] = Detail.getid ();
DATAS[I][1] = Detail.getname ();
。。。。。。。。。。。。。。。。 }
4. Return to Datas
Eclipse: Import Project: File---Import---Existing Projects into Workspace---Select project path---Finish
Import Picture: project name---SRC---general---file system---Files path---Select Picture--finish---Move the picture to the Lib package
Generate Document: Project RIGHT---export---java---javadoc---Select the build path---finish
Java Rack Package: Project Right---export---java---jar file select build path----Rack Name---Finish
Import Rack Package: Copy Rack package to project---build path
Interface plug-in use: Class right---Open with---windowbuilder editor---The lower left corner of the design button
This article is from the "allow you to ask me" blog, please be sure to keep this source http://dycode.blog.51cto.com/11459164/1817859
Address Book Project details