- 浏览: 1487801 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (525)
- SEO (16)
- JAVA-EE-Hibernate (6)
- JAVA-EE-Struts (29)
- JAVA-EE-Spring (15)
- Linux (37)
- JAVA-SE (29)
- NetWork (1)
- CMS (14)
- Semantic Research (3)
- RIA-Flex (0)
- Ajax-Extjs (4)
- Ajax-Jquery (1)
- www.godaddy.com (0)
- SSH (34)
- JavaScript (6)
- SoftwareEngineer (9)
- CMMI (0)
- IDE-Myeclipse (3)
- PHP (1)
- Algorithm (3)
- C/C++ (18)
- Concept&Items (2)
- Useful WebSite (1)
- ApacheServer (2)
- CodeReading (1)
- Socket (2)
- UML (10)
- PowerDesigner (1)
- Repository (19)
- MySQL (3)
- SqlServer (0)
- Society (1)
- Tomcat (7)
- WebService (5)
- JBoss (1)
- FCKeditor (1)
- PS/DW/CD/FW (0)
- DesignPattern (11)
- WebSite_Security (1)
- WordPress (5)
- WebConstruction (3)
- XML|XSD (7)
- Android (0)
- Project-In-Action (9)
- DatabaseDesign (3)
- taglib (7)
- DIV+CSS (10)
- Silverlight (52)
- JSON (7)
- VC++ (8)
- C# (8)
- LINQ (1)
- WCF&SOA (5)
- .NET (20)
- SOA (1)
- Mashup (2)
- RegEx (6)
- Psychology (5)
- Stock (1)
- Google (2)
- Interview (4)
- HTML5 (1)
- Marketing (4)
- Vaadin (2)
- Agile (2)
- Apache-common (6)
- ANTLR (0)
- REST (1)
- HtmlAnalysis (18)
- csv-export (3)
- Nucth (3)
- Xpath (1)
- Velocity (6)
- ASP.NET (9)
- Product (2)
- CSS (1)
最新评论
-
lt26w:
理解成门面模式应该比较容易明白吧
FacadePattern-Java代码实例讲解 -
lt26w:
看下面的例子比较明白.
FacadePattern-Java代码实例讲解 -
javaloverkehui:
这也叫文档,别逗我行吗,也就自己看看。
HtmlCleaner API -
SE_XiaoFeng:
至少也应该写个注释吧。
HtmlCleaner API -
jfzshandong:
...
org.springframework.web.filter.CharacterEncodingFilter 配置
0.2版更新内容:
1.使用文件存储数据;
2.使用HashMap查找学生信息;
3.使用DAO模式;
4.使用Factory模式;
5.使用BufferedReader、PrintWriter读写文件。
Student.java:学生类 程序代码 程序代码 package cn.edu.ahau.mgc.stu; public class Student { private String id; private String name; private int age; 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 getAge() { return age; } public void setAge(int age) { this.age = age; } } StudentAction.java:学生信息处理类 程序代码 程序代码 package cn.edu.ahau.mgc.stu; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Scanner; public class StudentAction { Scanner sc = new Scanner(System.in); public void add() { Student stu = new Student(); System.out.println("请输入学生学号:"); String id = sc.next(); System.out.println("请输入学生姓名:"); String name = sc.next(); System.out.println("请输入学生年龄:"); int age = sc.nextInt(); stu.setId(id); stu.setName(name); stu.setAge(age); try { DAOFactory.getStudentDAOInstance().add(stu); } catch (Exception e) { System.out.println("添加学生信息失败!"); } } public void showAll() { List<Student> stus = null; try { stus = DAOFactory.getStudentDAOInstance().queryAll(); } catch (Exception e) { System.out.println("信息查找失败!"); } Iterator<Student> iter = stus.iterator(); this.printHeader(); while (iter.hasNext()) { Student stu = iter.next(); this.print(stu); } this.printFooter(); } public void printHeader() { System.out.println("------------------------"); System.out.println("学号\t姓名\t年龄"); System.out.println("------------------------"); } public void printFooter() { System.out.println("------------------------"); } public void print(Student stu) { System.out.println(stu.getId() + "\t" + stu.getName() + "\t" + stu.getAge()); } public Student queryById() { System.out.println("请输入学号:"); String id = sc.next(); HashMap<String, Student> stus = null; try { stus = DAOFactory.getStudentDAOInstance().queryById(); } catch (Exception e) { System.out.println("信息查找失败!"); } Student stu = null; if (stus.containsKey(id)) { stu = stus.get(id); } if (stu != null) { this.printHeader(); this.print(stu); this.printFooter(); } else { System.out.println("对不起,没找到您要查找的学生!"); } return stu; } } DAOFactory.java:数据操作工厂类 程序代码 程序代码 package cn.edu.ahau.mgc.stu; public class DAOFactory { public static StudentDAO getStudentDAOInstance() { return new StudentDAOImpl(); } } StudentDAO.java:学生信息数据操作接口 程序代码 程序代码 package cn.edu.ahau.mgc.stu; import java.util.HashMap; import java.util.List; public interface StudentDAO { //查询所有学生信息 public List<Student> queryAll() throws Exception; //按ID查询学生信息 public HashMap<String, Student> queryById() throws Exception; //添加学生信息 public void add(Student stu) throws Exception; } StudentDAOImpl.java:学生信息数据操作实现类 程序代码 程序代码 package cn.edu.ahau.mgc.stu; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class StudentDAOImpl implements StudentDAO { public static final String FILE_PATH = "DB/student.txt"; public List<Student> queryAll() throws Exception { List<Student> stus = new ArrayList<Student>(); FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(FILE_PATH); br = new BufferedReader(fr); String stuStr = null; while ((stuStr = br.readLine()) != null) { String[] stuMsg = stuStr.split(":"); if (stuMsg.length == 3) { Student stu = new Student(); stu.setId(stuMsg[0]); stu.setName(stuMsg[1]); int age = 20; try { age = Integer.parseInt(stuMsg[2]); } catch (NumberFormatException e) { age = 20; } stu.setAge(age); stus.add(stu); } } } catch (FileNotFoundException e) { e.printStackTrace(); throw new Exception(e); } catch (IOException e) { e.printStackTrace(); throw new Exception(e); } finally { if (br != null) { try { br.close(); } catch (Exception e) { e.printStackTrace(); throw new Exception(e); } br = null; } if (fr != null) { try { fr.close(); } catch (Exception e) { e.printStackTrace(); throw new Exception(e); } fr = null; } } return stus; } public HashMap<String, Student> queryById() throws Exception { HashMap<String, Student> stus = new HashMap<String, Student>(); FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(FILE_PATH); br = new BufferedReader(fr); String stuStr = null; while ((stuStr = br.readLine()) != null) { String[] stuMsg = stuStr.split(":"); if (stuMsg.length == 3) { Student stu = new Student(); stu.setId(stuMsg[0]); stu.setName(stuMsg[1]); int age = 20; try { age = Integer.parseInt(stuMsg[2]); } catch (NumberFormatException e) { age = 20; } stu.setAge(age); stus.put(stuMsg[0], stu); } } } catch (FileNotFoundException e) { e.printStackTrace(); throw new Exception(e); } catch (IOException e) { e.printStackTrace(); throw new Exception(e); } finally { if (br != null) { try { br.close(); } catch (Exception e) { e.printStackTrace(); throw new Exception(e); } br = null; } if (fr != null) { try { fr.close(); } catch (Exception e) { e.printStackTrace(); throw new Exception(e); } fr = null; } } return stus; } public void add(Student stu) throws Exception { FileWriter fw = null; PrintWriter pw = null; try { fw = new FileWriter(FILE_PATH, true); pw = new PrintWriter(fw, true); pw.println(stu.getId() + ":" + stu.getName() + ":" + stu.getAge()); } catch (IOException e) { e.printStackTrace(); } finally { if (pw != null) { pw.close(); pw = null; } if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); throw new Exception(e); } fw = null; } } } } StudentMgr.java:学生信息管理类 程序代码 程序代码 package cn.edu.ahau.mgc.stu; import java.util.Scanner; public class StudentMgr { public static void main(String[] args) { StudentAction sa = new StudentAction(); Scanner sc = new Scanner(System.in); boolean flag = true; while (flag) { showMenu(); int selected = sc.nextInt(); switch(selected) { case 1 : sa.add(); break; case 2 : sa.showAll(); break; case 3 : sa.queryById(); break; case 4 : flag = false; System.out.println("已退出!"); break; } } } public static void showMenu() { System.out.println("学生信息管理菜单:"); System.out.println("(1)增加学生信息"); System.out.println("(2)显示所有学生信息"); System.out.println("(3)根据学号查询学生信息"); System.out.println("(4)退出管理"); } } student.txt:学生数据文件 程序代码 程序代码 1001:Magci:20 1002:MGC:20 1003:haha:24 1005:lala:19 1004:test:23
发表评论
-
关于java.util.concurrent必须知道的5件事(一)
2010-08-10 18:34 1406本文原作者:Ted Neward ... -
Java盲点:双重检查锁定及单例模式
2010-06-17 11:11 3598Peter Haggar , 高级软件工程师, IBM 20 ... -
有关可读性
2010-05-13 15:31 1243Long operatorId = ( Long.val ... -
zzJAVA中用于处理字符串的“三兄弟”
2010-04-18 15:42 1095JAVA 中用于处理 字符 ... -
Java中可以使用 break/continue label 语句来控制多重嵌套循环的跳转
2010-04-16 16:40 3610在Java中可以使用 break/conti ... -
JAVA网络编程Socket常见问题 【长连接专题】
2010-03-18 16:30 11069一. 网络程序运行过程中的常见异常及处理 ... -
利用 Eclipse Visual Editor 项目构建 GUI
2010-02-05 13:51 1389一个用于构建图形接口的图形化工具 ... -
学JAVA必须知道:抽象类与接口的区别
2010-01-26 22:08 810abstract class和interface是Java语言 ... -
利 用xml,解析yahoo天气代码(java)
2010-01-06 15:46 5102利 用xml ... -
scanner
2009-12-30 02:32 1160import java.util.Scanner; publ ... -
java从键盘输入一些字符串,并将字符串保存到一个文件中
2009-12-30 02:23 5131import java.io.*; public class ... -
文件的操作。。。行数据封装
2009-12-30 00:43 1117140100171101 太原市公安局特警支队行政处 ... -
java获取当前目录:java中获取当前类所在的目录
2009-12-30 00:19 19001在学习工作中遇到路 ... -
JAVA中MAP的用法
2009-12-29 23:54 11466Map简介 将键映射到值的对象。一个映射不能包含 ... -
演示java中Map容器的常用功能:
2009-12-29 23:53 1859mport java.util.*; ... -
Map的用途
2009-12-29 23:52 1022Map以按键/数值对的形式存储数据,和数组非常相似,在数组中存 ... -
接口VS抽象类
2009-12-06 21:19 1148<!-- <rdf:RDF xmlns: ... -
应用java与flex轻松构建cs程序
2009-12-06 13:59 2587今天发现SmartInvoke这一好东西,拿过来与大家分享分享 ... -
JAVA中的equals()和hashCode()方法
2009-12-03 14:03 1055在 Java 语言中, equa ... -
获得系统时间 转换成字符串
2009-11-28 14:27 2836关键字: java 有时候经常用到JAVA 时间转换 如 ...
相关推荐
一个学生信息管理系统,使用jsp+Servlet的MVC模式,mysql数据库
第二个上传的资源,跟上一个纯jsp+Javabean比较,多了使用Servlet作为控制器,实现MVC模式的学生信息管理系统,还是小白,请勿见笑
MVC设计模式,实现学生信息管理(增删改查)使用MYSQL、C3P0、DBUtils
Java编写的学生管理系统源码,采用MVC模式,含有用户操作界面对话框,实现增,查,修,删,排序等功能
基于MVC模式,用JSP+J2EE开发的小型学生信息管理系统。适合新手学习,含数据库文件。数据库版本为MS-SQL2008
下载者谨慎! 与mysql数据库连接,实现登陆功能。 管理员登陆成功后能查看学生信息。
JSP留言管理系统Ⅵ(MVC+DAO设计模式),分享大家共同学习!
本人培训时做的一个留言管理系统,大家可以下载来参考下.
MVC三层架构+DAO工厂模式进行JAVA WEB开发
本论文主要研究学生信息管理系统的解决方案,设计并实现了一套面向管理员的基于MVC架构下的学生信息管理系统。基本解决学生信息管理过程中一些常见的问题。此系统是针对管理员开发的,实现了用户管理、学生基本信息...
使用MVC+DAO完成用户登陆(代码+笔记)
里面是经典的MVC模式,适合初学者学习MVC。
java学生信息管理系统MVC架构
简单的JavaWeb入门小程序,使用MVC模式(DAO\Service\Servlet)实现对mysql数据库的增删查改操作
Jsp+JavaBean+Servlet(MVC设计模式)的寝室管理系统 Jsp+JavaBean+Servlet(MVC设计模式)的寝室管理系统 Jsp+JavaBean+Servlet(MVC设计模式)的寝室管理系统
基于MVC模式(Servlet+jsp)实现的学生管理系统 基于MVC模式(Servlet+jsp)实现的学生管理系统 基于MVC模式(Servlet+jsp)实现的学生管理系统 基于MVC模式(Servlet+jsp)实现的学生管理系统 基于MVC模式(Servlet+jsp)实现...
小区物业管理系统,项目是基于JavaEE采用MVC模式结合SSM框架进行实现 小区物业管理系统,项目是基于JavaEE采用MVC模式结合SSM框架进行实现 小区物业管理系统,项目是基于JavaEE采用MVC模式结合SSM框架进行实现 小区...
一个比较完善的jsp的MVC模式的小项目,课程设计的时候或一个月做的。
mvc模式mvc模式mvc模式mvc模式mvc模式mvc模式mvc模式mvc模式mvc模式