ï»??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲老司机网,中文字幕高清在线,亚洲免费综合http://www.aygfsteel.com/rory/category/9611.htmlHappy study,Happy work,Happy lifezh-cnTue, 27 Feb 2007 12:36:04 GMTTue, 27 Feb 2007 12:36:04 GMT60SpringXmlrpcServiceExporter for xmlrpc3.xhttp://www.aygfsteel.com/rory/archive/2006/10/22/spring_xmlrpc3_service_exporter.html莫多莫多Sun, 22 Oct 2006 08:12:00 GMThttp://www.aygfsteel.com/rory/archive/2006/10/22/spring_xmlrpc3_service_exporter.htmlhttp://www.aygfsteel.com/rory/comments/76628.htmlhttp://www.aygfsteel.com/rory/archive/2006/10/22/spring_xmlrpc3_service_exporter.html#Feedback0http://www.aygfsteel.com/rory/comments/commentRss/76628.htmlhttp://www.aygfsteel.com/rory/services/trackbacks/76628.html      我们的项目用åˆîCº†xmlrpc,ä¸è¿‡˜q˜æ˜¯ç”¨çš„2.x版本的。由于xmlrpc3.x地推出。æä¾›äº†NULL,Serializable½{‰çš„æ”¯æŒåQŒå°†åŽŸæ¥çš„Hashtableæ”ÒŽˆäº†Map,Vectoræ”ÒŽˆäº†List。都是ä¸é”™çš„˜q›æ­¥ã€‚所以我们决定从xmlrpc2.xå‡çñ”到xmlrpc3.x.
      在springé‡Œé¢æœ‰å‡ ä¸ªServiceExporteråQŒorg.springframework.remoting.rmi.RmiServiceExporterã€org.springframework.remoting.caucho.HessianServiceExporterã€org.springframework.remoting.caucho.BurlapServiceExporter。丘q‡æ²¡æœ‰xmlrpcçš„serviceExporteråQŒåŽŸæ¥æˆ‘们是自己ž®è£…çš„XmlRpcServer,用servletæä¾›æœåŠ¡ã€?eg:http://localhost:8080/community/service/xmlrpc)没有和spring集æˆè™½ç„¶ç”¨äº†springã€?br />    考虑到spring的便利以åŠé…¾|®çš„åŒæ„我决定将xmlrpcService攑օ¥spring中。xmlrpc3.xå’Œxmlrpc2.x的代ç åŸºæœ¬ä¸Šæ²¡æœ‰ä¸€æ ïLš„。改了很多东è¥Ñ€‚除了类型å˜åŒ–之外,˜q˜æ·»åŠ äº†å¯¹å¼‚å¸¸çš„æ”¯æŒã€‚详¾l†ä¿¡æ¯è¯·å‚ç…§xmlrpc3.xæºä»£ç ã€?br />XmlRpcServiceExporter.java

package  com.jdkcn.xmlrpc;

import  javax.servlet.ServletException;

/**
 * 
@author  <a href="mailto:rory.cn@gmail.com">somebody</a>
 * 
@since  2006-9-27 03:59:22 pm
 * 
@version  $Id XmlRpcServiceExporter.java$
 
*/
public   class  XmlRpcServiceExporter  extends  RemoteExporter  implements
        Controller, InitializingBean {
    
    
private  XmlRpcServletServer server;
    
    
public  String serviceName;
    
    
public  Resource configFile;
    
    
public  Boolean enabledForExtensions;
    
    
public   void  setEnabledForExtensions(Boolean enabledForExtensions) {
        
this .enabledForExtensions  =  enabledForExtensions;
    }

    
public   void  setConfigFile(Resource configFile) {
        
this .configFile  =  configFile;
    }

    
public  String getServiceName() {
        
return  serviceName;
    }

    
public   void  setServiceName(String serviceName) {
        
this .serviceName  =  serviceName;
    }

    
public  XmlRpcServletServer getXmlRpcServletServer() {
        
return  server;
    }
    
    
/*  (non-Javadoc)
     * @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     
*/
    
public  ModelAndView handleRequest(HttpServletRequest request,
            HttpServletResponse response) 
throws  Exception {
        
if  ( ! WebContentGenerator.METHOD_POST.equals(request.getMethod())) {
            
throw   new  ServletException( " XmlRpcServiceExporter only supports POST requests " );
        }
        server.execute(request, response);
        
return   null ;
    }

    
/*  (non-Javadoc)
     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
     
*/
    
public   void  afterPropertiesSet()  throws  Exception {
        server 
=   new  XmlRpcServletServer();
        server.setHandlerMapping(newXmlRpcHandlerMapping());
        
if  (enabledForExtensions != null ) {
            ((XmlRpcServerConfigImpl) server.getConfig()).setEnabledForExtensions(enabledForExtensions.booleanValue());
        }
        
    }

    
/**  Creates a new handler mapping. The default implementation loads
     * a property file from the resource
     * 
     
*/
    
protected  XmlRpcHandlerMapping newXmlRpcHandlerMapping()  throws  XmlRpcException {
        
        SpringHandlerMapping mapping 
=   new  SpringHandlerMapping(getServiceInterface());
        mapping.addHandler(getServiceName(), getServiceInterface());
        mapping.setTagetObject(getProxyForService());
        
return  mapping;
    }
    
}

springé…置文äšg
    <bean id="accountService"  class="com.jdkcn.service.impl.AccountServiceImpl">
    
</bean>
        
<bean name="rpcAccountService" class="com.jdkcn.xmlrpc.XmlRpcServiceExporter">
        
<property name="service">
            
<ref bean="accountService"/>
        
</property>
        
<property name="serviceName">
            
<value>jdkcn.accountService</value>
        
</property>
        
<property name="enabledForExtensions">
            
<value>true</value>
        
</property>
        
<property name="serviceInterface">
            
<value>com.jdkcn.service.AccountService</value>
        
</property>
    
</bean>
ç„¶åŽæ˜ å°„一个地倞®±å¯ä»¥é€šè¿‡xmlrpc讉K—®æœåŠ¡äº?br />
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        
<property name="mappings">
            
<props> 
                
<prop key="/account">rpcAccountService</prop>
            
</props>
        
</property>
    
</bean>
web.xml
    <context-param>
        
<param-name>contextConfigLocation</param-name>
        
<param-value>
            classpath:spring/global.xml
        
</param-value>
    
</context-param>
    
    
<listener>
        
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    
</listener>

        
<servlet>
            
<servlet-name>service</servlet-name>
            
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        
</servlet>

        
<servlet-mapping>
            
<servlet-name>service</servlet-name>
            
