(MIS information management system actual combat development of independent use of files to achieve retention
development set
ID, name, age are public information, while students have results and workers have pay
Define an abstract class Person (ID, name, age), students are its subclasses, have achievements, and workers are its subclasses and have pay
How is ID defined?
It is best to generate the ID yourself, and the best way is to adopt the following encoding method:
·Symbol time stamp three-digit random number
·Example: March 2009 2220:10:10.345
The symbol for students is s and the symbol for workers is w
· Generated ID number: student --gt;s20090322201010345023
worker --gt;w20090322201010345023
Since today's programs have to satisfy the operating specifications of files and databases, a common specification - interface should be defined here
When querying information, the sorting operation can be performed, and the Comparable interface can be used to terminate.
Operations involving the data layer in the comprehensive code
· The data layer refers to the actual data operations -- gt; CRUD.
·It must be one person (human workers and students) who will operate the final result
There should be separation, one is comprehensive student management and the other is comprehensive worker management.
After the data layer operation specification definition ends, there are two options. One is to directly use subclasses to implement, but future repairs are not very convenient.
Therefore, it is best to use the design idea to end and be an intermediate layer.
Code Contact:
Main--gt;Menu--gt<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>ersonOperate--gt;DAO
Since the program requests both file retention and database retention, a factory can be designed here, and the DAO operation subclass instance can be obtained through this factory.
PersonDAO.java
packageorg.michael.demo.dao;
importjava.util.Set;
importorg.michael.demo.vo.Person;
//define the operation method of the detailed data
publicinterfacePersonDAO{
/
Operations that penetrate data
@paramperson
A person's information was stabbed
@return operation success or not
@throwsException
If there is an error, throw the error to the caller for management
/
publicbooleandoCreate(Personperson) throwsException;
/
update data operation
@paramperson
updated details
@return update success or not
@throwsException
If there is an error, throw the error
/
publicbooleandoUpdate(Personperson) throwsException;
/
Delete information by id
@paramid
Person's number
@return to delete or not
@throwsException
If there is an error, it is managed at the caller
/
publicbooleandoDelete(Stringid) throwsException;
/
Since there are multiple queries, it is necessary to return the Set call
@return comprehensive query results, a Set includes multiple Person targets
@throwsException
/
publicSetlt<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>ersongt;findAll() throwsException;
/
query by id
@paramid
Person's number
@return detailed personnel information
@throwsException
/
publicPersonfindById(Stringid) throwsException;
/
Search by keyword
@paramkeyWord
Entered keywords
@return returns a set of information
@throwsException
/
publicSetlt<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>ersongt;findByLike(StringkeyWord)throwsException;
}
PersonDAOImplFile.java
packageorg.michael.demo.dao.impl;
importjava.util.Iterator;
importjava.util.Set;
importjava.util.TreeSet;
importorg.michael.demo.dao.PersonDAO;
importorg.michael.demo.io.FileOperate;
importorg.michael.demo.vo.Person;
importorg.michael.demo.vo.Student;
importorg.michael.demo.vo.Worker;
publicclassPersonDAOImplFileimplementsPersonDAO{
//All content must be kept in a set, because a set can be directly reserved to the file
//The content of this ensemble is best read from the file, because the file itself needs to retain the target,
//But this program involves the status of the first run
privateSetlt<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>ersongt;allPerson;
privateFileOperatefo=null;
publicstaticStringfileName=null;
//Instantiate it in the struct method
@SuppressWarnings(unchecked)
publicPersonDAOImplFile(){
this.fo=newFileOperate(fileName);
try{
this.allPerson=(Set)fo.load();
}catch(Exceptione){
e.printStackTrace();
}
}
publicbooleandoCreate(Personperson) throwsException{
// is the stab operation
//Increase on the original basis
booleanflag=false;
try{
this.allPerson.add(person);
this.fo.save(this.allPerson);
flag=true;
}catch(Exceptione){
throwe;
}
returnflag;
}
publicbooleandoDelete(Stringid)throwsException{
booleanflag=false;
//If you want to delete, you must first perform a search operation
try{
this.allPerson.remove(this.findById(id));
this.fo.save(this.allPerson);
flag=true;
}catch(Exceptione){
throwe;
}
returnflag;
}
publicbooleandoUpdate(Personperson) throwsException{
//No matter how it is updated, the id inside cannot be changed
booleanflag=false;
try{
Personp=this.findById(person.getId());
if(person
abbr_ee4a125ec5654e72ed0be840842eb27c.doc)