[企业管理] [零基础学JAVA]Java SE实践开发-37.MIS信息管理系统实践开发[文

[复制链接]
发表于 2022-9-23 11:23:44
MIS信息管理系统实践开发之独自使用文件实现保留
开发布景
ID、名字、年纪为公共信息,而学生有成果,工人有薪酬
定义一个抽象类Person(ID、名字、年纪),学生是其子类,有成果,工人是其子类有薪酬
ID如何定义呢?
ID最好可以自己生成,最好的方法是采纳下面的编码方法:
·符号+时刻戳+三位随机数
·例如:2009年3月2220:10:10.345
·学生的符号为s,工人的符号为w
·生成的ID号:学生--gt;s20090322201010345023
工人--gt;w20090322201010345023
由于如今的程序要满意文件和数据库的操作规范,所以此处应当定义出一个公共的规范——接口
查询信息的时候可以进行排序操作,可以使用Comparable接口终结。
全面代码中牵扯到数据层的操作
·数据层就是指实在的数据操作--gt;CRUD。
·终究成果操作的必定是一个人(人为工人和学生)
应当进行分隔,一个是全面的学生管理,一个是全面的工人管理。
数据层操作规范定义终结今后,有两种选择,一种是直接使用子类实现,可是今后的修复不是很方便,
所以此处最好使用设计的思路终结,做一个中间层。
代码联系:
Main--gt;Menu--gt<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>ersonOperate--gt;DAO
由于程序即请求使用文件保留,又请求使用数据库保留,所以此处可以设计出一个工厂,通过此工厂进行DAO的操作子类实例获得。
PersonDAO.java
packageorg.michael.demo.dao;
importjava.util.Set;
importorg.michael.demo.vo.Person;
//定义详细的数据的操作方法
publicinterfacePersonDAO{
/
刺进数据的操作
@paramperson
刺进的是一个人员信息
@return操作成功与否的提示
@throwsException
假如有错误,则把错误抛给调用处管理
/
publicbooleandoCreate(Personperson)throwsException;
/
更新数据操作
@paramperson
更新的详细信息
@return更新成功与否的提示
@throwsException
假如有错误,则把错误抛出
/
publicbooleandoUpdate(Personperson)throwsException;
/
按id删去信息
@paramid
人员的编号
@return删去与否的提示
@throwsException
假如有错误,则在调用处管理
/
publicbooleandoDelete(Stringid)throwsException;
/
由于查询是多个,所以要回来Set调集
@return全面的查询成果,一个Set中包括了多个Person目标
@throwsException
/
publicSetlt<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>ersongt;findAll()throwsException;
/
按id进行查询
@paramid
人员的编号
@return详细的人员信息
@throwsException
/
publicPersonfindById(Stringid)throwsException;
/
按关键词进行查询
@paramkeyWord
输入的关键词
@return回来一组信息
@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{
//一切的内容必定保留在一个调集之中,由于一个调集可以直接向文件中保留
//此调集的内容最好由文件读取进来,由于文件自身中要保留目标,
//可是此程序牵扯到首次运行的状况
privateSetlt<imgsrc="titter.gif"smilieid="9"border="0"alt=""/>ersongt;allPerson;
privateFileOperatefo=null;
publicstaticStringfileName=null;
//在结构方法中为其实例化
@SuppressWarnings(unchecked)
publicPersonDAOImplFile(){
this.fo=newFileOperate(fileName);
try{
this.allPerson=(Set)fo.load();
}catch(Exceptione){
e.printStackTrace();
}
}
publicbooleandoCreate(Personperson)throwsException{
//就是刺进操作
//在原有的基础上进行增加操作
booleanflag=false;
try{
this.allPerson.add(person);
this.fo.save(this.allPerson);
flag=true;
}catch(Exceptione){
throwe;
}
returnflag;
}
publicbooleandoDelete(Stringid)throwsException{
booleanflag=false;
//假如要删去之前必须先进行搜索操作
try{
this.allPerson.remove(this.findById(id));
this.fo.save(this.allPerson);
flag=true;
}catch(Exceptione){
throwe;
}
returnflag;
}
publicbooleandoUpdate(Personperson)throwsException{
//无论怎样更新,里边的id是不能改变的
booleanflag=false;
try{
Personp=this.findById(person.getId());
if(person
abbr_ee4a125ec5654e72ed0be840842eb27c.doc

(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)

[下载]11234504312.rar




上一篇:[零基础学JAVA]Java SE应用部分-36.反射机制与工厂设计模式
下一篇:bbs+毕业设计+源代码

使用道具 举报

Archiver|手机版|小黑屋|吾爱开源 |网站地图

Copyright 2011 - 2012 Lnqq.NET.All Rights Reserved( ICP备案粤ICP备14042591号-1粤ICP14042591号 )

关于本站 - 版权申明 - 侵删联系 - Ln Studio! - 广告联系

本站资源来自互联网,仅供用户测试使用,相关版权归原作者所有

快速回复 返回顶部 返回列表