<url-pattern>/service/xmlrpc3/*</url-pattern>
        
</servlet-mapping>
ç„¶åŽæˆ‘们的service地倞®±æ˜¯˜q™æ ·çš„http://localhost:8080/service/xmlrpc3/account

希望对大家有用,˜q™é‡Œæä¾›project下è²ã€‚包å«ä¸€ä¸ªclient½E‹åºã€‚com.jdkcn.xmlrpc.Client

点击下è²å®Œæ•´ä»£ç 

创造共用åè®?¾|²å,éžå•†ä¸?ä¿æŒä¸€è‡? src=   除ç»ç‰¹åˆ«æ³¨æ˜Žå¤?本文章版æƒå½’莫多泡æˆö所æœ?
¾|²å,éžå•†ä¸šç”¨é€?ä¿æŒä¸€è‡?   somebody(莫多)

莫多 2006-10-22 16:12 å‘表评论
]]>
关于springå¯åŠ¨çš„ä¼˜åŒ–çš„é—®é¢˜http://www.aygfsteel.com/rory/archive/2006/08/10/speed_up_spring_problem.html莫多莫多Thu, 10 Aug 2006 02:59:00 GMThttp://www.aygfsteel.com/rory/archive/2006/08/10/speed_up_spring_problem.htmlhttp://www.aygfsteel.com/rory/comments/62740.htmlhttp://www.aygfsteel.com/rory/archive/2006/08/10/speed_up_spring_problem.html#Feedback2http://www.aygfsteel.com/rory/comments/commentRss/62740.htmlhttp://www.aygfsteel.com/rory/services/trackbacks/62740.html  jspark 的这½‹‡æ–‡ç« ã€?a class="postTitle2" id="viewpost1_TitleUrl" href="/jspark/archive/2006/07/29/60712.html">å¼€å‘阶ŒDµeclipse下é¢çš„spring容器的å¯åŠ¨ä¼˜åŒ?/a> 》讲到如何加快springçš„å¯åŠ¨é€Ÿåº¦ã€‚éžå¸¸æ„Ÿè°?span style="FONT-WEIGHT: bold">jspark. 一下是引用的原文:

  最˜q‘在负责一个大™å¹ç›®åQŒé¡¹ç›®ç»„æˆå‘˜åŒ…括™å¹ç›®¾lç†å¤§æ¦‚10个ähå·¦å³ã€‚项目技术用struts+spring+hibernate实现。项目的规模相对æ¥è¯´æ˜¯æ¯”较大的,æ€Õd…±æœ?0大模å—,æ¯ä¸ªå¤§æ¨¡å—åˆåˆ†äؓ有å几个ã€ç”šè‡›_‡ å个ž®æ¨¡å—。开å‘å·¥å…ïL”¨eclipseåQŒç”±äºŽåœ¨å¼€å‘阶ŒDµï¼Œ™å¹ç›®å¼€å‘æˆå‘˜éœ€è¦é¢‘¾Jé‡å¯æœåŠ¡å™¨ã€‚åœ¨å¯åЍæœåŠ¡å™¨çš„æ—¶å€™ï¼Œæ¯æ¬¡å¯åŠ¨æ—‰™—´æ€ÀL˜¯ä¼šè¶…˜q?分钟。记得以å‰åœ¨åšå¦å¤–一个项目时åQŒå¯åŠ¨æ—¶é—´ä¸åˆ?¿U’é’ŸåQŒç›¸å·®äº†10å€ï¼Œè€Œä¸”™å¹ç›®è§„模是差ä¸å¤šçš„ã€?/span>

    ä»Žåˆæ­¥åˆ†æžæ¥è¯ß_¼Œåº”该是hibernate解释hbm.xml时花è´ÒŽ—¶é—ß_¼Œæˆ–者å¯èƒ½æ˜¯spring容器å¯åЍòq¶è§£é‡Šæ‰€æœ‰çš„beané…置文äšg。诊断了一下,å‘现1分钟消耗的旉™—´ä¸»è¦åˆ†å¸ƒåœ¨hibernate解释hbm.xmlèŠÞp´¹5¿U’ï¼›spring容器从å¯åŠ¨åˆ°è§£é‡Šbeané…置文äšg竟然èŠ×ƒº†58¿U’,真是太嚣张了。当旉™žå¸¸æ€€ç–‘spring的效率问题。ä¼å›¾ä»Ž¾|‘上æœçƒ¦ç›¸å…³èµ„æ–™åQŒçœ‹çœ‹æœ‰ä»€ä¹ˆä¼˜åŒ–措施ã€?/span>

    首先是找åˆîCº†hibernateçš„å¯åŠ¨ä¼˜åŒ?http://www.hibernate.org/194.html  里é¢çš„ä¸»è¦æ€æƒ³æ˜¯é€šè¿‡ž®†xmlåºåˆ—花到本地的文仉™‡ŒåQŒæ¯‹Æ¡è¯»å–çš„æ—¶å€™æ ¹æ®æƒ…况,从本地文件读å–åÆˆååºåˆ—化åQŒèŠ‚çœäº†hibernate xmlçš„è§£æžæ—¶é—´ã€‚æŒ‰ç…§è¿™ä¸ªæ–¹å¼æµ‹è¯•了一下,å‘现hibernateçš„å¯åŠ¨æ—¶é—´ä»Ž5¿U’é™ä½Žåˆ°3¿U’,但是˜q™ä¸ªä¼˜åŒ–对于整个å¯åЍ˜q‡ç¨‹æ˜¯æ¯æ°´èžR薪的åQŒæ¯«æ— ç”¨å¤„ã€?/span>

    没办法,åˆä»”¾l†æŸ¥çœ‹äº†spring的资料,¾lˆäºŽå‘现spring的容器是æä¾›äº†lazy-load的,å³é»˜è®¤çš„¾~ºçœè®„¡½®æ˜¯bean没有lazy- loadåQŒè¯¥å±žæ€§å¤„于false状æ€ï¼Œ˜q™æ ·å¯ÆD‡´spring在å¯åŠ¨è¿‡½E‹å¯¼è‡´åœ¨å¯åŠ¨æ—¶å€™ï¼Œä¼šé»˜è®¤åŠ è½½æ•´ä¸ªå¯¹è±¡å®žä¾‹å›¾åQŒä»Žåˆå§‹åŒ–ACTIONé…ç½®ã€åˆ° serviceé…置到daoé…ç½®ã€ä¹ƒè‡›_ˆ°æ•°æ®åº“连接ã€äº‹åŠ¡ç­‰½{‰ã€‚这么庞大的规模åQŒé𾿀ªspringçš„å¯åŠ¨æ—¶é—´è¦èб将˜q?分钟。å°è¯•了一下,把beansçš?default-lazy-initæ”¹äØ“truež®±ï¼Œå†æ¬¡å¯åЍåQŒé€Ÿåº¦ä»ŽåŽŸæ¥çš„55¿U’,é™åˆ°8¿U’é’ŸåQï¼GreatåQ虽然是éžå¸¸ž®ä¸€ä¸ªæ”¹åŠ¨ï¼Œä½†æ˜¯å½±å“¼‹®å®žéžå¸¸å¤§ã€‚一个项目组10个ähåQŒå‡è‹¥æ¯ä¸ªäh一天åã^å‡éœ€è¦åœ¨eclipse下å¯åŠ¨æµ‹è¯•æœåС噍50‹Æ¡ã€‚那么一天项目组需è¦é‡å?00‹Æ¡ï¼Œæ¯æ¬¡èŠ‚çœ50¿U’çš„è¯ï¼Œž®±æ˜¯ 25000¿U’,ž®†è¿‘几个ž®æ—¶åQŒå·®ä¸å¤šä¸€ä¸ªå·¥ä½œæ—¥åQŒå¤šä¹ˆå¯è§‚的数字åQ?/span>

   ä¸è¿‡åœ¨è¿è¡ŒæœŸé—´ç¬¬ä¸€‹Æ¡ç‚¹™åµé¢çš„æ—¶å€™ï¼Œç”׃ºŽspringåšäº†lazy-loadåQŒçŽ°åœ¨å°±éœ€è¦å¯åŠ¨ä¸€éƒ¨åˆ†éœ€è¦çš„beansåQŒæ‰€ä»¥ç¨å¾®æ…¢2åQ?¿U’é’ŸåQŒä½†æ˜¯æ˜Žæ˜¾æ¯”½{‰å‡ åç§’è¦å¿«å¾ˆå¤šåQŒå€¼å¾—一鉴ã€?/span>

    以上是针对开å‘阶ŒD늚„spring容器å¯åŠ¨ä¼˜åŒ–åQŒåœ¨éƒ¨çÖv到实际环境中åQŒå€’是没必è¦è®¾¾|®äØ“lazy-load。毕竟部¾|²åˆ°å®žé™…çŽ¯å¢ƒä¸­ä¸æ˜¯ç»å¸¸çš„äº‹ï¼Œæ¯æ¬¡å¯åЍ1åˆ†é’Ÿå€’ä¸æ˜¯å¤§é—®é¢˜ã€?

æˆ‘è¿™é‡Œè¦æé†’çš„æ˜¯ä¸æ˜¯è¯´æœ‰çš„beans都能讄¡½®default-lazy-initæˆäØ“true.对于schedulerçš„beanä¸èƒ½ç”¨lazy-init

< beans  default-lazy-init ="true" >
    
    
< bean  class ="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
        
< property  name ="triggers" >
            
< list >
                
< ref  bean ="buildHtmlTrigger" />
                
< ref  bean ="askTrigger" />
                
< ref  bean ="mailSenderTrigger" />
                
< ref  bean ="topicDetailBuildTrigger" />
                
< ref  bean ="forumBuildTrigger" />
                
< ref  bean ="topicBuildTrigger" />
            
</ list >
        
</ property >
    
</ bean >
</ beans >




˜q™æ ·çš„è¯ã€‚所有的schedulerž®±éƒ½ä¸ç®¡ç”¨äº†ã€‚æ‰€ä»¥è¯·å¤§å®¶è¦æ³¨æ„ã€?br />

< beans >
    
    
< bean  class ="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
        
< property  name ="triggers" >
            
< list >
                
< ref  bean ="buildHtmlTrigger" />
                
< ref  bean ="askTrigger" />
                
< ref  bean ="mailSenderTrigger" />
                
< ref  bean ="topicDetailBuildTrigger" />
                
< ref  bean ="forumBuildTrigger" />
                
< ref  bean ="topicBuildTrigger" />
            
</ list >
        
</ property >
    
</ bean >
</ beans >


 



]]>
关于Freemarker生æˆé™æ€æ–‡ä»¶çš„问题http://www.aygfsteel.com/rory/archive/2006/06/21/54134.html莫多莫多Wed, 21 Jun 2006 02:46:00 GMThttp://www.aygfsteel.com/rory/archive/2006/06/21/54134.htmlhttp://www.aygfsteel.com/rory/comments/54134.htmlhttp://www.aygfsteel.com/rory/archive/2006/06/21/54134.html#Feedback0http://www.aygfsteel.com/rory/comments/commentRss/54134.htmlhttp://www.aygfsteel.com/rory/services/trackbacks/54134.html使用FreeMarker生æˆHtml陿€æ–‡ä»?实例)ã€?br />      在我们的™å¹ç›®ä¸­ä¹Ÿç”¨åˆ°äº†Freemarker生æˆé™æ€æ–‡ä»¶ã€‚丘q‡è¿™é‡Œæˆ‘è¦è¯´çš„æ˜¯¾~–ç çš„问题。我们的™å¹ç›®ä½¿ç”¨çš„都是UTF-8¾~–ç åQŒæˆ‘直接使用 飞云ž®ä¾  æä¾›çš„æ–¹æ³•生æˆçš„æ–‡äšg在UTF-8¾~–ç ä¸‹å¯Ÿçœ‹æ˜¯ä¹Þq åQŒè€ŒGBK正常(åŽæ¥å‘çŽ°å› äØ“æˆ‘ç”¨çš„ä¸­æ–‡æ“作系¾lŸæ‰€ä»¥ç”¨GBK查看正常)ã€?br />      当然我把Freemarker的酾|®éƒ½æ”ÒŽˆäº†UTF-8åQŒæˆ‘的模版文件也是UTF-8¾~–ç çš„ã€‚ä¸‹é¢æ˜¯åŽŸæ¥çš„代ç ?br />
    public void setTemplatePath(Resource templatePath) {
        
this.templatePath = templatePath;
        
//讄¡½®freemarkerçš„å‚æ•?/span>
        freemarkerCfg = new Configuration();
        
try {
            freemarkerCfg.setDirectoryForTemplateLoading(
this.templatePath.getFile());
            freemarkerCfg.setObjectWrapper(
new DefaultObjectWrapper());
            freemarkerCfg.setDefaultEncoding(
"UTF-8");
        } 
catch (IOException ex) {
            
throw new SystemException("No Directory found,please check you config.");
        }
    }
    /**
     * 生æˆé™æ€æ–‡ä»?br />     * 
@param templateFileName 模版åç§°eg:(biz/order.ftl)
     * 
@param propMapÂ ç”¨äºŽå¤„ç†æ¨¡æ¿çš„属性Object映射 
     * 
@param htmlFilePath è¦ç”Ÿæˆçš„陿€æ–‡ä»¶çš„路径,相对讄¡½®ä¸­çš„æ ¹èµ\å¾?例如 "/biz/2006/5/" 
     * 
@param htmlFileName è¦ç”Ÿæˆçš„æ–‡äšgå?例如 "123.htm" 
     * 
@return
     
*/
    
