SSH框架从底层数据库到jsp页面响应流程及注意事项
2016-05-19 20:08
344 查看
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>
总之,大体按照以上流程开发即可,遇到问题,不要慌乱,一般都是些很简单的问题。
相关文章推荐
- CDH5中spark写mysql报“Did not find registered driver with class com.mysql.jdbc.Driver”错误原因
- 数据定义未来——2016数据库技术大会总结
- 数据库--ORCAL-day03
- sql 比模糊查询速度快的查询方法
- CursorAdpater 从数据库中加载数据
- mysql并发插入
- redis数据类型设计和实现(之二)链表
- MONGODB范围查询
- mysql修改密码
- MyBatis-generator使用,为Example添加分页
- SQLite数据库简介
- MySQL 索引原理及慢查询优化
- COALESCE函数
- MONGODB显示漂亮,关系查询,逻辑运算
- Pgsql数据库jsonb操作函数集合
- 终于搞定了一个C#的聊天室 使用的SQLServer+VS 用的Socket 整理下搜的书签
- GreenDao数据库简单使用
- mysql %s 模糊查询的问题
- 搭建高可用mongodb集群(二)—— 副本集
- Mysql五种时间格式