บทความ

กำลังแสดงโพสต์จาก เมษายน, 2012

Spring Framework กับการใช้งาน config file ด้วย PropertyPlaceholderConfigurer

บทความเกี่ยวกับ : Spring Framework กับการใช้งาน config file ด้วย PropertyPlaceholderConfigurer บางงานผมจำเป็นต้องมีการเก็บค่าบางอย่างลงใน Properties file เพื่อเป็น Configuration ไว้ใช้งานในระบบ วิธีการของผมคือ ผมจะวางไฟล์ นี้ไว้ใน Class Path หรือ หัอง SRC จากนั้นทำกาน Load file นี้ขึ้นมาใช้ได้ด้วย PropertyPlaceholderConfigurer  ตามตัวอย่าง     <!-- Spring properties file config -->     <bean name="propertyPlaceholder"         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">         <property name="locations">             <list>                 <value>classpath*:db.properties</value>             </list>         </property>     </bean> จากตัวอย่าง ผมมีไฟล์ชื่อว่า db.properties วางไว้ใน class path สาเหตุที่วางไว้ในนี้เพราะจะได้ไม่ต้องระบุ Path ให้ยุ่งยากจากนั้นเวลาใช้ก็แค่เรียกใช้งานตาม tag ดังนี้     <bean id="dataSource"           class=&qu

Java Date Format จัดรูปแบบวันที่ด้วย SimpleDateFormat

บทความเกี่ยวกับ : Java Date Format จัดรูปแบบวันที่ด้วย SimpleDateFormat วันนี้จะมานำเสนอวิธีการจัด Format Date ด้วยรูปแบบต่างๆ ผ่าน Class ที่มีชื่อว่า java.text.SimpleDateFormat มาดูตัวอย่างกันเลยครับ         Date date=new Date();         System.out.println("No format :"+date);         java.text.SimpleDateFormat df= new java.text.SimpleDateFormat();         System.out.println("No pattern format :"+df.format(date));         df.applyPattern("dd/mm/yyyy");         System.out.println("dd/mm/yyyy format :"+df.format(date));         df.applyPattern("dd/mm/yyyy HH:mm:ss");         System.out.println("dd/mm/yyyy HH:mm:ss format :"+df.format(date)); จากตัวอย่างข้างต้นผลการ Run ออกมาได้ตามนี้ No format :Thu Apr 05 16:29:18 ICT 2012 No pattern format :5/4/2555, 16:29 น. dd/mm/yyyy format :05/29/2555 dd/mm/yyyy HH:mm:ss format :05/29/2555 16:29:18 ลองนำไปประยุกต์ใช้งานได้ครับ ไม่ยากๆ