private boolean buildHtml(String templateFileName,Map propMap, String htmlFilePath,String htmlFileName){
        
try {
            Template template 
= freemarkerCfg.getTemplate(templateFileName);
            template.setEncoding(
"UTF-8");
            
//创å¾ç”Ÿæˆæ–‡äšg目录
            creatDirs(buildPath.getFilename(),htmlFilePath);
            File htmlFile 
= new File(buildPath + htmlFilePath + htmlFileName);
            Writer out 
= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile)));
            template.process(propMap,out);
            out.flush();
            
return true;
        } 
catch (TemplateException ex){
            log.error(
"Build Error"+templateFileName,ex);
            
return false;
        } 
catch (IOException e) {
            log.error(
"Build Error"+templateFileName,e);
            
return false;
        }
        
    }
䏋颿˜¯ä¿®æ”¹ä¹‹åŽçš„代ç 
    /**
     * 生æˆé™æ€æ–‡ä»?br />     * 
@param templateFileName 模版åç§°eg:(biz/order.ftl)
     * 
@param propMapÂ ç”¨äºŽå¤„ç†æ¨¡æ¿çš„属性Object映射 
     * 
@param htmlFilePath è¦ç”Ÿæˆçš„陿€æ–‡ä»¶çš„路径,相对讄¡½®ä¸­çš„æ ¹èµ\å¾?例如 "/biz/2006/5/" 
     * 
@param htmlFileName è¦ç”Ÿæˆçš„æ–‡äšgå?例如 "123.htm" 
     * 
@return
     
*/
    
private boolean buildHtml(String templateFileName,Map propMap, String htmlFilePath,String htmlFileName){
        
try {
            Template template 
= freemarkerCfg.getTemplate(templateFileName);
            template.setEncoding(
"UTF-8");
            
//创å¾ç”Ÿæˆæ–‡äšg目录
            creatDirs(buildPath.getFilename(),htmlFilePath);
            File htmlFile 
= new File(buildPath + htmlFilePath + htmlFileName);
            Writer out 
= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile),"UTF-8"));
            template.process(propMap,out);
            out.flush();
            
return true;
        } 
catch (TemplateException ex){
            log.error(
"Build Error"+templateFileName,ex);
            
return false;
        } 
catch (IOException e) {
            log.error(
"Build Error"+templateFileName,e);
            
return false;
        }
        
    }
原因ž®±åœ¨äºŽOutputStreamWriterçš„ä¸åŒæž„造方æ³?br />
OutputStreamWriter(OutputStream out)
          创å¾ä½¿ç”¨é»˜è®¤å­—符¾~–ç çš?OutputStreamWriterã€?br />
OutputStreamWriter(OutputStream out, String charsetName)
          创å¾ä½¿ç”¨æŒ‡å®šå­—符集的 OutputStreamWriterã€?br />
 
˜q™ä¸ªæ˜¯ä¸­æ–‡JDK的文档说明,刚开始我使用默认的构造函敎ͼŒæ‰€ä»¥ä‹É用了¾pÈ»Ÿé»˜è®¤çš„ç¼–ç ï¼ŒGBKåQŒæ‰€ä»¥åœ¨ç”Ÿæˆé™æ€æ–‡ä»¶çš„æ—¶å€™æŠŠUTF-8内容用GBK¾~–ç å†™å…¥äº†ï¼Œæ‰€ä»¥åœ¨UTF-8下æµè§ˆå°±æœ‰é—®é¢˜ã€?br />
˜q˜æœ‰å…³äºŽä¿®æ”¹æ¨¡ç‰ˆæ–‡äšgåŒæ ·ä¹Ÿè¦æ³¨æ„˜q™ä¸ªé—®é¢˜ã€?br />
    public String loadTemplate(String templateName) {
        StringBuffer sb 
= new StringBuffer();
        
try {
            File file 
= new File(templatePath+"/"+templateName);
            BufferedReader reader 
= new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
            String line 
= reader.readLine();
            
while(line != null)    {
                sb.append(line);
                sb.append(
"\r\n");
                line 
= reader.readLine();
            }
            reader.close();
        } 
catch (IOException e) {
            
throw new SystemException("Loading template Error:",e);
        }
        
return sb.toString();
    }
    public void saveTemplate(String templateName, String templateContent) {
        
try {
            File file 
= new File(templatePath + "/" + templateName);
            Writer out 
= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"UTF-8"));
            out.write(templateContent);
            out.flush();
            
//扔出templatesave事äšg
            TemplateSaveEvent evt = new TemplateSaveEvent();
            evt.setTemplateName(templateName);
            dispatchTemplateEvent(evt);
        } 
