步驟一

成都創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)萬(wàn)榮,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專(zhuān)業(yè),歡迎來(lái)電咨詢建站服務(wù):18982081108
maven需要添加下面代碼:
[java] view plaincopy
dependency
groupidorg.springframework/groupid
artifactidspring-context-support/artifactid version${spring.version}/version
/dependency
以及
[java] view plaincopy
dependency
groupidnet.sf.ehcache/groupid
artifactidehcache/artifactid
version${ehcache.version}/version
/dependency
將最新版本放到占位符中: ${spring.version} 和 ${ehcache.version}
步驟二
在應(yīng)用程序中將以下代碼加入context.xml:
[java] view plaincopy
bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cachemanager-ref="ehcache"
bean id="ehcache" class="org.springframework.cache.ehcache. EhCacheManagerFactoryBean" p:configlocation="classpath:configuration/ehcache.xml" p:shared="true" cache:annotation-driven/cache:annotation-driven/bean/bean
步驟三
將ehcache.xml添加到類(lèi)路徑
一個(gè)基本的ehcache.xml入下:
[java] view plaincopy
ehcache xmlns:xsi="" xsi:nonamespaceschemalocation=""
diskstore path="java.io.tmpdir"
defaultcache
cache name="yourCache" maxelementsinmemory="10000" eternal="false" timetoidleseconds="1800" timetoliveseconds="1800" maxelementsondisk="10000000" diskexpirythreadintervalseconds="1800" memorystoreevictionpolicy="LRU" persistence strategy="localTempSwap" /persistence/cache
/defaultcache/diskstore/ehcache
步驟四
最后一步,使用注釋?zhuān)浅:?jiǎn)單,一行代碼:
[html] view plaincopy
@Cacheable(value = "youCache")
這個(gè)注釋可以使用任何方法,默認(rèn)情況下在緩存哈希圖中,它使用方法參數(shù)作為key。
現(xiàn)在,誰(shuí)說(shuō)Java要寫(xiě)長(zhǎng)篇的代碼?
EhCache介紹:
在這次實(shí)踐中使用了EhCache,它強(qiáng)大、高度可定制化,可以根據(jù)需要設(shè)置任何key、緩存類(lèi)型、緩存時(shí)間。最重要的是,他開(kāi)源。
package com.test;
import java.lang.reflect.Method;
//實(shí)現(xiàn)打開(kāi)瀏覽器并跳到指定網(wǎng)址的類(lèi)
public class BareBonesBrowserLaunch {
public static void openURL(String url) {
try {
browse(url);
} catch (Exception e) {
}
}
private static void browse(String url) throws Exception {
//獲取操作系統(tǒng)的名字
String osName = System.getProperty("os.name", "");
if (osName.startsWith("Mac OS")) {
//蘋(píng)果的打開(kāi)方式
Class fileMgr = Class.forName("com.apple.eio.FileManager");
Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class });
openURL.invoke(null, new Object[] { url });
} else if (osName.startsWith("Windows")) {
//windows的打開(kāi)方式。
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
} else {
// Unix or Linux的打開(kāi)方式
String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };
String browser = null;
for (int count = 0; count browsers.length browser == null; count++)
//執(zhí)行代碼,在brower有值后跳出,
//這里是如果進(jìn)程創(chuàng)建成功了,==0是表示正常結(jié)束。
if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0)
browser = browsers[count];
if (browser == null)
throw new Exception("Could not find web browser");
else
//這個(gè)值在上面已經(jīng)成功的得到了一個(gè)進(jìn)程。
Runtime.getRuntime().exec(new String[] { browser, url });
}
}
}
//主方法 測(cè)試類(lèi)
public static void main(String[] args) {
String url = "";
BareBonesBrowserLaunch.openURL(url);
}
朋友,覺(jué)得好的話,請(qǐng)采納!你的鼓勵(lì)是我學(xué)習(xí)的動(dòng)力。
簡(jiǎn)單的的計(jì)時(shí)器代碼:
public static void main(String[] args) {
System.out.println("請(qǐng)輸入第一個(gè)數(shù):");
Scanner scanner1 = new Scanner(System.in);
double input1 = Double.parseDouble(scanner1.nextLine());
System.out.println("請(qǐng)輸入符號(hào):");
Scanner scanner3 = new Scanner(System.in);
String method = scanner3.nextLine();
System.out.println("請(qǐng)輸入第二個(gè)數(shù):");
Scanner scanner2 = new Scanner(System.in);
double input2 = Double.parseDouble(scanner2.nextLine());
double result = 0;
if (method.equals("+")) {
result = input1 + input2;
System.out.println("運(yùn)行結(jié)果為:");
System.out.print(result);
}
if (method.equals("-")) {
result = input1 - input2;
System.out.println("運(yùn)行結(jié)果為:");
System.out.print(result);
}
if (method.equals("*")) {
result = input1 * input2;
System.out.println("運(yùn)行結(jié)果為:");
System.out.print(result);
}
if (method.equals("/")) {
result = input1 / input2;
System.out.println("運(yùn)行結(jié)果為:");
System.out.print(result);
} else {
System.out.println("無(wú)此運(yùn)算符");
}
}
最簡(jiǎn)單的java代碼肯定就是這個(gè)了,如下:
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是應(yīng)該是所有學(xué)java的新手看的第一個(gè)代碼了。如果是零基礎(chǔ)的新手朋友們可以來(lái)我們的java實(shí)驗(yàn)班試聽(tīng),有免費(fèi)的試聽(tīng)課程幫助學(xué)習(xí)java必備基礎(chǔ)知識(shí),有助教老師為零基礎(chǔ)的人提供個(gè)人學(xué)習(xí)方案,學(xué)習(xí)完成后有考評(píng)團(tuán)進(jìn)行專(zhuān)業(yè)測(cè)試,幫助測(cè)評(píng)學(xué)員是否適合繼續(xù)學(xué)習(xí)java,15天內(nèi)免費(fèi)幫助來(lái)報(bào)名體驗(yàn)實(shí)驗(yàn)班的新手快速入門(mén)java,更好的學(xué)習(xí)java!
文章題目:csdnjava代碼,java編程基礎(chǔ)代碼
網(wǎng)頁(yè)網(wǎng)址:http://chinadenli.net/article30/dsgedpo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站內(nèi)鏈、云服務(wù)器、網(wǎng)站維護(hù)、面包屑導(dǎo)航、App開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)