国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

Spring學(xué)習(xí)基礎(chǔ)---配置文件

2024-09-05 00:17:18
字體:
供稿:網(wǎng)友
1,配置文件的配置頭
<?xml version="1.0" encoding="UTF-8"?>

<!--
  - Application context definition for JPetStore’s business layer.
  - Contains bean references to the transaction manager and to the DAOs in
  - dataAccessContext-local/jta.xml (see web.xml’s "contextConfigLocation").
  -->
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
這樣寫才對

2,配置文件可以使用多個屬性文件
<!-- Configurer that replaces ${...} placeholders with values from properties files -->
 <!-- (in this case, mail and JDBC related properties) -->
 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
   <list>
    <value>WEB-INF/mail.properties</value>
    <value>WEB-INF/jdbc.properties</value>
   </list>
  </property>
 </bean>
類是框架的。
里面包含兩個屬性文件,屬性文件里都是“key=value”這種形式的。這樣配置文件里就可以使用屬性文件里的key,使用方法
${key},這樣轉(zhuǎn)移出屬性設(shè)置,維護起來比較方便。

3,定義Validator供web層使用,自定義類。
<bean id="accountValidator" class="org.springframework.samples.jpetstore.domain.logic.AccountValidator"/>
類里面使用了ValidatorUtils系統(tǒng)類來進行處理。

4,服務(wù)層的定義。
 PetStoreImpl定義在配置文件中,是自己的類。
 所有的DAO都是它的屬性,注意,DAO是interface,而不是class.
 PetStoreImpl中定義了所有的DAO接口作為屬性,定義了他們的set方法,但是沒有定義get方法。
 這樣所有的業(yè)務(wù)操作就可以不用管DAO是如何實現(xiàn)的了,而只管使用這個PetStoreImpl就好了。

 DAO都是接口這種做法與平時開發(fā)不一樣,我以前使用hibernate生成工具生成的dao都是默認好的實現(xiàn)類。
 而此處的DAO卻都是接口。他們的實現(xiàn)方法是這樣的:
 interface PetStoreFacade { } //定義所有的業(yè)務(wù)方法。
 interface AccountDao{} //定義所有帳戶的業(yè)務(wù)方法。
 interface CategoryDao{} //定義類別的業(yè)務(wù)方法。
 interface ProductDao{} //定義產(chǎn)品的業(yè)務(wù)方法。
 。。。其他DAO接口,定義自己的業(yè)務(wù)方法。
 class PetStoreImpl implements PetStoreFacade //這個類就是一個javabean,操作的都是接口。
 //定義所有DAO接口當作自己的屬性。
 //實現(xiàn)set方法
 //實現(xiàn)PetStoreFacade 定義的業(yè)務(wù)接口,實現(xiàn)的時候調(diào)用DAO接口的方法。

 如果是我自己,那么就會定義IDAO當作接口,因為hibernate插件自動生成dao類,容易混淆。
 

共4頁上一頁1234下一頁
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 溆浦县| 福清市| 宿迁市| 绥滨县| 平江县| 雷州市| 新郑市| 永年县| 家居| 洛宁县| 台前县| 平利县| 繁昌县| 宝鸡市| 龙胜| 扶余县| 新野县| 天门市| 夹江县| 长武县| 吴川市| 龙江县| 合作市| 罗平县| 德庆县| 依安县| 新营市| 镇远县| 平陆县| 敦煌市| 克什克腾旗| 博罗县| 靖远县| 双鸭山市| 资源县| 简阳市| 甘孜| 松桃| 登封市| 大化| 修文县|