catch (IOException e) {
            
throw new SystemException("Write template Error",e);
        }
    }



莫多 2006-06-21 10:46 å‘表评论
]]>
spring关于底层资æºçš„æŠ½è±¡æ˜¯å¦‚此方便http://www.aygfsteel.com/rory/archive/2006/06/11/52065.html莫多莫多Sun, 11 Jun 2006 15:01:00 GMThttp://www.aygfsteel.com/rory/archive/2006/06/11/52065.htmlhttp://www.aygfsteel.com/rory/comments/52065.htmlhttp://www.aygfsteel.com/rory/archive/2006/06/11/52065.html#Feedback2http://www.aygfsteel.com/rory/comments/commentRss/52065.htmlhttp://www.aygfsteel.com/rory/services/trackbacks/52065.html     最˜q‘看《Professional Java Development with the Spring Framework》时看到了spring对底层资æºçš„æŠ½è±¡åQŒæ‰æ‰‘Öˆ°äº†å®Œ¾ŸŽè§£å†Ïx–¹æ¡ˆã€?br />     原æ¥çš„代ç ï¼š
    private String templatePath;
    
public void setTemplatePath(String templatePath) {
        
this.templatePath = templatePath;
    }
    
public void initListener() {
        TemplateEventListener templateListener 
= new TemplateEventListener(){
            
public void handleTemplateEvent(TemplateEventSupport evt) {
                
// æ·ÕdŠ äº‹äšg到队列中
                queue.offer(evt);
                
if(log.isDebugEnabled()){
                    log.debug(
"Add Template about:" + evt.getTemplateName());
                }
            }
            
        };
        
        
//注册模版监å¬äº‹äšg
        templateManager.addEventListener(Constants.TEMPLATE_SAVE_EVENT, templateListener,false);
        
        
        
//讄¡½®freemarkerçš„å‚æ•?/span>
        freemarkerCfg = new Configuration();
        
try {
            freemarkerCfg.setDirectoryForTemplateLoading(
new File(templatePath));
            freemarkerCfg.setObjectWrapper(
new DefaultObjectWrapper());
            freemarkerCfg.setDefaultEncoding(
"UTF-8");
        } 
catch (IOException ex) {
            
throw new SystemException("No Directory found,please check you config.");
        }
    }
é…置文äšg

    
<bean id="buildHtmlService" class="cn.jdk.leaf.service.impl.BuildHtmlServiceImpl" init-method="initListener">
        
<property name="templatePath"><value>${templatePath}</value></property>
    
</bean>
templatePath.path=D:/template
使用spring对底层资æºçš„æŠ½è±¡åªè¦æŠŠtemplatePathæ”ÒŽˆResourcež®±å¯ä»¥äº†
    private Resource templatePath;
    
public void setTemplatePath(Resource templatePath) {
        
this.templatePath = templatePath;
    }
    
public void initListener() {
            TemplateEventListener templateListener 
= new TemplateEventListener(){
            
public void handleTemplateEvent(TemplateEventSupport evt) {
                
// æ·ÕdŠ äº‹äšg到队列中
                queue.offer(evt);
                
if(log.isDebugEnabled()){
                    log.debug(
"Add Template about:" + evt.getTemplateName());
                }
            }
            
        };    
        
//注册模版监å¬äº‹äšg
        templateManager.addEventListener(Constants.TEMPLATE_SAVE_EVENT, templateListener,false);
        
        
        
//讄¡½®freemarkerçš„å‚æ•?/span>
        freemarkerCfg = new Configuration();
        
try {
            freemarkerCfg.setDirectoryForTemplateLoading(templatePath.getFile());
            freemarkerCfg.setObjectWrapper(
new DefaultObjectWrapper());
            freemarkerCfg.setDefaultEncoding(
"UTF-8");
        } 
catch (IOException ex) {
            
throw new SystemException("No Directory found,please check you config.");
        }
    }
bean的酾|®ä¸å˜ï¼Œåªè¦ä¿®æ”¹propertiesæ–‡äšgž®±å¯ä»¥äº†ã€?br />
    <bean id="buildHtmlService" class="cn.jdk.leaf.service.impl.BuildHtmlServiceImpl" init-method="initListener">
        
<property name="templatePath"><value>${templatePath}</value></property>
    
</bean>
把propertiesæ–‡äšg修改æˆ?br />
templatePath.path=template
在webcontext目录下é¢å»ºç«‹ä¸€ä¸ªtemplate目录ž®±å¯ä»¥äº†ã€‚在部çÖv到æœåŠ¡å™¨çš„æ—¶å€™éœ€è¦éƒ¨¾|²åˆ°ä¸€ä¸ªç‰¹å®šçš„目录åªè¦ä¿®æ”¹˜q™ä¸ªé…置文äšgä¸?br />
templatePath.path=file:/D:/template
˜q™æ ·ž®±å¯ä»¥äº†ã€?br />
创造共用åè®?¾|²å,éžå•†ä¸?ä¿æŒä¸€è‡? src=  除ç»ç‰¹åˆ«æ³¨æ˜Žå¤?本文章版æƒå½’莫多泡æˆö所æœ?
¾|²å,éžå•†ä¸šç”¨é€?ä¿æŒä¸€è‡?   somebody(莫多)   


