通過(guò)spring用beanshell實(shí)現(xiàn)java接口示例
說(shuō)明
1.通過(guò)腳本語(yǔ)言讓JAVA執(zhí)行動(dòng)態(tài)代碼
2.用Spring可以將腳本語(yǔ)言代理成Java接口的實(shí)現(xiàn)類
3.Spring2.5.6中支持三種腳本語(yǔ)言ruby,Groovy,BeanShell
4.示例中為spring與beanshell結(jié)合
5.依賴spring2.5.6,bsh-2.0b4
import org.junit.Test;
import org.springframework.scripting.bsh.BshScriptUtils;
import bsh.EvalError;
public class TestBeanShell {
@Test
public void testShell() {
String srciptText = "say(name){ return \"hello,\"+name;}";
SayHello sh;
try {
sh = (SayHello) BshScriptUtils.createBshObject(srciptText, new Class[] { SayHello.class });
String res=sh.say("vidy");
System.out.println(res);
} catch (EvalError e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
interface SayHello {
public String say(String name);
}
相關(guān)文章
實(shí)例講解JSP獲取ResultSet結(jié)果集中的數(shù)據(jù)的方法
這篇文章主要介紹了JSP獲取ResultSet結(jié)果集中數(shù)據(jù)的方法,文后還介紹一種遍歷ResultSet中的數(shù)據(jù)并轉(zhuǎn)化為表格的方法,需要的朋友可以參考下2016-04-04
jsp讀取數(shù)據(jù)庫(kù)實(shí)現(xiàn)分頁(yè)技術(shù)簡(jiǎn)析
這篇文章介紹的是用javabean和jsp頁(yè)面來(lái)實(shí)現(xiàn)數(shù)據(jù)的分頁(yè)顯示,例子中所使用的數(shù)據(jù)庫(kù)是Mysql,需要的朋友可以了解下2012-11-11
web開發(fā)中添加數(shù)據(jù)源實(shí)現(xiàn)思路
這篇文章主要介紹了 web開發(fā)中添加數(shù)據(jù)源實(shí)現(xiàn)思路的相關(guān)資料,需要的朋友可以參考下2017-04-04

