Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

javaÖеÄÏòÉÏתÐÍÓÐʲôÃîÓÃ?

¼ÙÈçÄãÔÚÒ»¸öÎïÁ÷ÔËÊ乫˾£¬Óиö¿Í»§ÒªÇóÄãΪËûÔËÊäÒ»¶¨ÊýÁ¿µÄ²úÆ·µ½Ä³µØ£¬Ê¹ÓÃijÖÖ½»Í¨¹¤¾ß£®ÄÇÎÒÃǼÙÉèÄãµÄ¹ÜÀí³ÌÐòÖÐÓÐTruckÀ࣬TrainÀ࣬PlaneÀàרÃÅÓÃÀ´ÊµÏÖʹÓò»Í¬½»Í¨¹¤¾ßµÄ³É±¾¼ÆË㣬¶¼Óз½·¨cost(Double weight,Double space);ÄÇô£¬ÎÊÌâ³öÀ´ÁË£®¿Í»§¶ÔÓÚÔËÊäÆ÷ÖÖÀàÊÇ¿ÉÑ¡ÔñµÄ£¬ÄãÊDz»ÊÇÒª¶ÔÿÖÖÔËÊäÆ÷new¸öʵÀý·Åµ½²»Í¬µÄservice·½·¨ÖÐΪ¿Í»§·þÎñÄØ£¿
ºÜÃ÷ÏÔÕâô×öÓкܶà´úÂëÖظ´£¬¶øÇÒЧÂÊÌ«µÍ£®ÄÇôΪʲô²»¹¹ÔìÒ»¸öÔËÊ乤¾ßµÄ¸¸Àà:
public class Conveyance{
protected weight;
protected space;
public abstract Double cost(Double weight,Double space);
}
È»ºó×ÓÀàTruck,Plane,Train·Ö±ðʵÏÖcost·½·¨
ÔÙ¹¹ÔìÒ»¸ö¹¤³§ÀàΪ¿Í»§ÖÆÔì×ÓÀàʵÀý
public class ConveyanceFactory{
public static Conveyance getConveyance(String which){
if(which.equils("Truck")){return new Truck();}
else if(which.equils("Train")){return new Train();}
else if(which.equils("Plane")){return new Plane();}
else{return null;}
}
}
·þÎñ³ÌÐòµÄ·½·¨ÊµÏÖ£º
public double transportCost(String type,Double weight,Double space){
Conveyance c;Double cost;
c = ConveyanceFactory.getConveyance("type");
cost = c.cost(weight,space);
return cost;
}
¿´ÉÏÃæ·þÎñ²ãµÄ´úÂë¶à¼òµ¥‘£¬¶øÇÒÔÚMVC²ã´Î½á¹¹Öз½·¨ºÍÀàµÄÉè¼ÆÒ²ºÍÃæÏò¶ÔÏó£®Õâ¾ÍÊÇÉÏËÜÔìÐ͸øÎÒÃÇ´øÀ´µÄºÃ´¦¿©
Õâ»Ø¾Í·½±ãÁË£¬ÐèÒªTruckµÄʱºò£¬¿Í»§Ö»Òª¸æËßÄãËûÒªÓÿ¨³µÔËÊäÔ˶àÉÙ¾àÀë¶àÔ¶£®ÄÇÒµÎñÔ±¾ÍÔÚoption°´Å¤ÀïÃæÑ¡Ôñ”¿¨³µ”ÔÚÎı¾¿òÀïÊäÈëÖØÁ¿¶àÉÙ¾àÀë¶àÔ¶£®veiw²ã°ÑÊý¾Ý´«¸øcontroler´¦Àí³ÉÎÒÃǵķþÎñ³ÌÐòÐèÒªµÄÊý¾ÝÀàÐÍ£®È»ºó·þÎñ³ÌÐò±»controlerµ÷Óã¬ÓÃtransportCost·½·¨¼ÆËã³ö³É±¾·µ»Ø¸øveiw£¬ÏÔʾ¸øÒµÎñÔ±£¬ÒµÎñÔ±¾Í¿ÉÒÔ¸æËß¿Í»§ÐèÒªÖ§¸¶¶àÉÙÇ®À²‘
¿ÉÒÔÓ¦ÓÃjavaÖеÄÉÏתÐͶÔÏó£¬ÊµÏÖjava±à³ÌµÄ¶à̬¡£
ÉÏתÐͶÔÏó²»ÊǸ¸Àà´´½¨µÄ¶ÔÏ󣬶øÊÇ×ÓÀà¶ÔÏóµÄ“¼ò»¯”״̬£¬Ëü²»¹ØÐÄ×ÓÀàÐÂÔöµÄ¹¦ÄÜ£¬Ö»¹ØÐÄ×ÓÀà¼Ì³ÐºÍÖØдµÄ¹¦ÄÜ¡£
µ±Ò»¸öÀàÓкܶà×ÓÀàʱ£¬²¢ÇÒÕâЩ×ÓÀ඼ÖØдÁ˸¸ÀàÖеÄij¸ö·½·¨¡£
µ±Ê¹ÓÃÉÏתÐͶÔÏóÔÚµ÷ÓÃÕâ¸ö·½·¨Ê±¾Í¿ÉÄܾßÓжàÖÖÐÎ̬¡£ÒòΪ²»Í¬µÄ×ÓÀàÔÚÖØд¸¸ÀàµÄ·½·¨Ê±¿ÉÄܲúÉú²»Í¬µÄÐÐΪ¡£Ò²¾ÍÊÇ˵£¬²»Í¬¶ÔÏóµÄÉÏתÐͶÔÏóµ÷ÓÃͬһ·½·¨¿ÉÄܲúÉú²»Í¬µÄÐÐΪ¡£
ÀýÈçÏÂÃæµ


