ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
RegisterDAO registerDAO = (RegisterDAO)ac.getBean("RegisterDAO");web
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/spring.xml");
RedisTemplate redisTemplate = (RedisTemplate)context.getBean("redisTemplate");redis
若是是兩個以上:
ApplicationContext ac = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml","dao.xml"});算法
或者用通配符:spring
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:/*.xml");6.計算總頁碼數app
(totalCount + pageInfo.getLength() - 1) / pageInfo.getLength()jsp
7.分頁算法編碼
pageInfo.setStart((page-1)*pageSize);spa
8.對URL進行編碼code
URLDecoder.decode(str,"UTF-8");orm
URLEncoder.encode(str,"UTF-8");
DecimalFormat df = new DecimalFormat("####.00");
Double joinRate=new Double(df.format(temp*100));
13.Spring異常
<!-- 異常處理 -->
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="defaultErrorView" value="errorPage/systemError"/> <!-- 默認爲500,系統錯誤(error.jsp) -->
<property name="defaultStatusCode" value="500"/>
<!-- 配置多個statusCode -->
<property name="statusCodes">
<props>
<prop key="500">500</prop>
<prop key="404">404</prop>
</props>
</property>
<property name="exceptionMappings">
<props>
<!-- 這裏你能夠根據須要定義N多個錯誤異常轉發 -->
<prop key="com.Exception">errorPage/systemError</prop>
<prop key="com.alibaba.dubbo.rpc.RpcException">errorPage/netError</prop>
</props>
</property>
</bean>
public static void main(String[] args)throws Exception{ File file = new File("F:\\a.png"); String a=file.separator; System.out.println(a); String fileName=file.getName(); String prefix=fileName.substring(fileName.lastIndexOf(".")); String datePag = new SimpleDateFormat("yyyyMMdd").format(new Date()); String ctime = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()); System.out.println(ctime); System.out.println(prefix); String path="D:\\"+ctime; String pathPag="D:\\"+datePag; File data = new File(path); File dataPag = new File(pathPag); if(!dataPag.exists()) dataPag.mkdirs(); FileInputStream fis = new FileInputStream(file); byte[] b = new byte[1024]; int len = 0; FileOutputStream fos = new FileOutputStream(pathPag+"\\"+ctime+prefix); while((len=fis.read(b))!=-1){ fos.write(b,0,len); } fos.close(); fis.close();}