莫多 2006-06-11 23:01 å‘表评论
]]>
关于Hibernateçš„DetachedCriteria查询的addOrder问题的解军_Šžæ³?/title><link>http://www.aygfsteel.com/rory/archive/2006/05/29/48850.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Mon, 29 May 2006 15:29:00 GMT</pubDate><guid>http://www.aygfsteel.com/rory/archive/2006/05/29/48850.html</guid><wfw:comment>http://www.aygfsteel.com/rory/comments/48850.html</wfw:comment><comments>http://www.aygfsteel.com/rory/archive/2006/05/29/48850.html#Feedback</comments><slash:comments>9</slash:comments><wfw:commentRss>http://www.aygfsteel.com/rory/comments/commentRss/48850.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/rory/services/trackbacks/48850.html</trackback:ping><description><![CDATA[上篇文章:ã€?a class="singleposttitle" id="viewpost1_TitleUrl" href="/rory/archive/2006/05/21/47339.html"><font color="#223355"><strong>今天å‘现一个hibernateçš„bug,或者说一个应该注æ„的地方比较åˆé€?/strong></font></a> ã€‹é‡Œé¢æˆ‘æåˆ°äº†HibernateæŸ¥è¯¢éœ€è¦æ³¨æ„的一个问题。今天å‘çŽîCº†ä¸€ä¸ªæœ€å¥½çš„解决办法。如果大家现在用HibernateåQŒç›¸ä¿¡å¤§å®‰™ƒ½å›žç”¨åˆ°DetachedCriteria.关于DetachedCriteria查询è¯ähŸ¥çœ?a >http://dev.yesky.com/241/2033241.shtml</a>ã€?br />      DetachedCriteria¾l™æˆ‘们的Hibernate查询带æ¥äº†å¾ˆå¤šæ–¹ä¾¿ï¼Œä½†æ˜¯å¦‚果你带上排åºä¿¡æ¯å°±ä¼šå‡ºçŽ°æˆ‘çš„ä¸Šä¸€½‹‡æ–‡ç« é‡Œé¢è¯´çš„é‚£¿U错误,今天å‘现一个很好的解决æ–ÒŽ³•åQŒå…¶å®žä¹Ÿå¾ˆç®€å•。就是先把传入的带Orderä¿¡æ¯çš„DetachedCriteriaåŽÀLމorderä¿¡æ¯æŸ¥è¯¢æ•°æ®æ€ÀL¡æ•ŽÍ¼Œç„¶åŽå†æŠŠOrderåŠ å›žæ¥æŸ¥è¯¢æ»¡­‘Ïx¡ä»¶çš„对象。通过查看Hibernateçš„æºä»£ç å‘现Criteria的实现CriteriaImplå‘现其实addOrder是给private List orderEntries = new ArrayList();˜q™ä¸ªList加倹{€‚这个Listé‡Œé¢æ”„¡š„是OrderEntry对象。这个OrderEntryé‡Œé¢æ”¾äº†ä¸€ä¸ªcriteria å’?order.<br /><br />     <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> PaginationSupport findPageByCriteria(</span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> DetachedCriteria detachedCriteria, </span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> pageSize, </span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> startIndex) {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> (PaginationSupport) getHibernateTemplate().execute(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> HibernateCallback() {<br />            </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Object doInHibernate(Session session) </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> HibernateException {<br />                Criteria criteria </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> detachedCriteria.getExecutableCriteria(session);<br />                CriteriaImpl impl </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (CriteriaImpl) criteria;<br />                List orderEntrys </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> ArrayList();<br />                </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000">{<br />                    Field field </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> CriteriaImpl.</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">.getDeclaredField(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">orderEntries</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />                    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Get orders</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">                    orderEntrys </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (List) field.get(impl);<br />                    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Remove orders</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">                    field.set(criteria,</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> ArrayList());<br />                }</span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000">(Exception ex){<br />                    ex.printStackTrace();<br />                    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">TODO xxxx</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">                }<br />                </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> totalCount </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> ((Integer) criteria.setProjection(Projections.rowCount())<br />                        .uniqueResult()).intValue();<br />                criteria.setProjection(</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">);<br />                <br />                </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000">{<br />                    Field field </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> CriteriaImpl.</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">.getDeclaredField(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">orderEntries</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />                    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Add orders return</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">                    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">orderEntrys.size(); i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br />                        List innerOrderEntries </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (List) field.get(criteria);<br />                        innerOrderEntries.add(orderEntrys.get(i));<br />                    }<br />                }</span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000">(Exception ex){<br />                    ex.printStackTrace();<br />                    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">TODO cccc</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">                }<br />                List items </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> criteria.setFirstResult(startIndex).setMaxResults(pageSize).list();<br />                PaginationSupport ps </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> PaginationSupport(items, totalCount, pageSize,<br />                        startIndex);<br />                </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> ps;<br />            }<br />        }, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">);<br />    }</span></div>希望大家多多交æµ<img src ="http://www.aygfsteel.com/rory/aggbug/48850.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/rory/" target="_blank">莫多</a> 2006-05-29 23:29 <a href="http://www.aygfsteel.com/rory/archive/2006/05/29/48850.html#Feedback" target="_blank" style="text-decoration:none;">å‘表评论</a></div>]]></description></item><item><title>关于Hibernate3çš„NativeSQL查询是如此简å?/title><link>http://www.aygfsteel.com/rory/archive/2006/05/26/48274.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Fri, 26 May 2006 02:33:00 GMT</pubDate><guid>http://www.aygfsteel.com/rory/archive/2006/05/26/48274.html</guid><wfw:comment>http://www.aygfsteel.com/rory/comments/48274.html</wfw:comment><comments>http://www.aygfsteel.com/rory/archive/2006/05/26/48274.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/rory/comments/commentRss/48274.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/rory/services/trackbacks/48274.html</trackback:ping><description><![CDATA[现在的系¾lŸä¸­è™½ç„¶ä½¿ç”¨äº†ã€‚Hibernate但是没有使用Hibernate的关è”å…³¾pÀL¥˜q›è¡Œæ•°æ®åº“æ“作。所有的½Ž¡ç†æ“作都是å•独实现的。所以也ä¸èƒ½ç”¨Criteria.add()˜q™ç§æ–¹å¼åŽÀLŸ¥è¯¢å…³è”的一æ–V€‚所以åªèƒ½ç”¨Native SQLåŽÀLŸ¥è¯¢ç»“果返回对象了。按照Hibernate3çš„reference里é¢è¯´çš„<br /><div id="wmqeeuq" class="sect1" lang="zh-cn"><div id="wmqeeuq" class="titlepage"><div><div><h2 class="title" style="CLEAR: both"><font color="#006400">16.1. 使用<tt class="literal">SQLQuery</tt></font></h2></div></div><div><font color="#006400"></font></div></div><p><font color="#006400">对原生SQL查询执行的控制是通过<tt class="literal">SQLQuery</tt>接壘q›è¡Œçš„,通过执行<tt class="literal">Session.createSQLQuery()</tt>获喘q™ä¸ªæŽ¥å£ã€‚最½Ž€å•的情况下,我们å¯ä»¥é‡‡ç”¨ä»¥ä¸‹å½¢å¼åQ?/font></p><pre class="programlisting"><font color="#006400">List cats = sess.createSQLQuery("select * from cats") .addEntity(Cat.class) .list();</font></pre><p><font color="#006400">˜q™ä¸ªæŸ¥è¯¢æŒ‡å®šäº?</font></p><div id="wmqeeuq" class="itemizedlist"><ul type="disc"><li><p><font color="#006400">SQL查询字符ä¸?/font></p></li><li><p><font color="#006400">查询˜q”回的实ä½?/font></p></li></ul></div><p><font color="#006400">˜q™é‡ŒåQŒç»“果集字段å被å‡è®¾ä¸ÞZ¸Žæ˜ å°„æ–‡äšg中指明的字段å相åŒã€‚对于连接了多个表的查询åQŒè¿™ž®±å¯èƒ½é€ æˆé—®é¢˜åQŒå› ä¸ºå¯èƒ½åœ¨å¤šä¸ªè¡¨ä¸­å‡ºçŽ°åŒæ ·å字的字ŒDüc€‚下é¢çš„æ–ÒŽ³•ž®±å¯ä»¥é¿å…å­—ŒDµåé‡å¤çš„é—®é¢?</font></p><pre class="programlisting"><font color="#006400">List cats = sess.createSQLQuery("select {cat.*} from cats cat") .addEntity("cat", Cat.class) .list();</font></pre><p><font color="#006400">˜q™ä¸ªæŸ¥è¯¢æŒ‡å®šäº? </font></p><div id="wmqeeuq" class="itemizedlist"><ul type="disc"><li><p><font color="#006400">SQL查询语å¥åQŒå®ƒå¸¦ä¸€ä¸ªå ä½ç¬¦åQŒå¯ä»¥è®©Hibernate使用字段的别å? </font></p></li><li><p><font color="#006400">查询˜q”回的实体,和它的SQL表的别å. </font></p></li></ul></div><p><font color="#006400"><tt class="literal">addEntity()</tt>æ–ÒŽ³•ž®†SQL表的别å和实体类è”ç³»èµäh¥åQŒåƈ且确定查询结果集的åÅžæ€ã€?</font></p><p><font color="#006400"><tt class="literal">addJoin()</tt>æ–ÒŽ³•å¯ä»¥è¢«ç”¨äºŽè²å…¥å…¶ä»–的实体和集åˆçš„å…Œ™”. </font></p><pre class="programlisting"><font color="#006400">List cats = sess.createSQLQuery( "select {cat.*}, {kitten.*} from cats cat, cats kitten where kitten.mother = cat.id" ) .addEntity("cat", Cat.class) .addJoin("kitten", "cat.kittens") .list();</font></pre><p><font color="#006400">原生的SQL查询å¯èƒ½˜q”回一个简å•的标é‡å€¼æˆ–者一个标é‡å’Œå®žä½“的结åˆä½“ã€?</font></p><pre class="programlisting"><font color="#006400">Double max = (Double) sess.createSQLQuery("select max(cat.weight) as maxWeight from cats cat") .addScalar("maxWeight", Hibernate.DOUBLE); .uniqueResult();</font></pre><p><font color="#006400">除此之外åQŒä½ ˜q˜å¯ä»¥åœ¨ä½ çš„hbmæ–‡äšg中æ˜q°ç»“果集映射信æ¯åQŒåœ¨æŸ¥è¯¢ä¸­ä‹É用ã€?/font></p><pre class="programlisting"><font color="#006400">List cats = sess.createSQLQuery( "select {cat.*}, {kitten.*} from cats cat, cats kitten where kitten.mother = cat.id" ) .setResultSetMapping("catAndKitten") .list();<br /></font></pre></div><br />åŽæ¥æˆ‘ä‹É用了命åSQL查询方å¼ã€?br /><div id="wmqeeuq" class="titlepage"><div><div><h2 class="title" style="CLEAR: both"><font color="#006400">16.3. 命åSQL查询</font></h2></div></div><div><font color="#006400"></font></div></div><p><font color="#006400">å¯ä»¥åœ¨æ˜ ž®„文档中定义查询的åå­?然厞®±å¯ä»¥è±¡è°ƒç”¨ä¸€ä¸ªå‘½åçš„HQL查询一æ ïL›´æŽ¥è°ƒç”¨å‘½åSQL查询.在这¿U情况下,我们<span id="wmqeeuq" class="emphasis"><em>ä¸?/em></span> 需è¦è°ƒç”?tt class="literal">addEntity()</tt>æ–ÒŽ³•. </font></p><pre class="programlisting"><font color="#006400"><sql-query name="persons"> <return alias="person" class="eg.Person"/> SELECT person.NAME AS {person.name}, person.AGE AS {person.age}, person.SEX AS {person.sex} FROM PERSON person WHERE person.NAME LIKE :namePattern </sql-query></font></pre><pre class="programlisting"><font color="#006400">List people = sess.getNamedQuery("persons") .setString("namePattern", namePattern) .setMaxResults(50) .list();</font><br /><br />我觉得这¿Uå‘弿¯”较好。这样写出æ¥çš„sqlå¯ä»¥å¾ˆæ•´é½ã€‚我们的数æ®åº“ä‹É用的是oracleåQŒä¸˜q‡æŒ‰ç…§è¿™ä¸Šé¢çš„写法å‘现sqlè¯­å¥æœ‰é”™è¯¯ã€?br />åŽæ¥æ‹¿åˆ°æŽ§åˆ¶å°æ‰§è¡Œä¹ŸæŠ±é”™ã€‚因为原æ¥éƒ½ç”¨sqlserveråQŒè€Œsqlserver都是å¯ä»¥çš„ã€‚åŽæ¥å‘现是表ä¸èƒ½æœ‰åˆ«åæ”ÒŽˆ˜q™æ ·ž®±å¥½äº†ã€?br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">            </span><span style="COLOR: #0000ff">SELECT</span><span style="COLOR: #000000"> T_PAY.sys_id </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.sysId},<br />                   T_PAY.sys_flag </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.sysFlag},<br />                   T_PAY.sys_domain </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.sysDomain},<br />                   T_PAY.sys_owner </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.sysOwner},<br />                   T_PAY.sys_create_date </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.sysCreateDate},<br />                   T_PAY.sys_update_date </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.sysUpdateDate},<br />                   T_PAY.pay_id </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.payId},<br />                   T_PAY.pay_name </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.payName},<br />                   T_PAY.pay_type_id </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.payTypeId},<br />                   T_PAY.pay_date </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.payDate},<br />                   T_PAY.money_type_id </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.moneyTypeId},<br />                   T_PAY.amount </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.amount},<br />                   T_PAY.payer_id </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.payerId},<br />                   T_PAY.payer_name </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.payerName},<br />                   T_PAY.accept_id </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.acceptId},<br />                   T_PAY.accept_name </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.acceptName},<br />                   T_PAY.pay_state_id </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.payStateId},<br />                   T_PAY.remark </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> {pay.remark}<br />            </span><span style="COLOR: #0000ff">FROM</span><span style="COLOR: #000000">   T_PAY<br />            </span><span style="COLOR: #0000ff">JOIN</span><span style="COLOR: #000000">   T_BIZ_PAY<br />            </span><span style="COLOR: #0000ff">ON</span><span style="COLOR: #000000">       T_PAY.pay_id </span><span style="COLOR: #808080">=</span><span style="COLOR: #000000"> T_BIZ_PAY.pay_id<br />            </span><span style="COLOR: #0000ff">WHERE</span><span style="COLOR: #000000">  T_BIZ_PAY.biz_id </span><span style="COLOR: #808080">=</span><span style="COLOR: #000000"> :bizId</span></div></pre>  <strong>˜q™é‡Œè¦ç‰¹åˆ«çš„æé†’一下大家åƒä¸‡ä¸è¦æŠŠä¸»é”®å¿˜äº†ã€‚刚开始我ž®±å¿˜äº†ä¸»é”®ï¼ŒåŽæ¥è°ƒè¯•了åŠå¤©æ‰æ‰‘Ö‡ºåŽŸå› æ¥ã€?br /></strong><br />˜q™æ ·åœ¨sping里é¢ç”¨å›žè°ƒæŸ¥è¯¢ä¸€ä¸‹å°±ok了。真的很方便.<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> List getPaysByBizId(</span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> String bizId) {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> (List)getHibernateTemplate().execute(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> HibernateCallback(){<br />            </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Object doInHibernate(Session session)</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> HibernateException{<br />                Query query </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> session.getNamedQuery(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">find.pays.by.bizid</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />                query.setParameter(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">bizId</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,bizId);<br />                </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> query.list();<br />            }<br />        },</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">);<br />    }</span></div><img src ="http://www.aygfsteel.com/rory/aggbug/48274.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/rory/" target="_blank">莫多</a> 2006-05-26 10:33 <a href="http://www.aygfsteel.com/rory/archive/2006/05/26/48274.html#Feedback" target="_blank" style="text-decoration:none;">å‘表评论</a></div>]]></description></item><item><title>今天å‘现一个hibernateçš„bug,或者说一个应该注æ„的地方比较åˆé€?/title><link>http://www.aygfsteel.com/rory/archive/2006/05/21/47339.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Sun, 21 May 2006 14:49:00 GMT</pubDate><guid>http://www.aygfsteel.com/rory/archive/2006/05/21/47339.html</guid><wfw:comment>http://www.aygfsteel.com/rory/comments/47339.html</wfw:comment><comments>http://www.aygfsteel.com/rory/archive/2006/05/21/47339.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.aygfsteel.com/rory/comments/commentRss/47339.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/rory/services/trackbacks/47339.html</trackback:ping><description><![CDATA[今天把myblog用sql server部çÖväº†ä¸€ä¸‹ï¼Œå¯æ˜¯å‘çŽ°åˆ†é¡µæŸ¥è¯¢çš„æ—¶å€™å‡ºçŽ°é”™è¯¯ï¼Œçœ‹æŽ§åˆ¶å°æŠ¥é”™è¯´è¯­å¥æœ‰é”?ç”±æ¥å‘现分页的时候先查询总记录数目的那æ¡è¯­å¥å‡ºé”™äº?br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">select</span><span style="COLOR: #000000"> </span><span style="COLOR: #ff00ff">count</span><span style="COLOR: #000000">(</span><span style="COLOR: #808080">*</span><span style="COLOR: #000000">) </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> y0_ </span><span style="COLOR: #0000ff">from</span><span style="COLOR: #000000"> myblog_Blog this_ </span><span style="COLOR: #0000ff">inner</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">join</span><span style="COLOR: #000000"> myblog_Blog_Category categories3_ </span><span style="COLOR: #0000ff">on</span><span style="COLOR: #000000"> this_.id</span><span style="COLOR: #808080">=</span><span style="COLOR: #000000">categories3_.blogId </span><span style="COLOR: #0000ff">inner</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">join</span><span style="COLOR: #000000"> myblog_Category category1_ </span><span style="COLOR: #0000ff">on</span><span style="COLOR: #000000"> categories3_.categoryId</span><span style="COLOR: #808080">=</span><span style="COLOR: #000000">category1_.id </span><span style="COLOR: #0000ff">where</span><span style="COLOR: #000000"> category1_.id</span><span style="COLOR: #808080">=</span><span style="COLOR: #000000">? </span><span style="COLOR: #0000ff">order</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">by</span><span style="COLOR: #000000"> this_.postTime </span><span style="COLOR: #0000ff">desc</span></div>      原æ¥å¼€å‘的时候我是用的mysqlåQŒæ²¡æœ‰ä“Q何问题。原因就在最åŽé¢çš„order by 语å¥åQŒsql server 在select count(*)里é¢ä¸èƒ½ç”?order by。然åŽè·Ÿítªä»£ç å‘çŽ?<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> PaginationSupport getBlogsByCategoryByPage(</span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> String categoryId, </span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> startIndex, </span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> pageSize) {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> (PaginationSupport) getHibernateTemplate().execute(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> HibernateCallback() {<br />            </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Object doInHibernate(Session session) </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> HibernateException {<br />                Criteria criteria </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> session.createCriteria(Blog.</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">);<br />                Criteria cateCriteria </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> criteria.createCriteria(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">categories</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />                cateCriteria.add(Expression.eq(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">id</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,categoryId));<br />                criteria.addOrder(Order.desc(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">postTime</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br />                </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> totalCount </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> ((Integer) criteria.setProjection(Projections.rowCount())<br />                        .uniqueResult()).intValue();<br />                criteria.setProjection(</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">);<br />                <br />                List items </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> criteria.setFirstResult(startIndex).setMaxResults(pageSize).list();<br />                List blogs </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> ArrayList();<br />                </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(Iterator ite </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> items.iterator(); ite.hasNext();) {<br />                    Object[] objs </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (Object[])ite.next();<br />                    blogs.add(objs[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br />                }<br />                PaginationSupport ps </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> PaginationSupport(blogs, totalCount, pageSize, startIndex);<br />                </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> ps;<br />            }<br />        }, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">);<br />    }</span></div>原æ¥é—®é¢˜ž®±åœ¨Criteria.addOrder(Order.desc("postTime"));˜q™å¥è¯çš„ä½ç½®ä¸Šé¢åQŒint totalCount = ((Integer) criteria.setProjection(Projections.rowCount())<br />      .uniqueResult()).intValue();<br />˜q™å¥è¯çš„æ—¶å€™å°±ä¼šç”Ÿæˆä¸Šé¢é‚£å¥è¯åQŒå¦‚果在˜q™ä¹‹å‰addOrderž®×ƒ¼šå‡ºçŽ°é—®é¢˜åQŒå¦‚果你用mysqlä¸ä¼šå‡ºçŽ°é—®é¢˜åQŒå¦‚果你用sql serverž®×ƒ¼šæŠ¥é”™ã€‚è§£å†Ïx–¹æ³•就是把addOrderè¯­å¥æ”‘Öˆ°totalCount下颞®±å¯ä»¥äº†ã€?br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> PaginationSupport getBlogsByCategoryByPage(</span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> String categoryId, </span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> startIndex, </span><span style="COLOR: #0000ff">final</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> pageSize) {<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> (PaginationSupport) getHibernateTemplate().execute(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> HibernateCallback() {<br />            </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> Object doInHibernate(Session session) </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> HibernateException {<br />                Criteria criteria </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> session.createCriteria(Blog.</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">);<br />                Criteria cateCriteria </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> criteria.createCriteria(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">categories</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />                cateCriteria.add(Expression.eq(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">id</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,categoryId));<br />                </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> totalCount </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> ((Integer) criteria.setProjection(Projections.rowCount())<br />                        .uniqueResult()).intValue();<br />                criteria.setProjection(</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">);<br />                <br />                </span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br />                 * Fix a bug ,Order must add after get the totalCount,<br />                 * beacuse SqlServer not support order by in the select count(*).<br />                 </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br />                criteria.addOrder(Order.desc(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">postTime</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br />                List items </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> criteria.setFirstResult(startIndex).setMaxResults(pageSize).list();<br />                List blogs </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> ArrayList();<br />                </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(Iterator ite </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> items.iterator(); ite.hasNext();) {<br />                    Object[] objs </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (Object[])ite.next();<br />                    blogs.add(objs[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br />                }<br />                PaginationSupport ps </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> PaginationSupport(blogs, totalCount, pageSize, startIndex);<br />                </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> ps;<br />            }<br />        }, </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">);<br />    }</span></div><br />˜q™æ ·ç”Ÿæˆçš„sql语奞®±æ˜¯˜q™æ ·çš„ã€?br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">select</span><span style="COLOR: #000000"> </span><span style="COLOR: #ff00ff">count</span><span style="COLOR: #000000">(</span><span style="COLOR: #808080">*</span><span style="COLOR: #000000">) </span><span style="COLOR: #0000ff">as</span><span style="COLOR: #000000"> y0_ </span><span style="COLOR: #0000ff">from</span><span style="COLOR: #000000"> myblog_Blog this_ </span><span style="COLOR: #0000ff">inner</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">join</span><span style="COLOR: #000000"> myblog_Blog_Category categories3_ </span><span style="COLOR: #0000ff">on</span><span style="COLOR: #000000"> this_.id</span><span style="COLOR: #808080">=</span><span style="COLOR: #000000">categories3_.blogId </span><span style="COLOR: #0000ff">inner</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">join</span><span style="COLOR: #000000"> myblog_Category category1_ </span><span style="COLOR: #0000ff">on</span><span style="COLOR: #000000"> categories3_.categoryId</span><span style="COLOR: #808080">=</span><span style="COLOR: #000000">category1_.id </span><span style="COLOR: #0000ff">where</span><span style="COLOR: #000000"> category1_.id</span><span style="COLOR: #808080">=</span><span style="COLOR: #000000">?</span></div><br />以åŽå¤§å®¶ä¹Ÿè¦æ³¨æ„了。呵å‘üc€?br /><img src ="http://www.aygfsteel.com/rory/aggbug/47339.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/rory/" target="_blank">莫多</a> 2006-05-21 22:49 <a href="http://www.aygfsteel.com/rory/archive/2006/05/21/47339.html#Feedback" target="_blank" style="text-decoration:none;">å‘表评论</a></div>]]></description></item><item><title>如何¾l™webworkçš„action里的Field讄¡½®åˆå§‹å€?¾l?http://www.aygfsteel.com/rory/archive/2006/04/22/42463.html莫多莫多Sat, 22 Apr 2006 03:21:00 GMThttp://www.aygfsteel.com/rory/archive/2006/04/22/42463.htmlhttp://www.aygfsteel.com/rory/comments/42463.htmlhttp://www.aygfsteel.com/rory/archive/2006/04/22/42463.html#Feedback0http://www.aygfsteel.com/rory/comments/commentRss/42463.htmlhttp://www.aygfsteel.com/rory/services/trackbacks/42463.html如何¾l™webworkçš„action里的Field讄¡½®åˆå§‹å€?/a>