Ïà¹ØÎĵµ£º

JAVAÀ¬»øÊÕ¼¯Ëã·¨µÄºËÐÄ˼Ïë

1.À¬»øÊÕ¼¯Ëã·¨µÄºËÐÄ˼Ïë
¡¡¡¡JavaÓïÑÔ½¨Á¢ÁËÀ¬»øÊÕ¼¯»úÖÆ£¬ÓÃÒÔ¸ú×ÙÕýÔÚʹÓõĶÔÏóºÍ·¢ÏÖ²¢»ØÊÕ²»ÔÙʹÓÃ(ÒýÓÃ)µÄ¶ÔÏ󡣸ûúÖÆ¿ÉÒÔÓÐЧ·À·¶¶¯Ì¬ÄÚ´æ·ÖÅäÖпÉÄÜ·¢ÉúµÄÁ½¸öΣÏÕ£ºÒòÄÚ´æÀ¬»ø¹ý¶à¶øÒý·¢µÄÄÚ´æºÄ¾¡£¬ÒÔ¼°²»Ç¡µ±µÄÄÚ´æÊÍ·ÅËùÔì³ÉµÄÄÚ´æ·Ç·¨ÒýÓá£
¡¡¡¡À¬»øÊÕ¼¯Ëã·¨µÄºËÐÄ˼ÏëÊÇ£º¶ÔÐéÄâ»ú¿ÉÓÃÄÚ´æ¿Õ¼ä£¬¼´¶Ñ¿Õ ......

JavaÄÚ²¿ÀࣨInner Class£©Ïê½â

ÖØÐÂÀ´ÈÏʶһÏÂÄÚ²¿ÀàµÄÇø±ð
1         
Static member class£¨¾²Ì¬³ÉÔ±Àࣩ
ÀàÉùÃ÷Öаüº¬“static”¹Ø¼ü×ÖµÄÄÚ²¿Àà¡£ÈçÒÔÏÂʾÀý´úÂ룬
Inner1/Inner2/Inner3/Inner4¾ÍÊÇOuterµÄËĸö¾²Ì¬³ÉÔ±Àà¡£¾²Ì¬³ÉÔ±ÀàµÄʹÓ÷½Ê½ÓëÒ»°ã¶¥²ãÀàµÄʹÓ÷½Ê½»ù±¾Ïàͬ¡£
publi ......

Java¶ÁдCSVÎļþ

CSVÎļþ¼ò½é
¶ººÅ·Ö¸ôÐÍÈ¡Öµ¸ñʽ£¨Ó¢ÎÄÈ«³ÆΪComma Separated Values£¬¼ò³ÆCSV£©£¬ÊÇÒ»ÖÖ´¿Îı¾¸ñʽ£¬ÓÃÀ´´æ´¢Êý¾Ý¡£ÔÚCSVÖУ¬Êý¾ÝµÄ×Ö¶ÎÓɶººÅ·Ö¿ª£¬³ÌÐòͨ¹ý¶ÁÈ¡ÎļþÖØд´½¨ÕýÈ·µÄ×ֶΣ¬·½·¨ÊÇÿ´ÎÓöµ½¶ººÅʱ¿ªÊ¼ÐÂÒ»¶ÎÊý¾Ý¡£
CSVÎļþÊÇÒ»¸ö¼ÆËã»úÊý¾ÝÎļþÓÃÓÚÖ´ÐÐÉóÅкÍÕæÕýµÄ×éÖ¯¹¤¾ß£¬¶ººÅ·Ö¸ôµÄÇåµ¥¡£³£³£±»ÓÃÓÚÒÆ ......

JavaÖйØÓÚpackageµÄ×ܽá

ÓÉÓÚ´ó¼Ò¶ÔpackageµÄʹÓôæÔÚÌ«¶àÀ§»ó£¬ÎÒÔÚÕâÀォ×Ô¼º¶ÔÓÚpackageµÄʹÓõÄÁìÎò½øÐÐÒ»µã×ܽ᣺
¡¡¡¡packageÖÐËù´æ·ÅµÄÎļþ
¡¡¡¡ËùÓÐÎļþ£¬²»¹ýÒ»°ã·ÖһϾͷÖÕâÈýÖÖ
¡¡¡¡1£¬java³ÌÐòÔ´Îļþ£¬À©Õ¹ÃûΪ.java¡£
¡¡¡¡2£¬±àÒëºÃµÄjavaÀàÎļþ£¬À©Õ¹ÃûΪ.class¡£
¡¡¡¡3£¬ÆäËûÎļþ£¬ÆäËûÈκÎÎļþ,Ò²³ÆΪresource
¡¡¡¡ÀýÈçͼƬ ......

GSON£¨JSON×Ö·û´®×ª»»³ÉÒ»¸öÏàµÈµÄJava¶ÔÏó£©

GsonÕâ¸öJavaÀà¿â¿ÉÒÔ°ÑJava¶ÔÏóת»»³ÉJSON£¬Ò²¿ÉÒÔ°ÑJSON×Ö·û´®×ª»»³ÉÒ»¸öÏàµÈµÄJava¶ÔÏó¡£GsonÖ§³ÖÈÎÒ⸴ÔÓJava¶ÔÏó°üÀ¨Ã»ÓÐÔ´´úÂëµÄ¶ÔÏó¡£
´úÂëÀý×Ó£º
util.DateºÍsql.Date±»×ª³É³¤ÕûÐÎÓÃÓÚÐòÁл¯´«Êä 
public class SQLDateSer
ializer implements JsonSerializer<java.sql.Date> {
public JsonElemen ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