2012年1月31日 星期二

javascript 畫三角形

許久不見的三角形
for(var i=0;i<10;i++){
for(var d=0;d < 10-i;d++){
document.write(" ");
}
for(var k=0;k<2*i-1;k++){
document.write("★");
}

document.write("<br/>");

}
var c=2
for(var i=9;i>0;i--){

for(var k=0;k<c;k++){
document.write(" ");
}
for(var k=0;k<2*i-3;k++){
document.write("☆");
}
c++;
document.write("<br/>");
}

2012年1月18日 星期三

Ibatis+Spirng配置

1.properties //dblink實際參數
 
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:專案目錄/spring.properties" />
</bean>

2.dblink 配合properties

<bean id="testDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${test_driverClassName}" />
<property name="url" value="${test_url}" />
<property name="username" value="${test_username}" />
<property name="password" value="${test_password}" />
<property name="testWhileIdle" value="true"/>
<property name="validationQuery" value="select 1 from dual"/>
<property name="logAbandoned" value="true"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="3600"/>
<property name="maxWait" value="20"/>
<property name="maxIdle" value="10"/>
<property name="maxActive" value="-1"/>
<property name="accessToUnderlyingConnectionAllowed" value="true"/>
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
lazy-init="true" />
<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
<property name="nativeJdbcExtractor">
<ref local="nativeJdbcExtractor" />
</property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="testDataSource"/>
</bean>

3.讀取sqlmapconfig


<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation">
<value>classpath:專案目錄/SqlMapConfig.xml</value>
</property>
<property name="transactionConfigProperties">
<props>
<prop key="DefaultAutoCommit">false</prop>
</props>
</property>
<property name="lobHandler">
<ref local="oracleLobHandler" />
</property>
</bean>

4.java 讀取dao
  
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClient" />
<property name="exceptionTranslator">
<bean class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
<property name="dataSource" ref="dataSource" />
</bean>
</property>
</bean>
<bean id="ibatisDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="target">
<ref bean="baseIbatisDao"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>

String prototype

網路上找到對於prototype的定義、以下是我從字面翻過來的
"javascript既有對像都只有讀的prototype屬性。
只能為原型添加功能,但不能被賦予不同的原型。
但是定義的對象可以被賦給新的原型。"

常用如下:
String.prototype.trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
// 全部取代指定字串
String.prototype.replaceAll = function (str1,str2) {
return this.replace(new RegExp(str1,"gm"),str2);
};

// 移除Array指定筆數
Array.prototype.remove = function (i) {
return this.splice(i,1);
};

JavaScript String 多種用法

以下這些在coding的過程滿常需要用到、在這裡做個紀錄
string data="test"
data.******()
.toString()
.length
.charAt()
.lastIndexOf()
.indexof()
.replace()
.split()
.slice(start(略),end((略)) //截斷取出
.fontcolor("Red")
.toLowerCase()
.toUpperCase()
.sub()//上標
.sup() //下標
.link("www.google.com")
.big()
.small()
.bold()
.italics()
.strike()

11.7k Rec

微風運河一圈3.91k
Round 1 22:32.69
Round 2 23:52.64
Round 3 24:50.21
Total time 1:11:15.56

2012年1月13日 星期五

Ireport 中文粗體

將要顯示粗體的中文字(kaiu.ttf)的字體改 Arial Narrow、則在ireport中勾選粗體才有作用
Map fontsMap = new HashMap ();
fontsMap.put(new FontKey("Arial Narrow", true, false),
new PdfFont(dir+File.separator+"kaiu.ttf", "Identity-H", true, true, false));
fontsMap.put(new FontKey("標楷體", true, false),
new PdfFont(dir+File.separator+"kaiu.ttf", "Identity-H", true, false, false));//設置字體樣式
exporter.setParameter(JRExporterParameter.FONT_MAP, fontsMap);

2012年1月12日 星期四

ireport [sub report]

1.讀取mainReport
JasperReport jasperReport = JasperCompileManager.compileReport("C:\\Temp\\report2.jrxml");
2.先將sub.jasper讀進來、存放至主要的HashMap mapParameter = new HashMap();
InputStream stream1 = getRequest().getSession().getServletContext().getResourceAsStream("xxxxxxxx_subreport_Net.jasper");
JasperReport netReport = (JasperReport) JRLoader.loadObject(stream1);
//map key 對應subReport Name
mapParameter.put("NET_REPORT", netReport);
3.subReport 資料型態 JRMapCollectionDataSource(ArrayList<HashMap>)<
在此命 NetProduct>後續irport會用
放置mapParameter.put("Report_Net_list", NetProduct());
4.JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, a,new JREmptyDataSource());
new JREmptyDataSource也是實作implements JRDataSource 、
如果沒有JRDataSource、null值必需塞new JREmptyDataSource不能放置null或空值

5.iReport設置
(1)新增(NET_REPORT)parameter:net.sf.jasperreports.engine.JasperReport
用意在於java先讀取jaxml或jasper檔在傳給ireport
(2)新增(Report_Net_list)Parameter:net.sf.jasperreports.engine.data.JRMapCollectionDataSource
(2)Expression class :net.sf.jasperreports.engine.JasperReport
Data Source Expression:放置之前java設置的Report_Net_list( JRMapCollectionDataSource)
附上test Code &JAR檔



jQuery ajax方式

var params = {
keyValue : '對應GetDateTagKey',
inputValue : '輸入值'};
var url = '../tag/getDataTag.action';
jQuery.ajax({
type:"POST",
dataType:"json",
async:false, // true:異步,false:同步
url:url,//目標url
data:params,//也可綁定action
beforeSend:function(){},//送出前執行
success:function(json){
var data = eval(json);
if(data != null){
custType.options.length = 0;
for(var i = 0 ; i < data.length ; i++){
custType.options[i] = new Option(data[i].dscr, data[i].lookup_code);
}
}else{
alert("取得失敗");
}
},
error:function(){
alert("取得異常");
}
});