jdev说到"ä¸ÞZ»€ä¹ˆè¦æ”‘Öœ¨˜q™é‡ŒåQŒè€Œä¸æ˜¯æ”¾åˆ°ç³»¾lŸé…¾|®æ–‡ä»¶ä¸­åQŒç„¶åŽåœ¨¾pÈ»Ÿè®„¡½®ç•Œé¢ä¸­æä¾›è®¾¾|?åQŒåŽæ¥æˆ‘ž®Þq”¨springæ¥æ³¨å…¥äº†ã€‚现在就把值放入propertiesæ–‡äšg中了ã€?br />

    <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      
<property name="locations">
        
<list>
          
<value>classpath:mail.properties</value>
          
<value>classpath:upload.properties</value>
        
</list>
      
</property>
    
</bean>
    
<!-- 收å‘外部邮箱 author:somebody-->
    
<bean id="outMailManager" class="cn.com.fivefortunes.mail.manager.impl.OutMailManagerImpl">
        
<property name="javaMailSender"><ref bean="javaMailSender"/></property>
        
<property name="attachementDirectory"><value>${mail.attachementDirectory}</value></property>
        
<property name="uploadFileDirectory"><value>${upload.directory}</value></property>
        
<property name="outMailHibernateManager"><ref bean="outMailHibernateManager"/></property>
        
