赞
踩
首先在项目的pom.xml中加入SSH所需要的配置
<!-- 完成SSH所需要的依赖及配置 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <!-- servelet的核心依赖 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> <scope>provided</scope> </dependency> <!-- hibernate框架 --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.2.10.Final</version> </dependency> <!-- 引入Spring核心库 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.10.RELEASE</version> </dependency> <!-- MySQL --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.35</version> </dependency> <!-- 引入c3p0数据库连接池 --> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> </dependency> <!-- Spring整合Hibernate依赖 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>4.3.10.RELEASE</version> </dependency> <!-- spring 的AspectJ依赖,解析事务切点 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>4.3.10.RELEASE</version> </dependency> <!-- 引入struts2依赖 --> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.3.33</version> </dependency> <!-- struts2整合Spring的整合包 --> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-spring-plugin</artifactId> <version>2.5.12</version> </dependency> <!-- log4j日志 --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.8.2</version> </dependency>
StudentDao里面的内容
public interface StudentDao { //添加 public void add(Student stu); //查 public List<Student> select(); //刪除 public void delete(Student stu); //修改 public void update(Student stu); //根據id查詢 public Student byid(Student stu); }
studentdao的实现类StudentDaoImp
//定义一个sessionFactory
private SessionFactory factory;
public void add(Student stu) {
factory.getCurrentSession().save(stu)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。