博文

阿拉伯数字转中文大写(2008-05-03 15:47:00)

摘要:import java.util.HashMap;public class TestFinal { private final static HashMap hm_upper = new HashMap();//大写 private final static HashMap hm_dw = new HashMap();//单位 private final static String str_upper[] = new String[]{  "零","壹","贰","叁","肆","伍","陆","柒","捌","玖" }; //定位到万亿,够用了 private final static String str_dw[] = new String[]{  "","拾","佰","仟","萬","拾","佰","仟","億",     "拾","佰","仟","萬" }; //初始化 static{  //大写  for(int i = 0;i < str_upper.length;i++){   hm_upper.put(i, str_upper[i]);  }  //单位  for(int i = 1;i <= str_dw.length;i++){   hm_dw.put(i,str_dw[i-1]);  } } /**  * 转换函数  * @param num  * @return  */ public String rtnConvertRMB(String num){  char str[] = num.toCharArray();  int j = str.length;  String strNum = "";  for(int i = 0;i <......

阅读全文(4247) | 评论:0

spring事务配置(2007-09-18 14:47:00)

摘要:<beans <!--spring数据源配置--> <bean id="DataSource"  class="org.apache.commons.dbcp.BasicDataSource">  <property name="driverClassName">   <value>com.mysql.jdbc.Driver</value>  </property>  <property name="url">   <value>jdbc:mysql://localhost:3306/test</value>  </property>  <property name="username">   <value>root</value>  </property>  <property name="password">   <value>mysql</value>  </property> </bean> <!--sessionFactory 配置hibernate 映射--> <bean id="sessionFactory"  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  <property name="dataSource">   <ref bean="DataSource" />  </property>  <property name="hi......

阅读全文(5440) | 评论:0

Hibernate实现对多个表进行关联查询(2006-12-28 08:58:00)

摘要:Hibernate实现对多个表进行关联查询? String sTest = "from tBookInfo book, BookSelection sel where book.id = sel.bookId"; Collection result = new ArrayList(); Transaction tx = null; try {  Session session = HibernateUtil.currentSession();  tx = session.beginTransaction();  Query query = session.createQuery(sql);  result = query.list();  tx.commit(); } catch (Exception e) {  throw e; } finally {  HibernateUtil.closeSession(); } ArrayList sList = (ArrayList) result; Iterator iterator1 = sList.iterator(); while (iterator1.hasNext()) {  Object[] o = (Object[]) iterator1.next();  tBookInfo bookInfo = (tBookInfo) o[0];  BookSelection bookSelect = (BookSelection) o[1];  System.out.println("BookInfo-Title: " + bookInfo.getTitle());  System.out.println("BookSelection-BookSelectionId: " + bookSelect.getId()); } ......

阅读全文(3114) | 评论:0

struts的体系结构(2006-12-28 08:57:00)

摘要:struts的体系结构?下面我们就从分别从视图、控制、模型和Struts的配置文件struts-config.xml来介绍struts的体系结构。   (1)视图:主要由JSP建立,Struts自身包含了一组可扩展的自定义标签库(Tag1 ib),可以简化创建用户界面的过程。   (2)模型:模型主要是表示一个系统的状态和业务逻辑。在Struts中,系统的状态主要由ActiomForm Bean体现,对于业务逻辑通常由JavaBean或EJB组件来实现。   (3)控制器:控制器主要由ActionServlet类和Action类来实现,ActionServlet类是Struts框架中的核心组件,主要负责接收HTTP请求信息。根据配置文件struts-config.xml的配置信息,把请求转发合适的Action对象。Action类负责调用模型的方法,更新模型的状态,并帮助控制应用程序的流程。   (4)配置文件struts-config.xml:当ActionServlet接收HTTP请求信息时,如何决定把用户请求转发给哪个Action对象呢?这就需要一些描述用户请求路径和Action映射关系的配置信息。在Struts中.这些配置映射信息都存储在特定的XML 文件Struts—config.xml中,在该配置文件中,每一个Action的映射信息都通过一个(action)元素来配置。这些配置信息在系统启动时会被读入内存,供Struts在运行期间使用,在内存中,每一个(action)元素都对应一个ActionMapping类的实例。......

阅读全文(2992) | 评论:1

统计java源代码的物理行,逻辑行,注释行(2006-12-26 17:40:00)

摘要://不是纯注释行的算作逻辑行 package com.regex;import java.io.*;import java.net.URLDecoder;import java.util.regex.*;public class Regex { private int REMARK=0; private int LOGIC=0; private int PHYSIC=0; boolean start=false;   /**  * @param args  */ public static void main(String[] args) { //测试方法  // TODO Auto-generated method stub  Regex re=new Regex();  re.regCount("Regex.java");  System.out.println("remark Line: "+re.REMARK);  System.out.println("logic Line: "+re.LOGIC);  System.out.println("physic Line: "+re.PHYSIC);  }/**   * @author BlueDance  * @param s  * @deprecated count  */ public void regCount(String s){  String url=null;  try {   url=URLDecoder.decode(this.getClass().getResource(s).getPath(),"UTF-8");  } catch (Exception e) {   e.printStackTrace();   // TODO: handle exception&nbs......

阅读全文(4145) | 评论:0

XML的JDOM解析(2006-12-22 15:49:00)

摘要:import java.io.*;import java.net.URLDecoder;import java.util.*;import org.jdom.*;import org.jdom.input.*;public class XMLJDOM { public static void main(String[] args) {  long startTime=System.currentTimeMillis();  new XMLJDOM().domParse();    System.out.println("所用时间:"+(System.currentTimeMillis()-startTime)); } public void domParse(){  String url=this.getClass().getResource("XML.xml").getPath();//获得绝对路径  String ss=null;  try{   ss=URLDecoder.decode(url, "UTF-8");                      //路径转码  }catch(Exception ex){   ex.printStackTrace();  }  File file=new File(ss);                              ......

阅读全文(2427) | 评论:0

XML的DOM4J解析(2006-12-22 15:46:00)

摘要:package test;import java.io.*;import java.net.URL;import java.net.URLDecoder; import java.net.URLDecoder;import java.util.*;import org.dom4j.*;import org.dom4j.io.*;public class XMLDom4J {  public static void main(String[] args) {  XMLDom4J xm=new XMLDom4J();  long startTime=System.currentTimeMillis();  xm.DOMParse();  System.out.println("处理时间:"+(System.currentTimeMillis()-startTime)); } public void DOMParse(){    String url=this.getClass().getResource("XML.xml").getPath(); //获得xml的绝对路径  String ss=null;  try{   ss=URLDecoder.decode(url, "utf-8");                     //对路径转码  }catch(Exception ex){   ex.printStackTrace();  }  File file=new File(ss);              ......

阅读全文(2528) | 评论:0

XML的DOM解析(2006-12-22 15:41:00)

摘要:package test;import java.io.*; import java.util.*; import org.w3c.dom.*; import javax.xml.parsers.*; public class XML{ public static void main(String [] args){  File file=new File("XML.xml");       long startTime=System.currentTimeMillis();        System.out.println("DOM解释开始:=========");     domParse(file);     System.out.println("所花时间为"+(System.currentTimeMillis()-startTime));        }    public static void domParse(File file){     DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();//创建DOM解析工厂     try{         DocumentBuilder builder=factory.newDocumentBuilder();      Document doc=builder.parse(file);                 &......

阅读全文(2485) | 评论:0

统计一个字符串在另一个字符串中出现次数(java)(2006-12-22 15:16:00)

摘要://这是一个用java语言编写的统计字符串出现次数的代码/* *统计字符串出现的次数 */public class TwoTest{ public static void main(String [] args){      String s="lsdd";  String y="iloveyouwhyyoulovemelove";   System.out.println(new TwoTest().countNumber(s,y)); } public int countNumber(String s,String y){    //统计方法  int count=0;  String [] k=y.split(s);                      //将字符串通过s断开返回数组k  if(y.lastIndexOf(s)==(y.length()-s.length())) //如果y最后一个包含s的索引等于y的长度-要的长度,那么出现的次数就等于k的长度   count=k.length;  else   count=k.length-1;//否则k长度-1,因为s不是单字符是多个  if(count==0)   System.out.println ("字符串\""+s+"\"在字符串\""+y+"\"没有出现过");  else   return count;  return -1;  }}......

阅读全文(10962) | 评论:6