<property name="outMailAccountManager"><ref bean="outMailAccountManager"/></property>
    
</bean>
˜q™æ ·æŠŠuploadFileDirectory攑օ¥mananger中去了。在properties里é¢é…置一下就ok了ã€?br />

upload.directory
=D:\\tomcat5\\webapps\\files
mail.attachementDirectory
=D:\\tomcat5\\webapps\\files
上次˜q˜æœ‰¾|‘勘q™æ ·è¯´åˆ°"return ServletActionContext.getServletContext().getRealPath("/");

ä½ è¿™æ äh¢äº†éƒ¨¾|²çŽ¯å¢ƒæ¯‹Æ¡éƒ½è¦æ”¹
而且也该�
D://tomcat5//webapps//files"
ä¹Ÿè®¸å¾ˆå¤šäººéƒ½ä»¥äØ“˜q™æ˜¯æœ€å¥½çš„æ–¹å¼åQŒå¯æ˜¯å®žé™…æƒ…å†µä¸æ˜¯è¿™æ øP¼Œæˆ‘们的uploadfileç›®å½•å·²ç»æœ?G的文ä»Óž¼Œè€ŒåŸºæœ¬ä¸Šæ¯å¤©æˆ‘们都è¦å‘布新的webappåQŒå¦‚果把uploadfile目录攑ֈ°webapp的一个å­ç›®å½•åQŒæ¯‹Æ¡éƒ¨¾|²çš„æ—¶å€™éƒ½è¦å…ˆæŠŠuploadfile copy出æ¥ç„¶åŽå†éƒ¨¾|ŒÓ€‚所以我们这么嚞®±æ˜¯æŠŠupload目录攑ֈ°å…¶ä»–目录ä¸åª„å“uploadfile目录里é¢çš„æ–‡ä»¶ã€‚关于我们项目的部çÖvè§æˆ‘的下一½‹‡æ–‡ç« ã€‚谢谢大家。如果您有什么更好的æ–ÒŽ³•è¯äh‚¨æŒ‡æ•™ã€?img src ="http://www.aygfsteel.com/rory/aggbug/42463.html" width = "1" height = "1" />

