SSH框架从底层数据库到jsp页面响应流程及注意事项

SSH框架完整实现从底层到jsp页面流程及注意事项

本文主要是以后为自己留个印象,第一次完整的弄清楚ssh框架使用时的开发流程,本文主要以一个实现显示数据库中视频章节信息为例,一切从简,重在开发流程上。

函数文件的书写

注意:下面给出的函数都省略了对应接口文件的书写,请自行补充。
先给出ChapterDAO文件中的getChaptersByCourseid()函数

public List getChaptersByCourseid() {
        // TODO Auto-generated method stub
        Session session=sessionFactory.openSession();
        Transaction ts=session.beginTransaction();
        Query query=session.createQuery("from Chapter where courseid=1");
        List chapters=query.list();
        System.out.println("c");
        System.out.println(chapters);
        ts.commit();
        session.close();
        return chapters;
    }

然后到ChapterService文件中的getChaptersByCourseid()函数

public List getChaptersByCourseid() {
        // TODO Auto-generated method stub
            return chapterDAO.getChaptersByCourseid();  
    }

最后就是action文件中的browseChapter()函数

public String browseChapter() throws Exception{
        System.out.println("abc");
        List chapters = chapterService.getChaptersByCourseid();
        Map request=(Map) ActionContext.getContext().get("request");
        request.put("chapters",chapters);
        return SUCCESS;
    }

上述文件都书写完整后,比较重要的就是application文件和struts文件的书写,也就是配置的问题,这里不处理好就会有各种各样问题。

配置文件相关

application文件相关

首先,mode文件需要保证没问题,这里使用的是chapter (其他的都是多的)

<property name="mappingResources">
            <list>
                <value>com/xuan/model/User.hbm.xml</value>
                <value>com/xuan/model/Guashi.hbm.xml</value>
                <value>com/xuan/model/Catalog.hbm.xml</value>
                <value>com/xuan/model/Xuanke.hbm.xml</value>
                <value>com/xuan/model/Userdetail.hbm.xml</value>
                <value>com/xuan/model/Course.hbm.xml</value>
                <value>com/xuan/model/Zhiliaolink.hbm.xml</value>
                <value>com/xuan/model/Message.hbm.xml</value>
                <value>com/xuan/model/Zhiliao.hbm.xml</value>
                <value>com/xuan/model/Operate.hbm.xml</value>
                <value>com/xuan/model/Chapter.hbm.xml</value>
                <value>com/xuan/model/Forum.hbm.xml</value>
                <value>com/xuan/model/Reforum.hbm.xml</value>
                <value>com/xuan/model/Videoinfo.hbm.xml</value></list>
        </property></bean>

然后是以下的配置

    <bean id="chapterDAO" class="com.xuan.dao.impl.ChapterDAO">
        <property name="sessionfactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
    <bean id="chapterService" class="com.xuan.service.impl.ChapterService">
        <property name="chapterDAO" ref="chapterDAO"></property>
    </bean> 
    <bean id="courseAction" class="com.xuan.action.courseAction">
        <property name="catalogService" ref="catalogService"></property>
        <property name="courseService" ref="courseService"></property>
        <property name="chapterService" ref="chapterService"></property>
    </bean>

这里需要理解为什么这样写,这里是分别导入了dao service 以及action文件,以及他们之间的关系

Struts文件

<action name="browseChapter" class="courseAction" method="browseChapter">
<result name="success">/chapter.jsp</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>

总之,大体按照以上流程开发即可,遇到问题,不要慌乱,一般都是些很简单的问题。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值