Java面向对象课设
题目要求
使用三层架构完成信息管理系统
相关试题
科研基金信息包括:记录ID、基金名称、基金类型(横向、纵向等)、基金级别(国家级、省市局、厅局级等)、基金金额、批准时间、管理机构、主持教师名称等。
试用面向对象程序设计思想,设计科研基金管理信息系统,使之能提供以下功能:
1、基金信息录入功能
2、基金信息文件读取功能
3、基金信息文件保存功能
4、基金信息浏览功能
5、查询功能:
-
按ID查询
-
按类型查询
6、修改功能:
- 根据ID修改相应信息;
7、删除基金功能:
- 删除相应ID的基金信息。
8、排序功能(由用户指定按照基金类型或ID;指定升序或降序)
9、退出
ToDoList:
-
使用java swing 开发桌面窗口程序 (view表示层)
-
实现CRUD的业务逻辑(Service业务逻辑层)
-
实现到数据的获取与导出(Dao数据访问层)
-
实体类作为数据容器,层间传递
实现流程
完成数据的导入及导出
创建数据的实体类(Fund.java)
描述 | 实体类属性 |
---|---|
记录ID | id |
基金名称 | fundName |
基金类型 | fundType |
基金级别 | fundLevel |
基金金额 | fundAmount |
批准时间 | approvalTime |
管理机构 | managementOrganization |
主持教师名称 | hostTeacher |
创建工具类(FileUtil.java)
描述 | 工具类方法 |
---|---|
将字符串覆盖写入文件 | writeFile(String fileName, String data) |
读取文件 | ReadFile(String fileName) |
数据操控层Dao层
使用Alibaba FastJSON 完成数据操作
config.properties
配置文件导入导出路径
file=src\\Fund.json
使用配置文件配置文件的读取和保存路径
{
resource = ResourceBundle.getBundle("config");
fileName = resource.getString("file");
}
描述 | 数据操控类方法 |
---|---|
将文件中的数据导入List | setAllFund(List list) |
将程序中List导出到文件 | getAllFund() |
具体业务的实现
描述 | 业务实现方法 |
---|---|
展示所有数据 | showAll() |
列表中添加数据 | addFund() |
通过ID从列表中修改数据 | updateFundById() |
通过ID从列表中删除数据 | removeFundByid(int id) |
按ID查询列表数据 | findFundById(int id) |
按类型查询列表数据 | findFundByType(String fundType) |
按照基金类型排序(升序或降序) | sortFundById(int id) |
按照ID排序(升序或降序) | sortFundByType(String fundType) |
页面操作逻辑
使用fillTable()进行页面渲染,通过表格的点击事件监听获取选中的数据id进行数据操控,通过按钮的事件监听进行数据操作。
描述 | 业务实现方法 |
---|---|
创建提示框 | createDialog(String msg) |
获取多行数据id(用于删除) | getselectIDList() |
获取单行数据id(用于更新数据) | getselectID() |
清空输入框 | nullText() |
将选中的数据填入输入框 | fillText() |
将数据列表渲染入表格 | fillTable(List fundList) |
获取输入框全部内容(用于添加更改数据) | getAllTexts(int id) |
将文件中读取的json转为hashmap | getMap(List fundList) |
添加数据 | addFundController(ActionEvent e) |
删除数据 | removeFundController(ActionEvent e) |
修改数据 | updateFundcontroller(ActionEvent e) |
通过id搜索 | findFundListByIdController(ActionEvent e) |
文件导入数据 | fileImportListController(ActionEvent e) |
数据导出文件 | listExportFileController(ActionEvent e) |
清空 | clearTableModel(ActionEvent e) |
通过类型搜索 | findFundListByTypeController(ActionEvent e) |
展示所有 | showAllController(ActionEvent e) |
具体实现原理
entity层完成实体类编写在Dao层使用java文件读写流,读出配置文件中路径及对应文件中数据,使用FastJson实现实体类对象与json的互相转化,在service层对实体对象进行数据操作,使用List对实体对象进行存储,对list 进行增删改查等数据操作,最后在view层使用Java swing技术实现页面绘制以及响应渲染,对控件进行监听调用service层方法接口。
实现难点
1. FastJson使用
public class FundDao {
// config为属性文件名,放在src下
private ResourceBundle resource;
private String fileName;
private Fund fund;
{
resource = ResourceBundle.getBundle("config");
fileName = resource.getString("file");
}
//将实体类对象list转为json数据并写入文件
public void setAllFund(List<Fund> list) {
JSONArray jsonArray = new JSONArray();
jsonArray.addAll(list);
try {
FileUtil.writeFile(fileName, jsonArray.toString());
} catch (IOException e) {
e.printStackTrace