搭建ssh框架的步骤
1.创建web项目
2.导入ssh 所需要的多有jar包,到web-inf下面的lib里面
3.将导入过来的jar包都build–path一下
4.切换到myeclipse database视图中,添加链接数据库的链接
5.新建一个数据库连接:
常用数据库连接字符串:https://blog.csdn.net/qq_34137397/article/details/55548094
6.切换视图,在src下面新建一个名为org.entity的包:
7.添加hibernate,右击项目名,选择myeclipseadd HIbernaete ……
在自动创建的hibernate.cfg.xml文件中,新加两行代码,实现打印输出sql语句和格式化sql语句的功能。
true
true
8.右击项目,添加struts
9.添加spring的内容:
10.web.xml里面的内容:
<?xml version="1.0" encoding="UTF-8"?> org.springframework.web.context.ContextLoaderListener contextConfigLocation classpath:applicationContext.xml openSessionInViewFilter org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
<init-param> <param-name>flushMode</param-name> <param-value>AUTO</param-value> </init-param>
openSessionInViewFilter /* struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /* 404 /errorPage.jsp index.jsp
11.配置spring的内容,打开applicationContext.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!-- sessionFactory -->
<bean id="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="configLocation"value="classpath:hibernate.cfg.xml"></property>
</bean>
<!-- 配置事务 -->
<bean id="txManage" class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManage"><tx:attributes><tx:method name="add*" propagation="REQUIRED"/><tx:method name="save*" propagation="REQUIRED"/><tx:method name="update*" propagation="REQUIRED"/><tx:method name="del*" propagation="REQUIRED"/><tx:method name="get*" read-only="true"/><tx:method name="find*" read-only="true"/></tx:attributes>
</tx:advice><!-- 切入点 -->
<aop:config><aop:pointcut expression="execution(* org.service..*.*(..))" id="mycut"/><aop:advisor advice-ref="txAdvice" pointcut-ref="mycut"/>
</aop:config></beans>
12.切换到myeclipse database视图:(反向生成实体类)
13.右击表:
点击finish完成即可。
14.切换视图至myeclipsep perspective
15.将项目发布到tomcat中。
16.启动tomcat服务,检查控制台是否有错误(一般只要控制台中没有超链接错误,正常显示毫秒数即可)。
17.如果没有错误,将服务关掉。
18.开始根据实体类写接口,一般一个实体类对应一个Dao接口
19.在IStudentDao接口中写增删改查的抽象方法。
20.开始写Dao层的实现类,新建一个StudentDaoImpl的实现类。需要继承HibernateDaoSupport类,实现IStudentDao接口。
实现类中的代码:
public class StudentDaoImpl extends HibernateDaoSupport implements IStudentDao {
//添加
@Override
public void saveStudent(Student student) {this.getHibernateTemplate().save(student);
}
//修改
@Override
public void updateStudent(Student student) {this.getHibernateTemplate().update(student);
}
//删除
@Override
public void delStudent(Student student) {this.getHibernateTemplate().delete(student);
}
//根据编号查询
@Override
public Student getStudentById(int sid) {return this.getHibernateTemplate().get(Student.class, sid);
}
//查询全部
@Override
public List<Student> getStudentAll() {return this.getSession().createQuery("from Student").list();
}
}
21.创建Service接口,IStudentService:
IStudentService中的代码:
22.创建Service的实现类,StudentServiceImpl。
在类中先创建dao层的对象,并且需要getters和setters
StudentServiceImpl中的代码:
public class StudentServiceImpl implements IStudentService {
//创建dao层的对象,需要getter和setter
private IStudentDao studentDao;
@Override
public void saveStudent(Student student) {studentDao.saveStudent(student);
}@Override
public void updateStudent(Student student) {studentDao.updateStudent(student);
}@Override
public void delStudent(Student student) {studentDao.delStudent(student);
}@Override
public Student getStudentById(int sid) {return studentDao.getStudentById(sid);
}@Override
public List<Student> getStudentAll() {return studentDao.getStudentAll();
}/** * @author Mu Xiongxiong * @created 2020-4-30 下午2:47:37 * @return type * 个人博客:https://blog.csdn.net/qq_34137397*/public IStudentDao getStudentDao() {return studentDao;
}/** * @author Mu Xiongxiong * @created 2020-4-30 下午2:47:37 * @param studentDao * 个人博客:https://blog.csdn.net/qq_34137397*/
public void setStudentDao(IStudentDao studentDao) {this.studentDao = studentDao;
}
}
23.创建applicationContext-dao.xml文件(可以复制一份applicationContext.xml一份,对应的在改一下),代码如下:
<?xml version="1.0" encoding="UTF-8"?>
24.创建applicationContext-service.xml文件(可以复制一份applicationContext-dao.xml一份,对应的在改一下),代码如下:
<?xml version="1.0" encoding="UTF-8"?>
25.创建StudentAction类,继承ActionSupport.
StudentAction里面的代码,省略展示getters和setters的方法:
26.配置Struts.xml文件:
<?xml version="1.0" encoding="UTF-8" ?> index.jsp
27.index.jsp页面,需要将学生信息用table的形式展示出来
首先在最上面添加jstl的标签库:
<%@ taglib uri=“http://java.sun.com/jsp/jstl/core” prefix=“c” %>
写一个table表格遍历信息:
<c:forEach items="${studentList }" var="stu"><tr><td>${stu.sid }</td><td>${stu.sname}</td><td>${stu.spass }</td><td>${stu.sphone }</td><td>${stu.grade.gname }</td><td><a href="getStudentByid?sid=${stu.sid }">修改</a>|<a href="delStudent?sid=${stu.sid }">删除</a></td></tr></c:forEach></table>
学号 | 姓名 | 密码 | 电话 | 年级 | 操作 |
- 创建applicationContext-action.xml文件(可以复制一份applicationContext-dao.xml一份,对应的在改一下),代码如下:
<?xml version="1.0" encoding="UTF-8"?>
29.在applicationContext.xml中引入applicationContext-dao.xml, applicationContext-service.xml, applicationContext-action.xml文件,引入方式:
运行结果:
搭建ssh框架的步骤相关推荐
- eclipse搭建SSH框架详解
2019独角兽企业重金招聘Python工程师标准>>> SSH框架是最常用的框架之一,在搭建SSH框架的时候总有人遇到这样,那样的问题.下面我介绍一下SSH框架搭建的全过程. 第一 ...
- myeclipse搭建SSH框架
搭建SSH框架 Struts+hibernater+spring架构(myeclipse) 右击,首先加入spring,加入hibernater,再加入struts2 复制jar包(把tomcat发布 ...
- 手把手教你搭建SSH框架(Eclipse版)
作者: C you again,从事软件开发 努力在IT搬砖路上的技术小白 公众号: [C you again],分享计算机类毕业设计源码.IT技术文章.游戏源码.网页模板.程序人生等等.公众号回复 ...
- 搭建SSH框架之一(资料准备)
最近一直在使用ssh,但都是在老的框架上开发,好久没有搭建ssh的框架,最近不忙.拿来练练手. 第一节:准备工作 下载ssh相关的开发包 由于下载不是很方便,没有下载最新版本的框架开发包.就用电脑存放 ...
- IDEA搭建SSH框架
一.前言知识 SSH: spring + struts + hibernate 二.所需环境 IDEA专业版 + MySQL(Navicat/MySQL Workbench的等等) 三.创建项目 (1 ...
- 使用maven整合SSH框架详细步骤
(文章所使用的的框架为Struts2+Spring+Hibernate,项目的结构图参照文章尾部) 1.第一步:创建maven工程,在pom.xml文件中导入需要的jar包依赖: <projec ...
- Myeclipse10下搭建SSH框架(图解)Struts2.1+Spring3.0+Hibernate3.3
一.建立一个Web Project ①点击File→New→Web Project 新建一个Web工程. ②在Project Name中输入项目名ssh,在J2EE Specificatio ...
- 在eclipse中如何搭建ssh框架
第一步:创建一个叫做ssh的项目吧.勾选web.xml文件,请看如下截图. 第二步:搭建struts2环境 首先:引入struts2的包 接下来需要修改WEB-INF里面的web.xml文件 第三步: ...
- eclipse Maven搭建SSH框架
http://www.cnblogs.com/flytop/p/8707669.html 原谅我的懒惰? 转载于:https://www.cnblogs.com/dwxxem/p/8947128.ht ...
最新文章
- H264码流结构分析
- mysql 多数据源多主一从复制
- python 链表操作 优化_python---单链表的常用操作
- C# 基于 adb 控制安卓
- 2020研究生数学建模获奖名单_赞!浙商大研究生在全国研究生数学建模竞赛中喜获41个奖项...
- BNU 鸣人的查克拉
- python的作用域分别有几种_Python作用域和命名空间
- npm install 的--save-dev和--save(看过不会忘)
- Vs自带的freetextbox无法在远端使用
- Android带LOGO二维码生成
- 三星r381android+wear,三星Gear 2 成功连接非三星手机详细教程
- linux查找外接摄像头端口
- Excel学习日记:L18-CountifsSumifs函数
- Ajax传JSON对象报错:JSON parse error: Unrecognized token ‘ids‘: was expecting (‘true‘, ‘false‘ or ‘null‘);
- shell习题第15题:看数字找规律
- 发布会直播平台哪家好
- 乐高收割机器人_乐高机器人制作~~农场收割机
- 在线时间戳计算时间差
- 微信小程序开发4——利用自定义组件实现页面内容切换功能
- java类型转换的例子
热门文章
- java开发中准则怎么写_Java开发中通用的方法和准则20条
- mac vim python3_VIM学习笔记 编译源码(Compile Code)-Python
- exceptionhandler注解_SpringMVC 中 @ControllerAdvice 注解的三种使用场景!
- word List 41
- 有了Unicode为啥还需要UTF-8
- Codeforces Round #715 (Div. 2) C. The Sports Festival 区间dp
- 【PKUWC2018】随机算法【状压dp】【组合计数】
- P1446 [HNOI2008]Cards
- cf1523B. Lord of the Values
- 【学习笔记】我命由天不由我之随机化庇佑 —— 爬山法 和 模拟退火法