- 浏览: 1792107 次
- 性别:
- 来自: 北京
-
文章分类
- 全部博客 (641)
- vb2005xu自己动手系列 (174)
- vb2005xu开发文章转摘 (47)
- vb2005xu发发牢骚 (99)
- vb2005xu新技术灌水 (12)
- vb2005xu网络资源集锦 (21)
- vb2005xu软件学习 (60)
- 英语学习 (3)
- JavaScript 学习 (54)
- JAVA OOP 巩固 之 CustomDatabase 的开发 (5)
- 2013年9月之前所在公司 记事 (7)
- FleaPHP/QEEPHP 资料 (87)
- JAVA MAIL 学习篇 (4)
- Python turbogears (5)
- Rails 个人开发四部曲 (3)
- 名人传 (8)
- iwp framework (5)
- 高考零分作文 (5)
- startos (8)
- lua (0)
- 职场 (1)
最新评论
-
hellotieye:
自己 评论 自己 挺嗨呀
Mysql sql查询时 if 的用法 -
igevin:
转载请标明出处,转自Gevin的博客http://blog.i ...
RESTful API 编写指南 -
Theobob:
...
实现简单的ACL -
vb2005xu:
比如 对于 curl 调用就不再需要 加各种if 判断了,
$ ...
搞一个简单的数据打印工具AsDebug の Laravel -
vb2005xu:
http://geekplux.com/wiki/
YII2 模块内自定义错误页
功能基本实现完成,可以编译执行,来查看效果.
程序基本实现了 显示代码与业务逻辑相分离,并模拟了一个数据库的实现机制.
package cn.iamsese.product.custom.company; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Date; import java.util.Enumeration; import java.util.Hashtable; /** * 商家信息记录系统
* cn.iamsese.product.custom.company * Author: vb2005xu [JAVA菜鸟] */ public class Main { public Main(){ this.init(); } private SellerOPInterface sellerOP ; private void init(){ this.sellerOP = new SellerOP(); this.initSellersData(this.sellerOP) ; } private void initTellLineRecordData(Seller seller){ TellLineRecordOPInterface tellLineRecordOP = this.sellerOP.getTellLineRecordOP(seller); tellLineRecordOP.addTellLineRecord( new TellLineRecord( 1 , MessageFormat.format("{0,date,full}",new Date()) , "抬高K钱1" ,"" + "虚太高价,故意坑人" ) ) ; tellLineRecordOP.addTellLineRecord( new TellLineRecord( 2 , MessageFormat.format("{0,date,full}",new Date()) , "抬高K钱2" ,"" + "虚太高价,故意坑人" ) ) ; tellLineRecordOP.addTellLineRecord( new TellLineRecord( 3 , MessageFormat.format("{0,date,full}",new Date()) , "抬高K钱3" ,"" + "虚太高价,故意坑人" ) ) ; tellLineRecordOP.addTellLineRecord( new TellLineRecord( 4 , MessageFormat.format("{0,date,full}",new Date()) , "抬高K钱4" ,"" + "虚太高价,故意坑人" ) ) ; //System.out.println(tellLineRecordOP.findAllTellLineRecords()); } private void initSellersData(SellerOPInterface sellerOP){ sellerOP.addSeller(new Seller(0,"商家1","鼎好111") ) ; Seller seller1 = new Seller(1,"商家2","鼎好112") ; sellerOP.addSeller(seller1) ; this.initTellLineRecordData(seller1); sellerOP.addSeller(new Seller(2,"商家3","鼎好103") ) ; } private void printSellersInfo(Enumeration<Seller> sellers){ //列出所有商家信息 String formatMSG = "| ID: {0} | Name: {1} | Adderss: {2} | Level: {3} |" ; while (sellers.hasMoreElements()){ Seller seller = sellers.nextElement(); System.out.println("----------Start-------------------------------------------------------------------------"); System.out.println(MessageFormat.format(formatMSG, seller.getId(),seller.getName(),seller.getAddress(),this.sellerOP.getSellerLevel(seller) )); this.printTellRecords(seller); System.out.println("----------Stop-----------------------------------------------------------------"); } } private void printTellRecords(Seller seller){ int recordCount = this.sellerOP.getTellLineRecordOP(seller).getRecordsCount() ; System.out.println("记录: " + recordCount); int i = 0 ; String formatMSG = " ID: {0} Date: {1} Title: {2} \n 描述 {3} " ; for(TellLineRecord record : this.sellerOP.getTellLineRecordOP(seller).findAllTellLineRecords()) { System.out.println( (i++) + "-----"); System.out.println(MessageFormat.format(formatMSG,record.getId(),record.getDate(),record.getTitle(),record.getDescription())); } } private void buildWebUI(){ this.printSellersInfo(this.sellerOP.findAllSeller()); } public static void main(String[] args) { Main console = new Main(); console.buildWebUI(); } } /** * 商家所在的大楼 * cn.iamsese.product.custom.zgcpzcompany * Author: vb2005xu [JAVA菜鸟] */ class Building { public final static int HAI_LONG = 0 ; //海龙 public final static int DING_HAO = 0 ; //鼎好 public final static int E_WORLD = 0 ; //E世界 } /** * 商家 * cn.iamsese.product.custom.zgcpzcompany * Author: vb2005xu [JAVA菜鸟] */ class Seller { private int id ; //公司ID private String name ;//公司名称 private String address ;//办公地点 public Seller(int id,String name,String address) { this.id = id ; this.name = name ; this.address = address ; } //public ArrayList<TellLineRecord> records ; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } } /** * 记录 * cn.iamsese.product.custom.zgcpzcompany * Author: vb2005xu [JAVA菜鸟] */ class TellLineRecord { private int id ; //ID private String date ; //时间 private String title ; //标题 private String description ; //描述 public TellLineRecord(int id,String date,String title,String description){ this.id = id ; this.date = date ; this.title = title ; this.description = description ; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } } //逻辑层 /** * 商家 操作接口 */ interface SellerOPInterface { public Enumeration<Seller> findAllSeller(); public boolean addSeller(Seller seller) ; public Seller findSellerByName(String name); public boolean removeSellerByName(String name) ; public void removeAllSeller(); public int getSellerLevel(Seller seller) ; // 获取商家的级别 public TellLineRecordOPInterface getTellLineRecordOP(Seller seller); } /** * 记录集 操作接口 * cn.iamsese.product.custom.zgcpzcompany * Author: vb2005xu [JAVA菜鸟] */ interface TellLineRecordOPInterface { public int getRecordsCount() ; public ArrayList<TellLineRecord> findAllTellLineRecords(); public boolean addTellLineRecord(TellLineRecord tellLineRecord) ; public TellLineRecord findTellLineRecordByID(int id); public boolean removeTellLineRecordByID(int id); public void removeAllTellLineRecord(); } class SellerOP implements SellerOPInterface { public SellerOP(){} public Enumeration<Seller> findAllSeller() { return DBStore.getDBStoreInstance().getSellerRecordStore().elements(); } public Seller findSellerByName(String name) { return DBStore.getDBStoreInstance().getSellerRecordStore().get(name); } public void removeAllSeller() { DBStore.getDBStoreInstance().getSellerRecordStore().clear(); } public boolean removeSellerByName(String name) { boolean state = false ; try { DBStore.getDBStoreInstance().getSellerRecordStore().remove(name) ; state = true ; } catch (NullPointerException e) { } return state; } public boolean addSeller(Seller seller) { boolean state = false ; try { DBStore.getDBStoreInstance().getSellerRecordStore().put(seller.getName(),seller) ; //为seller的记录对象初始化操作 DBStore.getDBStoreInstance().getTellLineRecordStore().put(seller.getName() , new ArrayList<TellLineRecord>() ) ; state = true ; } catch (NullPointerException e) { } return state; } public TellLineRecordOPInterface getTellLineRecordOP(Seller seller) { return new TellLineRecordOP(seller); } public int getSellerLevel(Seller seller) { //每两次加一个级别 //System.out.println(this.getTellLineRecordOP(seller)); return this.getTellLineRecordOP(seller).getRecordsCount() / 2 + 1; } } class TellLineRecordOP implements TellLineRecordOPInterface { private Seller seller ; public TellLineRecordOP(Seller seller) { this.seller = seller; } public ArrayList<TellLineRecord> findAllTellLineRecords() { return DBStore.getDBStoreInstance().getTellLineRecordStore().get(this.seller.getName()); } public TellLineRecord findTellLineRecordByID(int id) { return DBStore.getDBStoreInstance().getTellLineRecordStore().get(this.seller.getName()).get(id); } public void removeAllTellLineRecord() { DBStore.getDBStoreInstance().getTellLineRecordStore().get(this.seller.getName()).clear(); } public boolean removeTellLineRecordByID(int id) { boolean state = false ; try { DBStore.getDBStoreInstance().getTellLineRecordStore().get(this.seller.getName()).remove(id) ; state = true ; } catch (NullPointerException e) { } return state; } public boolean addTellLineRecord(TellLineRecord tellLineRecord) { boolean state = false ; try { //首先取得TellLineRecordStore,并判断其中是否存在this.seller.getName() if (DBStore.getDBStoreInstance().getTellLineRecordStore().containsKey(this.seller.getName())){ DBStore.getDBStoreInstance().getTellLineRecordStore().get(this.seller.getName()).add(tellLineRecord) ; state = true ; } // else { // -- 这个在调用addSeller时已经初始化了 // DBStore.getDBStoreInstance().getTellLineRecordStore().put(this.seller.getName() , new ArrayList<TellLineRecord>() ) ; // } // state = true ; } catch (NullPointerException e) { //e.printStackTrace(); } return state; } public int getRecordsCount() { try { return this.findAllTellLineRecords().size(); }catch (NullPointerException e) { //如果this.findAllTellLineRecords()返回null的话 return 0 ; } } } //实体层,这里没有使用到数据库,所以缺少了Dao层的实现 /** * 模拟的记录存储器存储器 * cn.iamsese.product.custom.zgcpzcompany * Author: vb2005xu [JAVA菜鸟] */ class DBStore { private static DBStore instance = null ; /** * < sellerName,ArrayList<TellLineRecord> > */ private Hashtable<String, ArrayList<TellLineRecord>> tellLineRecordStore ; /** * <sellerName,Seller> */ private Hashtable<String, Seller> sellerRecordStore ; /* * 仅能使用单态实例对象 */ private DBStore(){ this.setSellerRecordStore(new Hashtable<String, Seller> ()); this.setTellLineRecordStore(new Hashtable<String, ArrayList<TellLineRecord>>()) ; } public static DBStore getDBStoreInstance(){ if (instance == null) instance = new DBStore(); return instance ; } public Hashtable<String, ArrayList<TellLineRecord>> getTellLineRecordStore() { return tellLineRecordStore; } public void setTellLineRecordStore( Hashtable<String, ArrayList<TellLineRecord>> tellLineRecordStore) { this.tellLineRecordStore = tellLineRecordStore; } public Hashtable<String, Seller> getSellerRecordStore() { return sellerRecordStore; } public void setSellerRecordStore(Hashtable<String, Seller> sellerRecordStore) { this.sellerRecordStore = sellerRecordStore; } }
发表评论
-
前端截取url成图片
2017-11-09 18:16 1590有些小需求需要将 url 转成图片, 直接使用 ... -
excel-to-csv-inbrowser
2016-08-15 19:20 2945# excel-to-csv-inbrowser exce ... -
ws-http 最简单轻量的PHP CURL工具库
2016-07-29 20:44 2665欢迎大家拍砖 https://github.com/to ... -
常用的 js 代码梳理
2016-06-16 12:00 1951/** * 格式化时间函数 * @param {form ... -
Facade 包装类 -- 解决视图里面长长的命名空间调用问题
2016-04-20 10:48 1805有时候模版里面定义 ... -
搞一个简单的数据打印工具AsDebug の Laravel
2016-01-20 19:47 3115很多时候我们都要纠结于代码开发过程中的数据 dump 工作 ... -
ken\trade
2015-12-18 20:45 1573<?php namespace ken\tra ... -
我承认我手贱: 升级 xcode
2015-11-14 21:11 1919升级 xcode 之后, 在终端运行 git clone 出现 ... -
YII2 模块内自定义错误页
2015-11-07 12:17 5642当前YII框架中把错误异常配置都放置在 web.php 中, ... -
PHP单例模式面试注意事项
2015-10-20 09:57 1977最近面了不少PHP从业者,有实习生也有5/6年以上的开发者 ... -
NGINX 配置 SSL 证书 搭建 HTTPS 网站
2015-10-19 19:19 2938下面是详细的配置过程: 1、在服务器上使用 Open ... -
关于php cron任务管理的实现假想
2015-10-17 21:25 1936之前每开发一个计划任务功能均需要在线上操作crontab来新 ... -
fineuploader 跨子域上传文件 cookie丢失问题的解决
2015-10-14 13:30 4842目前的项目中,使用到了fineuploader 这个纯htm ... -
CentOS 6安全加固及性能优化
2015-07-27 14:54 4335CentOS 6安全加固及性能优化 我们可以通过调整 ... -
常见票据辨别真伪的方法
2015-04-28 09:07 17821、真伪鉴别图示和步 ... -
梳理面试中遇到的HTTP协议相关的问题和知识
2015-04-16 13:45 3979本文会是一个比较长的,持续更新的过程 当你在浏览器地 ... -
面试中遇到的期权问题
2015-04-13 14:33 2771最近在面试一直遇到 ... -
遭遇windows上PHP 不能打开GBK编码文件名的问题
2015-03-09 11:21 3180我在 目录下建了一个文件名为 謀定三國-i8ujlw.js ... -
遭遇jsonp同域下变作post请求的坑
2015-01-28 21:39 4783今天迁移一个站点时遇到一个坑爹问题,同一个jsonp接口在 ... -
nginx 400 错误请求分析
2015-01-27 15:01 3374在服务器上传文件过程中 nginx经常会出现 400 的错误 ...
相关推荐
本资源“[J2SE]应用编程150例”显然是一个旨在帮助初学者掌握Java编程的实践教程集合。下面,我们将深入探讨这些实例可能涵盖的关键知识点,并提供相关扩展信息。 1. **基本语法**:包括变量声明、数据类型(如整型...
Java1.5引入了重要的新特性,如泛型和反射,但与Java1.4相比,对初学者来说差异不大,因为Java1.5兼容1.4版本的代码。 为了开始编程,你需要下载Java Development Kit(JDK)。访问官方网站...
### Java JDK6 学习要点详析 #### 一、Java 概览 - **起源与发展**:Java 最初由 Sun Microsystems 的 James Gosling 在 Green ...无论是初学者还是资深开发者,都可以在这个平台上找到适合自己的资源和发展空间。
在IT行业中,二维码(2D Barcode)是一种广泛用于存储和传递信息的方式,它在很多领域都有应用,如产品追溯、...这个项目提供了一个基础的实现,可以帮助初学者了解二维码生成的基本流程,并在此基础上进行扩展和定制。
以下是一个生成二维码的例子: ```java import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.common.BitMatrix; String content = "你好,ZXing!"; QRCodeWriter writer = new QRCodeWriter();...
创建StringItem时,需要提供两个参数:一个是字符串内容,另一个是可选的类型。类型可以决定StringItem的显示样式,例如默认、单行或多行文本。以下是一个简单的创建StringItem的例子: ```java StringItem item = ...