<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    西沙璞玉
    愛不容易
    posts - 0,comments - 4,trackbacks - 0

    --

    項目基本架構 ext+action+service+dao+josn



    1,action


    spring<bean id="LoginAction"
    class="com.htsoft.oa.action.system.LoginAction"
    scope="prototype"/>


    struts <action name="login"
    class="LoginAction" method="login">


    classbean id相同


    下面是注入的service


    struts @Resource


    private
    AppUserService userService;
    (這個userService找不到對應的bean id,其實沒有對應關系,注解標簽會自動注入類型為AppUserServiceBean,根據實現類可以找到)

    @Resource(注解方式注入,默認是type類型相同,也可以用name=“”與 bean id 對應)



    private
    SysConfigService sysConfigService;


    spring




    <bean id="appUserService" class="com.htsoft.oa.service.system.impl.AppUserServiceImpl"> <constructor-arg index="0"ref="appUserDao"/></bean>




    <bean id="sysConfigService"class="com.htsoft.oa.service.system.impl.SysConfigServiceImpl"><constructor-arg index="0"ref="sysConfigDao"/>


    </bean>



    2service



    spring <beanid="appUserService"class="com.htsoft.oa.service.system.impl.AppUserServiceImpl">


    <constructor-arg index="0" ref="appUserDao"/> (構造器注入,多個參數從0開始)

    </bean>



    <bean id="indexDisplayService"class="com.htsoft.oa.service.system.impl.IndexDisplayServiceImpl">



    <constructor-arg index="0" ref="indexDisplayDao"/>

    </bean>

    <bean id="appRoleService"class="com.htsoft.oa.service.system.impl.AppRoleServiceImpl">


    <constructor-arg
    index="0" ref="appRoleDao"/>
    </bean>



    struts



    @Resource



    IndexDisplayService
    indexDisplayService;


    @Resource



    AppRoleService
    appRoleService;


    public AppUserServiceImpl(AppUserDao dao) {

    super(dao);

    this.dao
    = dao;


    }



    3dao



    spring


    <bean id="appUserDao"
    class="com.htsoft.oa.dao.system.impl.AppUserDaoImpl"
    parent="baseDao"/>

    parent

    表示繼承的父類如果有很多繼承同一個父類的BEAN


    那么在配置文件中實例那些BEAN時候可以省略掉父類已經注入的屬性


    bean定義繼承父bean定義,它可以覆蓋父bean的一些值,或者它需要的值。


    那么在配置文件中實例那些BEAN時候可以省略掉父類已經注入的屬性

    <bean id="baseDao"
    abstract="true" class="com.htsoft.core.dao.impl.BaseDaoImpl"
    parent="genericDao"/>



    <bean id="genericDao"
    abstract="true"
    class="com.htsoft.core.dao.impl.GenericDaoImpl">



    <property
    name="jdbcTemplate" ref="jdbcTemplate"/>(getter
    setter方式注入)


    <property name="sessionFactory"
    ref="sessionFactory"/>



    </bean>

    abstract="true" 抽象bean,作為父類 ,子類bean parent



    app-resources.xml



    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">

    <property name="dataSource" ref="dataSource"/>

    </bean>


    struts



    GennericDaoImpl.java 這個類選用了springjdbcTemplate連接數據庫


    protected JdbcTemplate jdbcTemplate;





    (jdbcTemplatebean id 相對應)



    public
    void setJdbcTemplate(JdbcTemplate jdbcTemplate) {



    this.jdbcTemplate
    = jdbcTemplate;



    }





    public
    void setPersistType(Class persistType) {



    this.persistType
    = persistType;



    }





    用注解標簽,看不到依賴關系,沒有顯示注入明了



    /////////////////////////////////////////////////////////////////////////////



    獲取系統配置的bean 這里的sysConfigService是個bean id的名字 (目錄查找方式)





    private static ApplicationContext
    appContext;



    下面的getBean封裝了這個appContext.getBean(beanId)這個可以獲得bean實例





    public
    void setApplicationContext(ApplicationContext applicationContext) throws
    BeansException {



    this.appContext=applicationContext;



    }





    public static void reloadSysConfig(){



    //configMap.clear();



    SysConfigService
    sysConfigService=(SysConfigService)getBean("sysConfigService");



    List<SysConfig>
    list=sysConfigService.getAll();



    for(SysConfig
    conf:list){



    configMap.put(conf.getConfigKey(),conf.getDataValue());



    }



    }



    //////////////////////////////////////////



    <action name="*SalesChance"
    class="SalesChanceAction" method="{1}">



    <result>${successResultValue}</result>



    <result
    name="input">/error.jsp </result>



    *號是通配符,就是說這個actionname為任意名稱。而class中的{1}是取第一個通配符的值。



    ${successResultValue}BaseAction.java



    private String
    successResultValue="/jsonString.jsp";
    成功跳轉頁面





    jsonString.jsp頁面
    <s:property value="jsonString" escape="false" />









    action到返回頁面的配置:



    <action name="*SalesChance"
    class="SalesChanceAction" method="{1}">



    <result>${successResultValue}</result>



    <result
    name="input">/error.jsp </result>



    *號是通配符,就是說這個actionname為任意名稱。而class中的{1}是取第一個通配符的值。



    ${successResultValue}



    BaseAction.java



    private String
    successResultValue="/jsonString.jsp";
    成功跳轉頁面





    jsonString.jsp頁面



    <s:if test="#request.isExport==null
    || #request.isExport==false"
    >



    <s:property value="jsonString" escape="false" />



    </s:if>





    protected String jsonString=JSON_SUCCESS;



    public static final String JSON_SUCCESS="{success:true}";





    具體action



    msg.append(",failure:true}");



    setJsonString(msg.toString());



    jsonString="{success:false,msg:'該用戶賬號不存在!'}";





    setJsonString(msg.toString());



    從這里重新設置json



    Gson
    是 Google 提供的用來在 Java 對象和 JSON 數據之間進行映射的 Java 類庫。可以將一個 JSON 字符串轉成一個 Java 對象,或者反過來。



    /**



    * 顯示詳細信息



    * @return



    */



    public String get(){



    AppRole appRole=appRoleService.get(roleId);



    Gson gson=new
    GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();



    //將數據轉成JSON格式



    StringBuffer sb = new StringBuffer("{success:true,data:");



    sb.append(gson.toJson(appRole));



    sb.append("}");



    setJsonString(sb.toString());





    return SUCCESS;



    }









    posted on 2012-05-04 13:50 @趙 閱讀(394) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    哥哥最近不是很忙
    主站蜘蛛池模板: 亚洲综合视频在线| 亚洲乱码中文字幕综合| 亚洲电影中文字幕| yellow视频免费看| 免费中文字幕在线| 九九久久精品国产免费看小说| 国产成人啪精品视频免费网| 午夜亚洲国产理论片二级港台二级| 免费特级黄毛片在线成人观看| 国产精品无码亚洲一区二区三区| 高清永久免费观看| 国产AV无码专区亚洲AWWW| aa毛片免费全部播放完整| 亚洲精品无码Av人在线观看国产| 无码精品人妻一区二区三区免费看| 久久久久久亚洲精品| 日本高清在线免费| 亚洲精品色播一区二区 | 亚洲精品无码人妻无码| 成人免费午间影院在线观看| 亚洲JIZZJIZZ妇女| 亚洲不卡无码av中文字幕| 久久久久国色AV免费观看| 亚洲精品福利视频| 大地资源二在线观看免费高清| 亚洲hairy多毛pics大全| 爱情岛论坛网亚洲品质自拍| 未满十八18禁止免费无码网站| 亚洲剧场午夜在线观看| 免费看国产曰批40分钟| 色www永久免费| 亚洲日产乱码一二三区别| 亚洲精品无码日韩国产不卡?V| 久久精品免费一区二区三区| 亚洲国产成人91精品| 九月婷婷亚洲综合在线| 亚洲人成日本在线观看| 全部免费毛片免费播放| 久久青草免费91线频观看不卡| 亚洲AV无码专区在线亚| 在线观看午夜亚洲一区|