莫多 2006-04-22 11:21 å‘表评论
]]>
springæ“作数æ®åº“如此简å?/title><link>http://www.aygfsteel.com/rory/archive/2006/04/07/39699.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Thu, 06 Apr 2006 16:03:00 GMT</pubDate><guid>http://www.aygfsteel.com/rory/archive/2006/04/07/39699.html</guid><wfw:comment>http://www.aygfsteel.com/rory/comments/39699.html</wfw:comment><comments>http://www.aygfsteel.com/rory/archive/2006/04/07/39699.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.aygfsteel.com/rory/comments/commentRss/39699.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/rory/services/trackbacks/39699.html</trackback:ping><description><![CDATA[以å‰ä¸€ç›´éƒ½æ²¡æœ‰è¯•过åQŒå‰å‡ å¤©æ‰“算把wordpressæ¢æˆè‡ªå·±å†™çš„½E‹åºåQŒå°±æƒ›_ˆ°äº†æ•°æ®çš„导入和导出,首先惛_ˆ°çš„æ˜¯ç”¨æ•°æ®åº“工具æ¥å¯¼ã€‚坿˜¯è§‰å¾—有些麻烦,我自å·Þqš„½E‹åºæ˜¯ç”¨spring+hibernateçš„ã€‚åŽæ¥æˆ‘ž®Þp¯•了一下springçš„JdbcTemplate,ž®±å’ŒHibernateTemplate一æ ïLš„好用。首先增加一个连接到wpæ•°æ®åº“çš„dataSource <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff"><</span><span style="COLOR: #800000">bean </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="dataSource2"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="org.springframework.jdbc.datasource.DriverManagerDataSource"</span><span style="COLOR: #ff0000"> destroy-method</span><span style="COLOR: #0000ff">="close"</span><span style="COLOR: #0000ff">></span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff"><</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="driverClassName"</span><span style="COLOR: #0000ff">><</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">></span><span style="COLOR: #000000">org.hibernate.dialect.MySQLDialect</span><span style="COLOR: #0000ff"></</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">></</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">></span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff"><</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="url"</span><span style="COLOR: #0000ff">></span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff"><</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">></span><span style="COLOR: #000000">jdbc:mysql://192.168.0.240:3306/wordpressωuseUnicode=true</span><span style="COLOR: #ff0000">&amp;</span><span style="COLOR: #000000">characterEncoding=utf8</span><span style="COLOR: #0000ff"></</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">></span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff"></</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">></span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff"><</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="username"</span><span style="COLOR: #0000ff">><</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">></span><span style="COLOR: #000000">root</span><span style="COLOR: #0000ff"></</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">></</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">></span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff"><</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="password"</span><span style="COLOR: #0000ff">><</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">></</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">></</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">></span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff"></</span><span style="COLOR: #800000">bean</span><span style="COLOR: #0000ff">></span></div><p>    ç„¶åŽåœ¨è{æ¢ç¨‹åºé‡Œé¢get˜q™ä¸ªdataSourceåQŒnew 一个JdbcTemplate(dataSource2)åQŒè¿™æ ·å°±ok了。很½Ž€å•å§ã€?/p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> testCopyData() </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br />        DataSource ds </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (DataSource)applicationContext.getBean(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">dataSource2</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        <br />        CategoryManager cateManager </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (CategoryManager) applicationContext.getBean(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">categoryManager</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        <br />        JdbcTemplate jt </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> JdbcTemplate(ds);<br />        System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Total posts:</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">jt.queryForInt(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">select count(*) from wp_posts</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br />        assertNotNull(ds);<br />        <br />        List cates </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> jt.queryForList(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">select * from wp_categories</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(Iterator ite </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> cates.iterator(); ite.hasNext();){<br />            i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">;<br />            Map result </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> (Map) ite.next();<br />            Category cate </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Category();<br />            cate.setName((String)result.get(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">cat_name</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br />            cate.setOrder(i);<br />            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)<br />                cate.setDefaultCategory(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">);<br />            cateManager.saveCategory(cate);<br />            System.out.println(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">cat_name:</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">result.get(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">cat_name</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        }<br />    }</span></div><img src ="http://www.aygfsteel.com/rory/aggbug/39699.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/rory/" target="_blank">莫多</a> 2006-04-07 00:03 <a href="http://www.aygfsteel.com/rory/archive/2006/04/07/39699.html#Feedback" target="_blank" style="text-decoration:none;">å‘表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> Ö÷Õ¾Ö©Öë³ØÄ£°å£º <a href="http://" target="_blank">ÓÀ°²ÊÐ</a>| <a href="http://" target="_blank">°¢¿ËËÕÊÐ</a>| <a href="http://" target="_blank">°²¼ªÏØ</a>| <a href="http://" target="_blank">Àè´¨ÏØ</a>| <a href="http://" target="_blank">ÓíÖÝÊÐ</a>| <a href="http://" target="_blank">½úÖÐÊÐ</a>| <a href="http://" target="_blank">¸ßÃÜÊÐ</a>| <a href="http://" target="_blank">ÒËÀ¼ÊÐ</a>| <a href="http://" target="_blank">ÓÀ¼ªÏØ</a>| <a href="http://" target="_blank">×¼¸ñ¶ûÆì</a>| <a href="http://" target="_blank">̨ÄÏÏØ</a>| <a href="http://" target="_blank">ÂåÂ¡ÏØ</a>| <a href="http://" target="_blank">¦µ×ÊÐ</a>| <a href="http://" target="_blank">ÆÖ½­ÏØ</a>| <a href="http://" target="_blank">Êè¸½ÏØ</a>| <a href="http://" target="_blank">ÌïÁÖÏØ</a>| <a href="http://" target="_blank">ÎåÕ¯ÏØ</a>| <a href="http://" target="_blank">ƾÏéÊÐ</a>| <a href="http://" target="_blank">ÄþºÓÏØ</a>| <a href="http://" target="_blank">½¨ÄþÏØ</a>| <a href="http://" target="_blank">Ûº£ÏØ</a>| <a href="http://" target="_blank">Ìì½òÊÐ</a>| <a href="http://" target="_blank">ÂÞ¶¨ÊÐ</a>| <a href="http://" target="_blank">å´²ýÏØ</a>| <a href="http://" target="_blank">ÂêÄÉË¹ÏØ</a>| <a href="http://" target="_blank">ÁÙ½­ÊÐ</a>| <a href="http://" target="_blank">ÁøºÓÏØ</a>| <a href="http://" target="_blank">»ª°²ÏØ</a>| <a href="http://" target="_blank">Î÷ÏçÏØ</a>| <a href="http://" target="_blank">¸ßÒØÏØ</a>| <a href="http://" target="_blank">Âò³µ</a>| <a href="http://" target="_blank">ÄÏ¿ªÇø</a>| <a href="http://" target="_blank">ÒÁͨ</a>| <a href="http://" target="_blank">¸ÊµÂÏØ</a>| <a href="http://" target="_blank">ÔÆ°²ÏØ</a>| <a href="http://" target="_blank">ÈÕÕÕÊÐ</a>| <a href="http://" target="_blank">É̶¼ÏØ</a>| <a href="http://" target="_blank">ÍпËÑ·ÏØ</a>| <a href="http://" target="_blank">̨ɽÊÐ</a>| <a href="http://" target="_blank">½ð̳ÊÐ</a>| <a href="http://" target="_blank">Óý¶ù</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>