- 浏览: 50126 次
- 性别:
- 来自: 沈阳
文章分类
最新评论
-
tan_meijun:
试了下 ,效果还不错
java输入汉字转为拼音 -
闫昌盛:
配置环境变量的
配置Tomcat环境变量 -
xcxinghai:
这是什么啊?
配置Tomcat环境变量
收藏列表
- 全部 [8]
- 默认 [3]
- oracle [1]
- spring源代码解析(四):spring mvc [1]
- update [1]
- 读取某个文件夹下的所有文件 [1]
- java 集合 collection list set map 区别 [1]
- java unzip [1]
标题 | 标签 | 来源 | |
jquery form | jquery form 插件的使用 | ||
function tt (){ alert("start"); var options ={ //target:'#project_needs', url:'projectNeedsAddProjectNeedsAction.action', //提交地址 type:'POST', //方式 dataType: 'html', //服务器返回的数据形式 success: function('html') { //回传函数实体,参数为XMLhttpRequest.responseText alert('success!!form'); $("#project_needs").html('html') ; } }; $('#projectNeedsAddForm').ajaxSubmit(options); //options return false; alert("end"); } |
|||
oracle update语句 | oracle, update | ||
为了方便起见,建立了以下简单模型,和构造了部分测试数据: 在某个业务受理子系统BSS中, SQL 代码 --客户资料表 create table customers ( customer_id number(8) not null, -- 客户标示 city_name varchar2(10) not null, -- 所在城市 customer_type char(2) not null, -- 客户类型 ... ) create unique index PK_customers on customers (customer_id) 由于某些原因,客户所在城市这个信息并不什么准确,但是在 客户服务部的CRM子系统中,通过主动服务获取了部分客户20%的所在 城市等准确信息,于是你将该部分信息提取至一张临时表中: SQL 代码 create table tmp_cust_city ( customer_id number(8) not null, citye_name varchar2(10) not null, customer_type char(2) not null ) 1) 最简单的形式 SQL 代码 --经确认customers表中所有customer_id小于1000均为'北京' --1000以内的均是公司走向全国之前的本城市的老客户:) update customers set city_name='北京' where customer_id<1000 2) 两表(多表)关联update -- 仅在where字句中的连接 SQL 代码 --这次提取的数据都是VIP,且包括新增的,所以顺便更新客户类别 update customers a -- 使用别名 set customer_type='01' --01 为vip,00为普通 where exists (select 1 from tmp_cust_city b where b.customer_id=a.customer_id ) 3) 两表(多表)关联update -- 被修改值由另一个表运算而来 SQL 代码 update customers a -- 使用别名 set city_name=(select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id) where exists (select 1 from tmp_cust_city b where b.customer_id=a.customer_id ) -- update 超过2个值 update customers a -- 使用别名 set (city_name,customer_type)=(select b.city_name,b.customer_type from tmp_cust_city b where b.customer_id=a.customer_id) where exists (select 1 from tmp_cust_city b where b.customer_id=a.customer_id ) 注意在这个语句中, =(select b.city_name,b.customer_type from tmp_cust_city b where b.customer_id=a.customer_id ) 与 (select 1 from tmp_cust_city b where b.customer_id=a.customer_id) 是两个独立的子查询,查看执行计划可知,对b表/索引扫描了2篇; 如果舍弃where条件,则默认对A表进行全表 更新,但由于 SQL 代码 select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id 有可能不能提供"足够多"值,因为tmp_cust_city只是一部分客户的信息,所以报错(如果指定的列--city_name可以为NULL则另当别论): SQL 代码 01407, 00000, "cannot update (%s) to NULL" // *Cause: // *Action: 一个替代的方法可以采用: SQL 代码 update customers a -- 使用别名 set city_name=nvl((select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id),a.city_name) 或者 SQL 代码 set city_name=nvl((select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id),'未知') -- 当然这不符合业务逻辑了 4) 上述3)在一些情况下,因为B表的纪录只有A表的20-30%的纪录数, 考虑A表使用INDEX的情况,使用cursor也许会比关联update带来更好的性能: SQL 代码 set serveroutput on declare cursor city_cur is select customer_id,city_name from tmp_cust_city order by customer_id; begin for my_cur in city_cur loop update customers set city_name=my_cur.city_name where customer_id=my_cur.customer_id; /** 此处也可以单条/分批次提交,避免锁表情况 **/ -- if mod(city_cur%rowcount,10000)=0 then -- dbms_output.put_line('----'); -- commit; -- end if; end loop; end; 5) 关联update的一个特例以及性能再探讨 在oracle的update语句语法中,除了可以update表之外,也可以是视图,所以有以下1个特例: SQL 代码 update (select a.city_name,b.city_name as new_name from customers a, tmp_cust_city b where b.customer_id=a.customer_id ) set city_name=new_name 这样能避免对B表或其索引的2次扫描,但前提是 A(customer_id) b(customer_id)必需是unique index或primary key。否则报错: SQL 代码 01779, 00000, "cannot modify a column which maps to a non key-preserved table" // *Cause: An attempt was made to insert or update columns of a join view which // map to a non-key-preserved table. // *Action: Modify the underlying base tables directly. 6)oracle另一个常见错误 回到3)情况,由于某些原因,tmp_cust_city customer_id 不是唯一index/primary key SQL 代码 update customers a -- 使用别名 set city_name=(select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id) where exists (select 1 from tmp_cust_city b where b.customer_id=a.customer_id ) 当对于一个给定的a.customer_id (select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id) 返回多余1条的情况,则会报如下错误: SQL 代码 01427, 00000, "single-row subquery returns more than one row" // *Cause: // *Action: 一个比较简单近似于不负责任的做法是 SQL 代码 update customers a -- 使用别名 set city_name=(select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id and rownum=1) 如何理解 01427 错误,在一个很复杂的多表连接update的语句,经常因考虑不周,出现这个错误, 仍已上述例子来描述,一个比较简便的方法就是将A表代入 值表达式 中,使用group by 和 having 字句查看重复的纪录 SQL 代码 (select b.customer_id,b.city_name,count(*) from tmp_cust_city b,customers a where b.customer_id=a.customer_id group by b.customer_id,b.city_name having count(*)>=2 ) |
|||
java unzip | java unzip | Java解压缩zip文件 | |
import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import org.apache.tools.zip.ZipEntry; import org.apache.tools.zip.ZipFile; /** * 可以处理中文文件名 */ public class UnZip2 { private static final int buffer = 2048; public static void main(String[] args) { unZip("D:\\ss\\test.zip"); } public static void unZip(String path) { int count = -1; int index = -1; String savepath = ""; boolean flag = false; File file = null; InputStream is = null; FileOutputStream fos = null; BufferedOutputStream bos = null; savepath = path.substring(0, path.lastIndexOf("\\")) + "\\"; try { ZipFile zipFile = new ZipFile(path); Enumeration<?> entries = zipFile.getEntries(); while(entries.hasMoreElements()) { byte buf[] = new byte[buffer]; ZipEntry entry = (ZipEntry)entries.nextElement(); String filename = entry.getName(); index = filename.lastIndexOf("/"); if(index > -1) filename = filename.substring(index+1); filename = savepath + filename; flag = isPics(filename); if(!flag) continue; file = new File(filename); file.createNewFile(); is = zipFile.getInputStream(entry); fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos, buffer); while((count = is.read(buf)) > -1) { bos.write(buf, 0, count ); } fos.close(); is.close(); } zipFile.close(); }catch(IOException ioe){ ioe.printStackTrace(); } } public static boolean isPics(String filename) { boolean flag = false; if(filename.endsWith(".jpg") || filename.endsWith(".gif") || filename.endsWith(".bmp") || filename.endsWith(".png")) flag = true; return flag; } } |
|||
js语音 | Microsoft Speech SDK例子(js) | ||
<html> <head><title>语音测试例子</title></head> <body> 音量: <input id="vol"></input>语速<input id="rat"></input> <p> 朗读人: <select id="speaker"> </select> 输出设备: <select id="outputer"> </select> <p> <textarea id="text" rows="3" cols="80"> 我们的教育真是问题成堆,很多情况下不是在培育英才而是在糟蹋人才。不上学大不了是个不识字的文盲,进校门后就可能成为弄虚作假的高手;不上大学可能还对学术有一份敬重,进大学后才知道学术是“什么玩艺儿”。一个人从幼儿园和小学开始,学校就逼着他如何搞形式,如何说假话,如何拉关系。只要在中国从幼儿园读到大学毕业,任何一个天真纯洁的孩子,都可能培养成为一个圆滑世故的老油条;任何一个真诚的儿童,都可能成为一个伪君子。 </textarea> <p> <button onClick="speak()">朗读</button><button onClick="stop()">停止</button> <p> <p id="test"></p> <script > var sap; //初始化TTS function init() { if(navigator.appName!="Microsoft Internet Explorer") { alert("请切换到IE内核"); return false; } try { sap= new ActiveXObject("Sapi.SpVoice"); } catch(ex) { alert("初始化失败!"+ex); return false; } if(sap==null) { alert("初始化失败!没有Sapi.SpVoice控件"); return false; } // return true; } //初始化设置参数 function setting() { vol.value=sap.Volume; rat.value=sap.Rate; var VoicesToken = sap.GetVoices(); var AudioOutputsToken = sap.GetAudioOutputs(); //朗读引擎 for( var i=0; i <VoicesToken.Count; i++ ) { var oOption = document.createElement("OPTION"); speaker.options.add(oOption); oOption.innerText = VoicesToken.Item(i).GetDescription(); oOption.value = i; } //输出设备 for( var i=0; i <AudioOutputsToken.Count; i++ ) { var oOption = document.createElement("OPTION"); outputer.options.add(oOption); oOption.innerText = AudioOutputsToken.Item(i).GetDescription(); oOption.value = i; } } //获取设置参数 function change() { try { sap.Volume=parseInt(vol.value); sap.Rate=parseInt(rat.value); sap.Voice = sap.GetVoices().Item(parseInt(speaker.value)); sap.AudioOutput = sap.GetAudioOutputs().Item(parseInt(speaker.value)); } catch(err) { alert("设置出错!"+err); } } if(init()) { setting(); } function speak() { change(); try { sap.speak(text.innerText,1); } catch(err) { alert("朗读出错"); } } function stop() { sap.speak("",2); } //语音朗读状态 function getStatus() { st=sap.Status; msg="Status:" +",\n CurrentStreamNumber:"+st.CurrentStreamNumber +",\n InputSentenceLength:"+st.InputSentenceLength +",\n InputSentencePosition:"+st.InputSentencePosition +",\n InputWordLength:"+st.InputWordLength +",\n InputWordPosition:"+st.InputWordPosition +",\n InputWord:"+text.innerText.substring(st.InputWordPosition,st.InputWordPosition+st.InputWordLength ) +",\n LastBookmark :"+st.LastBookmark +",\n LastBookmarkId :"+st.LastBookmarkId +",\n LastHResult :"+st.LastHResult +",\n LastStreamNumberQueued :"+st.LastStreamNumberQueued +",\n PhonemeId :"+st.PhonemeId +",\n RunningState :"+st.RunningState +",\n VisemeId :"+st.PhonemeId ; test.innerText=msg; } //getStatus(); setInterval("getStatus()",100); </script> </body> </html> |
|||
Java 集合 Collection List Set Map 区别 | java 集合 collection list set map 区别 | Java 集合 Collection List Set Map 区别 | |
package com.suypower.chengyu.collection; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.Map; import java.util.Set; public class CollectionTest { /** * @author chengYu * @return collection * Collections是针对集合类的一个帮助类。提供了一系列静态方法实现对各种集合的搜索、排序、线程完全化等操作。 * 相当于对Array进行类似操作的类——Arrays。 */ /* * 集合机构图 * Collection ├List │├LinkedList │├ArrayList │└Vector │ └Stack └Set HashSet , TreeSet , LinkedHashSet Map ├Hashtable ├HashMap └WeakHashMap */ /* * ArrayList * 随即访问速度快 * 非同步 List list = Collections.synchronizedList(new ArrayList(...)); * *****************************集合差操作 List a = Arrays.asList(lista.toArray()); List b = Arrays.asList(listb.toArray()); Collection subtract = CollectionUtils.subtract(a,b); */ public ArrayList toArrayList(ArrayList<String> arrayList) { System.out.println(); System.out.println("------------------ArrayList----------------------------------"); arrayList.add(null); //允许包括 null 在内的所有元素 arrayList.add(2,"A"); //将指定的元素插入此列表中的指定位置 System.out.println ("arrayList.contains(\"A\")="+(arrayList.contains("A")==true?"真":"假").toString()); // arrayList.clear(); 清空集合 System.out.println("arrayList.get(2)="+arrayList.get(2)); System.out.println("返回A的小标 :"+arrayList.indexOf("A")); if(arrayList.indexOf("A") != -1) { System.out.println("arrayList.indexOf(\"A\") != -1"+" 此集合里面找到A"); } System.out.println("测试此列表中是否没有元素:"+arrayList.isEmpty()); arrayList.remove("a"); // 从此列表中移除指定元素 arrayList.remove(1); // 移除此列表中指定位置上的元素(移除第二个元素) // 遍历元素 iterator Iterator<String> iterator = arrayList.iterator(); while(iterator.hasNext()) { System.out.print(iterator.next()); } System.out.println(); for(String str:arrayList)System.out.print(str);//打印集合 System.out.println(); System.out.println("-----------------------LinkedList-----------------------------"); return arrayList; } /* * LinkedList 用法 * 快速插入和删除 */ public LinkedList toLinkedList (LinkedList<String> linkedList) { linkedList.add("h"); linkedList.add(null); //允许包括 null 在内的所有元素 linkedList.addFirst("-addFirst-"); // linkedList.clear(); 清除 linkedlist System.out.println("linkedList.contains(\"d\")="+linkedList.contains("d")); System.out.println("获取第一个元素:"+linkedList.element()); System.out.println("获取第一个元素:"+linkedList.peek()); //找到不移除此列表的头 System.out.println("获取第一个元素:"+linkedList.poll());//找到并移除此列表的头 System.out.println("获取指定下标元素:"+linkedList.get(1)); System.out.println("获取元素的下标="+linkedList.indexOf("a")); System.out.println("测试此列表中是否没有元素;"+linkedList.isEmpty()); linkedList.remove();//找到并移除此列表的头(第一个元素) linkedList.remove(2); //移除指定下标元素 // linkedList.removeAll(linkedList); 移除所有集合内元素 //打印 linkedList 集合 for(String str:linkedList) { System.out.print(str); } System.out.println(); System.out.println("-----------------------set-----------------------------"); return linkedList; } /* * Set是一种不包含重复的元素的Collection,即任意的两个元素e1和e2都有e1.equals(e2)=false,Set最多有一个null元素。 * Set HashSet , TreeSet , LinkedHashSet(外部按成员的插入顺序遍历成员) * ArrayList arrayList = new ArrayList(set); */ public Set<String> toSet(Set<String> set) { /* * HashSet */ HashSet<String> hashSet = new HashSet<String>(); hashSet.add("hashSet"); hashSet.add("H"); hashSet.add("H"); System.out.println("isEmpty="+hashSet.isEmpty()); System.out.println("size="+hashSet.size()); System.out.println("contains:"+hashSet.contains("hashSet")); // hashSet.removeAll(hashSet); /* * 遍历集合 hashSet */ Iterator it = hashSet.iterator(); while(it.hasNext()) { System.out.print(it.next().toString()); } System.out.println("\n"+"----------------------"); for(String str:hashSet) { System.out.println(str); } /* * LinkedHashSet */ LinkedHashSet<String> lhs = new LinkedHashSet<String>(); lhs.add("1"); lhs.add("3"); lhs.add("8"); lhs.add("1"); lhs.add("3"); lhs.add("3"); for(String str:lhs) { System.out.println(str); } return set; } /* * 请注意,Map没有继承Collection接口 * Map提供key到value的映射 * 一个Map中不能包含相同的key 每个key只能映射一个 value Map接口提供3种集合的视图 Map的内容可以被当作一组key集合,一组value集合,或者一组key-value映射。 */ public Map<String,String> toMap(Map<String,String> map) { /* * hashMap * HashMap是非同步的,并且允许null,即null value和null key。 */ System.out.println("\n"+"------------map------------"); Map<String , String > hashMap = new HashMap<String, String>(); hashMap.put("a","valueA"); hashMap.put("b","valueB"); hashMap.put("c","valueC"); System.out.println("hashMap.containsKey(\"a\")="+hashMap.containsKey("a")); System.out.println("hashMap.containsValue(\"valueA\")="+hashMap.containsValue("valueA")); System.out.println("hashMap.get(\"b\")="+hashMap.get("b")); // 遍历 hashMap Iterator it = hashMap.entrySet().iterator(); while(it.hasNext()) { System.out.println(it.next()); } /* * HashTable 同步 * 这里就不举例啦 */ return map; } public static void main(String[] args) { CollectionTest collectionTest = new CollectionTest(); /* * 声明公用数据 */ String[] array = new String[]{"a","b","c","d","e","f","g"}; // 数组转换成集合 (集合转换数组 toArray() ) collectionTest.toArrayList(new ArrayList<String>(Arrays.asList(array))); collectionTest.toLinkedList(new LinkedList<String>(Arrays.asList(array))); collectionTest.toSet(new HashSet<String>(Arrays.asList(array))); // -list => set collectionTest.toMap(new HashMap<String,String>()); } /* * <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page> <error-page> <exception-type>java.lang.NullPointerException</exception-type> <location>/error.jsp</location> </error-page> */ } |
|||
读取某个文件夹下的所有文件 | 读取某个文件夹下的所有文件 | file IO 读取文件夹 | |
package com.suypower.djbxt.czxs.bean; /* import java.io.File; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.TreeSet; public class FileTest { public static void main(String[] args) { File directory = new File("e:\\tomcat5.5\\"); List fileList = listAllFiles(directory); Set fileNameSet = new HashSet(fileList.size()); for (int i = 0 ; i< fileList.size() ; i++) { File file = (File)fileList.get(i); fileNameSet.add(file.getAbsolutePath()); } for (Iterator i = new TreeSet(fileNameSet).iterator() ; i.hasNext() ; ) { System.out.println(i.next()); } } private static List listAllFiles(File directory) { if (directory == null || !directory.isDirectory()) { return null; } List fileList = new ArrayList(); addSubFileList(directory,fileList); return fileList; } private static void addSubFileList( File file, List fileList ){ File[] subFileArray = file.listFiles(); if (subFileArray == null || subFileArray.length == 0 ){ return; } for (int i = 0 ; i < subFileArray.length ; i++) { File subFile = subFileArray[i]; if (subFile == null ){ continue; } if (subFile.isFile() ){ fileList.add(subFile); continue; } else if (subFile.isDirectory() ){ addSubFileList(subFile, fileList); } } } } */ import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; public class Directory { private List file = new ArrayList(); private File f; public Directory() { } public List getAllFile(String dir_name) { File[] files = null; try { f = new File(dir_name); files = f.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { file.add(files[i].getName()); } else { getAllFile(files[i].getAbsolutePath()); } } } catch (Exception e) { System.out.println("目录路径不正确。"); } Collections.sort(file, new Com()); return file; } public static void main(String[] args) { List l = new Directory().getAllFile("e:\\db2"); Iterator it = l.iterator(); while (it.hasNext()) { System.out.println(it.next()); } } } // 比较器 class Com implements Comparator { public int compare(Object o1, Object o2) { String s = (String) o1; String s1 = (String) o2; return s.compareTo(s1); } } |
|||
jspTo html | jsp页面转换为html静态页面 | ||
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.text.SimpleDateFormat; import java.util.Date; /** * * @功能描述 将jsp页面转换为HTML文件 * @author Mac.Lee * @date Aug 31, 2011 * @time 8:06:02 PM */ public class CallForHtml { /* * 获得jsp页面内容 */ public static String getHtmlCode(String jsp){ String htmlCode=""; InputStream in=null; System.out.println(jsp); try { URL url=new URL(jsp); URLConnection connection=url.openConnection(); connection.connect(); in=connection.getInputStream(); BufferedReader reader=new BufferedReader(new InputStreamReader(in,"utf-8")); String currentLine; while((currentLine=reader.readLine())!=null){ htmlCode+=currentLine; } reader.close(); in.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return htmlCode; } /** * * @ Function 写入html文件 * @param htmlCode html文件内容 * @param path html文件的路径 * @param fileName 文件名 */ public static synchronized void writeHtml(String htmlCode,String path,String fileName){ PrintWriter pw=null; if(fileName==""){ /*若生成新闻内容 *則以当前时间为文件名 * */ Date date=new Date(); SimpleDateFormat time=new SimpleDateFormat("yyyyMMddHHmmss"); fileName=time.format(date)+".html"; } File file=new File(path,fileName); try { if(file.exists()){ file.delete(); }else{ file.createNewFile(); } pw=new PrintWriter(new FileOutputStream(path+"\\"+fileName,true)); pw.println(htmlCode); pw.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("文件转换成功"); } } |
|||
Spring源代码解析(四):Spring MVC | spring源代码解析(四):spring mvc | Spring源代码解析(四):Spring MVC | |
protected Object getHandlerInternal(HttpServletRequest request) throws Exception { //这里的HTTP Request传进来的参数进行分析,得到具体的路径信息。 String lookupPath = this.urlPathHelper.getLookupPathForRequest(request); .......//下面是根据请求信息的查找 return lookupHandler(lookupPath, request); } protected Object lookupHandler(String urlPath, HttpServletRequest request) { // 如果能够直接能在SimpleUrlHandlerMapping的映射表中找到,那最好。 Object handler = this.handlerMap.get(urlPath); if (handler == null) { // 这里使用模式来对map中的所有handler进行匹配,调用了Jre中的Matcher类来完成匹配处理。 String bestPathMatch = null; for (Iterator it = this.handlerMap.keySet().iterator(); it.hasNext();) { String registeredPath = (String) it.next(); if (this.pathMatcher.match(registeredPath, urlPath) && (bestPathMatch == null || bestPathMatch.length() <= registeredPath.length())) { //这里根据匹配路径找到最象的一个 handler = this.handlerMap.get(registeredPath); bestPathMatch = registeredPath; } } if (handler != null) { exposePathWithinMapping(this.pathMatcher.extractPathWithinPattern(bestPathMatch, urlPath), request); } } else { exposePathWithinMapping(urlPath, request); } // return handler; } |