- 浏览: 823109 次
- 性别:
- 来自: 北京
-
文章分类
- 全部博客 (406)
- 项目 (8)
- 统计分析 (3)
- java (7)
- jquery (15)
- oracle (32)
- 面试题 (8)
- 排序算法 (3)
- 蛇形矩阵算法 (3)
- 字符串 (1)
- ICU分析插件 (1)
- html5 (1)
- Ubuntu (4)
- Linux (4)
- memcache (2)
- myeclipse (3)
- hadoop (18)
- hbase (14)
- hive (7)
- zookeeper (2)
- pig (0)
- mysql (11)
- Redis (8)
- MongoDB (7)
- Cassandra (0)
- Neo4j (0)
- springMVC (2)
- ibatis (1)
- mahout (0)
- Highcharts (1)
- maven (6)
- 生活随笔 (6)
- 存储过程 (4)
- mybatis (2)
- bootstrap (19)
- 工作中遇到的问题 (23)
- node.js (3)
- web前段 (6)
- AngularJS (5)
- GIT (2)
- nginx (4)
- hive,sqoop (1)
- 高并发 (1)
- 算法 (3)
- 工具类 (2)
- ckeditor (1)
- java代码自动生成 (3)
- ueditor (6)
- svn (4)
- easyui (3)
- 数据挖掘 (4)
- ligerUi (1)
- fullcalendar (1)
- 微信公众号开发 (1)
- tomcat (2)
- 面试 (7)
- 数据库性能优化 (2)
- R语言 (3)
- R (6)
- ylcf (39)
- CentOS (13)
- docker (28)
- Spring Boot (10)
- Nexus (1)
- thymeleaf (2)
- nodejs (2)
- swagger (1)
- Jenkins (1)
- SpringCloud (9)
- vue (1)
- springClould问题汇总 (3)
- layui (1)
最新评论
-
greatwqs:
在前置请求页面返回token, 在提交接口中验证token, ...
Spring MVC 用拦截器+token防止重复提交 -
zhukewen_java:
这种方法的缺陷在于如果请求了两个save=true的方法,后面 ...
Spring MVC 用拦截器+token防止重复提交 -
byrgl5:
请问如果重复提交了三次呢?能避免吗?
Spring MVC 用拦截器+token防止重复提交 -
381895649:
是不是有病?
服务器被如下ip攻击,如何根据ip超找攻击来源 -
greatwqs:
最棒的10款MySQL管理工具
package myio.mydata; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.RandomAccessFile; import java.io.Serializable; public class Book implements Serializable { private String id; private String name; private int count; private float price; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } //transient Thread th = new Thread(); public Book(String id, String name, int count,float price) { super(); this.id = id; this.name = name; this.count = count; this.price = price; } public Book() { // TODO Auto-generated constructor stub } @Override public String toString() { // TODO Auto-generated method stub return "编号:"+id+" 书名:"+name+" 库存"+count+"进价:"+price; } public boolean equals(Object o) { if(this==o) { return true; } else { Book b = (Book)o; return this.id==b.id&&this.name.equals(b.name)&&this.count==b.count; } } public int hashCode() { System.out.println(name); return id.hashCode(); } // private void readObject(ObjectInputStream ois) throws IOException // { // this.id = ois.readInt(); // this.name = ois.readUTF(); // this.count = ois.readInt(); // //this.price = ois.readFloat(); // } // // private void writeObject(ObjectOutputStream oos) throws IOException // { // oos.writeInt(this.id); // oos.writeUTF(this.name); // oos.writeInt(this.count); // } public void readObject(RandomAccessFile raf) throws IOException { this.id = raf.readUTF(); this.name = raf.readUTF(); this.count = raf.readInt(); this.price = raf.readFloat(); } public void writeObject(RandomAccessFile raf) throws IOException { raf.writeUTF(this.id); raf.writeUTF(this.name); raf.writeInt(this.count); raf.writeFloat(this.price); } }package myio.mydata; /** * 书籍管理系统 */ import java.util.*; /** * 系统说明 : 1.首先系统加载 2.提供系统功能服务 3.系统退出 * * @author lzt * */ public class BookStore { static Scanner read = new Scanner(System.in); static FileOp fileOp = FileOp.getInstance(); public static void main(String[] args) { // 设置文件源 fileOp.setFileName("book.txt"); // 初始化 载入所有记录到容器 以供操作 fileOp.initial(); System.out.println("系统正在初始化···"); while (true) { opration(); } } private static void addInfo() { boolean ok = false; do { ok = false; System.out.print("\n请输入书籍编号:"); String id = read.next(); if(!fileOp.checkId(id)) { System.out.print("\n请输入书籍名称:"); String name = read.next(); int count = Integer.parseInt(getString("数量")); float price = Float.parseFloat(getString("价格")); // 根据输入构建书籍对象 Book book = new Book(id, name, count, price); // 将对象写入文件 if (fileOp.addInfo(book)) { System.out.println("书籍" + name + "添加成功!"); ok = true; } else { System.out.println("书籍未能添加!"); } } else { System.out.println("此id已经存在 请重新输入"); } }while(!ok); } private static void deleleInfo() { System.out.println("请输入您要删除的书籍编号:"); String id = read.next(); if(fileOp.checkId(id)) { if (fileOp.deleteInfo(id)) { System.out.println("编号为" + id + "的书籍删除成功!"); } } else { System.out.println("此书籍不存在"); } } private static void updateInfo() { System.out.println("请输入需要修改的书籍编号:"); String id = read.next(); if(fileOp.checkId(id)) { System.out.print("\n请输入书籍名称:"); String name = read.next(); int count = Integer.parseInt(getString("数量")); float price = Float.parseFloat(getString("价格")); // 构建书籍对象 Book book = new Book(id, name, count, price); // 将对象更新到文件 if (fileOp.updateInfo(book)) { System.out.println("编号为" + id + "的书籍的信息修改成功!"); } } else { System.out.println("此书籍不存在"); } } private static void queryInfo() { System.out.println("请输入您要查找的书籍的编号:"); String id = read.next(); if (fileOp.queryInfo(id)) { System.out.println("查询成功!"); } else { System.out.println("没有这样的书籍!"); } } public static void opration() { int choice = 0; String errors = null; System.out.println("**********************************"); System.out.println("*1.查看书籍信息"); System.out.println("*2.添加书籍信息"); System.out.println("*3.删除书籍信息"); System.out.println("*4.修改书籍信息"); System.out.println("*5.查看所有信息"); System.out.println("*6.退出系统"); System.out.println("**********************************"); System.out.println("请选择您的操作:"); do { try { choice = Integer.parseInt(read.next()); errors = null; } catch (NumberFormatException e) { System.out.println("输入有误!!"); errors = "error"; System.out.println("请重新输入:"); } } while (errors != null); switch (choice) { case 1: queryInfo(); break; case 2: addInfo(); break; case 3: deleleInfo(); break; case 4: updateInfo(); break; case 5: // 查询所有 if(fileOp.queryAll()) { System.out.println("查询成功!"); } break; case 6: System.out.println("欢迎再次使用!"); System.exit(0); break; default: System.out.println("输入有误!"); System.exit(-1); } } //按格式正确获取输入内容 public static String getString(String type) { String newString = ""; boolean flag = true; do { if(flag) { System.out.print("\n请输入书籍"+type+":"); flag = false; } else { System.out.print("\n输入有误 请重新输入书籍"+type+":"); } newString = read.next(); } while (!check(type,newString)); return newString; } //格式验证 public static boolean check(String type,String s) { boolean right = false; if(type.equals("数量")) { right = s.matches("^\\d+$"); } if(type.equals("价格")) { right = s.matches("^\\d+($|\\.\\d+$)"); } return right; } }
package myio.mydata; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class FileOp { private String fileName; private FileWriter fw = null; private BufferedWriter bw = null; private FileReader fr = null; private BufferedReader br = null; private ArrayList<Book> listInfo = new ArrayList<Book>(); String[] header = { "书籍编号", "书名", "书籍数量", "书籍单价" }; private static FileOp fileOp = new FileOp(); private FileOp() { } public static FileOp getInstance() { return fileOp; } // 设置文件源 public void setFileName(String fileName) { this.fileName = fileName; } // 获取文件源 public String getFileName() { return fileName; } // 获得输入输出流 public BufferedWriter getOutPutStream() { if (checkFile()) { try { fw = new FileWriter(fileName, true); bw = new BufferedWriter(fw); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return bw; } public BufferedReader getInPutStream() { if (checkFile()) { try { fr = new FileReader(fileName); br = new BufferedReader(fr); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return br; // BufferedReader br = new BufferedReader(); } // 关闭输入输出流 public void closeInPutStream() { try { fr.close(); br.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void closeOutPutStream() { try { fw.close(); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // 初始化加载 public boolean initial() { boolean flag = true; // 首先清空集合 if (listInfo.size() != 0) { listInfo.clear(); } BufferedReader br = getInPutStream(); try { br.readLine(); String strInfo = br.readLine(); while (strInfo != null) { String[] infos = strInfo.split("\t"); Book book = new Book(); book.setId(infos[0]); book.setName(infos[1]); book.setCount(Integer.parseInt(infos[2])); book.setPrice(Float.parseFloat(infos[3])); listInfo.add(book); strInfo = br.readLine(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); flag = false; } finally { closeInPutStream(); } // while return flag; } // 增加新书籍记录 public boolean addInfo(Book book) { boolean flag = false; // 添加失败标志变量 Book Book = book; BufferedWriter bw = getOutPutStream(); // 获得输出流 try { bw.newLine(); bw.write(book.getId() + "\t" + book.getName() + "\t" + book.getCount() + "\t"+ book.getPrice()); bw.flush(); // 清空缓冲 flag = true; // 添加记录成功 // 加入集合类中 listInfo.add(Book); return flag; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { closeOutPutStream(); // 关闭流 } return flag; } // 删除书籍记录 public boolean deleteInfo(String id) { boolean flag = false; for (int i = 0; i < listInfo.size(); i++) { if (id.equals(listInfo.get(i).getId())) { listInfo.remove(i); // 从集合中移出 System.out.println(" 删除书籍"); // 更新文件 if (updateFile()) { flag = true; // 删除成功 } break; } } return flag; } // 修改指定编号的书籍信息 public boolean updateInfo(Book book) { boolean flag = false; for (int i = 0; i < listInfo.size(); i++) { if (book.getId().equals(listInfo.get(i).getId())) { listInfo.set(i, book); // 更新集合 // 更新文件 if (updateFile()) { flag = true; // 更新成功 } break; } } return flag; } // 根据id查询书籍信息 public boolean queryInfo(String id) { boolean flag = false; // 无指定书籍信息标志变量 for (int i = 0; i < listInfo.size(); i++) { if (id.equals(listInfo.get(i).getId())) { System.out.println(listInfo.get(i).getId() + "\t" + listInfo.get(i).getName() + "\t" + listInfo.get(i).getCount() + "\t" + listInfo.get(i).getPrice()); flag = true; // 查询成功 break; } } return flag; } // 查询所有书籍信息 public boolean queryAll() { boolean flag = false; // 指定书籍信息标志变量 for (int i = 0; i < listInfo.size(); i++) { // 在控制台显示 System.out.println("书籍详细信息如下:"); System.out.println(header[0] + ": " + listInfo.get(i).getId() + " " + header[1] + ": " + listInfo.get(i).getName() + "\t" + header[2] + ": " + listInfo.get(i).getCount() + "\t" + header[3] + ": " + listInfo.get(i).getPrice()); System.out.println("\n*****************"); } flag = true; return flag; } // 更新文件 private boolean updateFile() { boolean flag = false; // 重写文件-->覆盖文件 FileWriter fileWriter = null; BufferedWriter bufferedWriter = null; try { fileWriter = new FileWriter(fileName); bufferedWriter = new BufferedWriter(fileWriter); // ********************************************************************************** bufferedWriter.write(header[0] + "\t" + header[1] + "\t" + header[2] + "\t" + header[3]); bufferedWriter.newLine(); for (int j = 0; j < listInfo.size(); j++) { bufferedWriter.write(listInfo.get(j).getId() + "\t" + listInfo.get(j).getName() + "\t" + listInfo.get(j).getCount() + "\t" + listInfo.get(j).getPrice()); bufferedWriter.newLine(); } bufferedWriter.flush(); // 清空缓冲 flag = true; // 删除成功 } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { bufferedWriter.close(); fileWriter.close(); // 关闭流操作 } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return flag; } // 检查文件源是否存在 public boolean checkFile() { File file = new File(fileName); boolean flag = false; // 如果指定的文件不存在,则创建该文件 if (!file.exists()) { try { flag = file.createNewFile(); if (flag) { System.out.println(fileName + "文件创建成功!"); } fw = new FileWriter(fileName); bw = new BufferedWriter(fw); bw.write(header[0] + "\t" + header[1] + "\t" + header[2] + "\t" + header[3]); bw.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { closeOutPutStream(); } } else { flag = true; } return flag; } //检测id是否重复 public boolean checkId(String id) { for (int i = 0; i < listInfo.size(); i++) { if (id.equals(listInfo.get(i).getId())) { return true; } } return false; } }
相关推荐
图书管理系统(纯HTML)图书管理系统(纯HTML)图书管理系统(纯HTML)图书管理系统(纯HTML)图书管理系统(纯HTML)图书管理系统(纯HTML)图书管理系统(纯HTML)图书管理系统(纯HTML)图书管理系统(纯HTML)图书管理系统(纯HTML)...
图书管理系统需求分析报告 图书管理系统需求分析报告是对图书管理系统的需求进行详细的分析和描述,以确保系统的设计和开发能够满足用户的需求。下面是图书管理系统需求分析报告的详细内容: 引言 图书管理系统...
vb图书管理系统 图书管理系统 图书管理系统vb图书管理系统 图书管理系统 图书管理系统vb图书管理系统 图书管理系统 图书管理系统vb图书管理系统 图书管理系统 图书管理系统vb图书管理系统 图书管理系统 图书管理系统...
微信小程序 图书管理系统 (源码)微信小程序 图书管理系统 (源码)微信小程序 图书管理系统 (源码)微信小程序 图书管理系统 (源码)微信小程序 图书管理系统 (源码)微信小程序 图书管理系统 (源码)微信小程序 图书管理...
PHP图书管理系统源码(毕业设计),软件架构说明 PHP+MySQL+layui php版本:7.3.4 MySQL版本:5.7.26PHP图书管理系统源码(毕业设计),软件架构说明 PHP+MySQL+layui php版本:7.3.4 MySQL版本:5.7.26PHP图书管理...
图书管理系统是一种基于网络的软件应用,它主要用于存储、管理和检索图书馆内的书籍信息,方便读者查询、借阅和归还图书。在这个系统中,通常会包含多个功能模块,如用户管理、书籍管理、借阅管理、预约管理等。本...