struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)

为了之后学习的日子里加深对框架的理解和使用,这里将搭建步奏简单写一下,目的主要是方便以后自己回来脑补;

1:File--->New--->Other--->Maven--->Maven Project--->Next(之后界面如下所示:)

struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)

--->Next(点击next之后出现如下界面:选择最后一个 maven-archetype-webapp,然后点击next)

struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)

--->Next(点击next之后出现如下界面,然后选择好组织号,工程号,版本号即可),最后点击Finish

struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)

2:maven项目创建好之后会报错,这里先在pom.xml中导入jar包,导入方式如下所示:这个pom配置好之后点击保存会将jar包下载到本地仓库,这个学习maven的时候都配置过,这个自己下去脑补吧;注意第304行struts2注解配置;

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bie.maven</groupId>
<artifactId>ssh_annotation</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ssh_annotation Maven Webapp</name>
<url>http://maven.apache.org</url> <!-- 配置一下jar包 -->
<properties>
<java-version>1.8</java-version>
<junit-version>4.8.2</junit-version>
<org.springframework-version>3.2.4.RELEASE</org.springframework-version>
<jackson-mapper-asl-version>1.9.12</jackson-mapper-asl-version>
<jackson-core-asl-version>1.9.12</jackson-core-asl-version>
<mysql-connector-java-version>5.1.8</mysql-connector-java-version> <!--
<org.mybatis-version>3.2.7</org.mybatis-version>
<org.mybatis-spring-version>1.2.2</org.mybatis-spring-version>
--> <opensymphony-version>2.4.2</opensymphony-version>
<freemarker-version>2.3.9</freemarker-version>
<c3p0-version>0.9.1.2</c3p0-version>
<commons-collections-version>1.0</commons-collections-version>
<commons-fileupload-version>1.2.2</commons-fileupload-version>
<org.apache.commons-version>3.1</org.apache.commons-version>
<commons-codec-version>1.6</commons-codec-version>
<dom4j-version>1.6.1</dom4j-version>
<javax.servlet-version>1.2</javax.servlet-version>
<aspectjweaver-version>1.6.6</aspectjweaver-version>
<slf4j-log4j12-version>1.6.6</slf4j-log4j12-version>
<log4j-version>1.2.16</log4j-version>
<javax.servlet-jsp-version>2.0</javax.servlet-jsp-version>
<cglib-version>2.2.2</cglib-version>
<slf4j-api-version>1.6.6</slf4j-api-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 配置 junit4.8.2 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<type>jar</type>
</dependency>
<!-- 配置 spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument-tomcat</artifactId>
<version>${org.springframework-version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!--springmvc 转换为 Json -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson-mapper-asl-version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>${jackson-core-asl-version}</version>
</dependency>
<!--配置 freemarker -->
<dependency>
<groupId>freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>${freemarker-version}</version>
</dependency>
<!-- 配置 mybatis-spring ssh这里可以不配置mybatis-->
<!--
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${org.mybatis-version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${org.mybatis-spring-version}</version>
</dependency>
--> <!-- jdbc driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java-version}</version>
</dependency>
<!-- connect pool with c3p0 -->
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>${c3p0-version}</version>
</dependency>
<!-- apache commons jar -->
<!-- <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>${commons-collections-version}</version>
<scope>provided</scope>
</dependency> --> <dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload-version}</version>
</dependency> <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${org.apache.commons-version}</version>
</dependency> <dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec-version}</version>
</dependency>
<!-- analyze xml use dom4j -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>${dom4j-version}</version>
</dependency>
<!-- about servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${javax.servlet-version}</version>
</dependency> <dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency> <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency> <!-- memcached -->
<dependency>
<groupId>com.google.code.maven-play-plugin.spy</groupId>
<artifactId>memcached</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>${cglib-version}</version>
</dependency>
<dependency>
<groupId>net.fckeditor</groupId>
<artifactId>java-core</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20131018</version>
</dependency>
<!-- excel鎿嶄綔 -->
<!-- <dependency> <groupId>cn.liu.jxl</groupId> <artifactId>jxl</artifactId>
<version>2.6.10</version> </dependency> --> <dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>jsptags</groupId>
<artifactId>pager-taglib</artifactId>
<version>2.0</version>
</dependency> <dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.10</version>
</dependency> <dependency>
<groupId>opensymphony</groupId>
<artifactId>oscache</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency> <dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.8</version>
<exclusions>
<exclusion>
<artifactId>javassist</artifactId>
<groupId>javassist</groupId>
</exclusion>
</exclusions>
</dependency> <!-- spring和struts之间的联系 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.8</version>
</dependency> <!-- struts2的注解 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.8</version>
</dependency> <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.1.7.Final</version>
</dependency>
<dependency>
<groupId>displaytag</groupId>
<artifactId>displaytag</artifactId>
<version>1.2</version>
</dependency> </dependencies> <build>
<finalName>ssh_annotation</finalName>
</build> </project>

3:web.xml里面的dtd默认是2.3的,不过2.3的不支持el表达式,所以这里修改为2.5的。配置如下所示:

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>Archetype Created Web Application</display-name> <display-name>Archetype Created Web Application</display-name> </web-app>

4:项目配置好上面的,接下来开始写代码,首先从web.xml的配置开始,比如struts2的核心过滤器,spring核心配置文件,监听器;

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>Archetype Created Web Application</display-name> <display-name>Archetype Created Web Application</display-name> <!-- 配置spring的监听器 ,加载本地的springp配置文件-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:bean-*.xml</param-value>
</context-param> <!--
spring的监听器 spring-web-3.2.4.RELEASE.jar ==》org.springframework
==》context ==》ContextLoaderListener
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!--
struts2的核心过滤器
1:filter-class ==》 struts2-core-2.3.8.jar ==》org.apache.struts2
==》 dispatcher ==》 ng ==》filter ==》StrutsPrepareAndExecuteFilter
-->
<filter>
<filter-name>struts2Filter</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>

5:配置好之后就需要配置一下maven标准格式:在src/main下面创建一个java的文件夹,在src/下面创建一个test,在test下面创建java文件夹,配置如下所示:

struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)

6:将spring的配置文件bean-common.xml配置文件放到src/main/resources下面即可(src/main/resources也是根目录):配置如下所示:

 <?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
"> <!-- 使用注解annotation配置项目 -->
<context:annotation-config></context:annotation-config> <!-- 使用扫描组件,扫描注解 ,自动扫描某某包,扫描所有的包-->
<context:component-scan base-package="com.bie"></context:component-scan> <!-- 使用spring管理struts,使用sring管理hibernate -->
<!--
配置数据源:
1:spring-jdbc-3.2.4.RELEASE.jar==》org.springframework.jdbc
==》datasource
==》DriverManagerDataSource
-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql:///crm_ssh?characterEncoding=UTF-8"></property>
<property name="username" value="root"></property>
<property name="password" value="123456"></property>
</bean> <!--
配置数据源生成hibernate的sessionFactory
1:spring-orm-3.2.4.RELEASE.jar ==》org.springframework.orm ==》hibernate4
==LocalSessionFactoryBean
-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 引入数据源 ,hibernate可以操作数据库,使用某个数据源生成sessionFactory-->
<property name="dataSource" ref="dataSource"></property> <!-- 配置hibernate的相关配置,方言,显示sql语句等等 -->
<property name="hibernateProperties">
<props>
<!--
mysql的方言:
hibernate-core-4.1.7.Final.jar
-->
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<!-- 打印sql语句 -->
<prop key="hibernate.show_sql">true</prop>
</props>
</property> <!-- 之前开发使用的是映射文件,现在使用的是注解配置 -->
<property name="annotatedClasses">
<!-- 这是一个集合,使用list集合进行赋值 -->
<list>
<!-- 使用注解的类都需要加到这里 -->
<value>com.bie.po.User</value>
<value>com.bie.po.Dept</value>
</list>
</property>
</bean> <!--
spring采用事务管理hibernate的事务 :事务管理器:transactionManager
1:spring-orm-3.2.4.RELEASE.jar ==》org.springframework.orm ==》
hibernate4==》HibernateTransactionManager
-->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<!-- spring要管理事务,那么spring要对hibernate拥有处置权 -->
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <!-- 在配置切面 之上配置事务管理的通知:
1:事务管理的通知要使用上面的事务管理:transactionManager
-->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 配置事务的传播特性 -->
<tx:method name="find*" read-only="true"/>
<tx:method name="get*" read-only="true"/>
<tx:method name="query*" read-only="true"/> <!-- required:本操作内如果有事务,则使用事务,如果没有,则开启新的事务 -->
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice> <!--
配置切面,使用切面来管理事务
1:第一个※代表public
2:第二个※代表类
3:第三个※代表方法
4:第三个※(..)里面的..代表任意参数
-->
<aop:config>
<!-- 切入点 -->
<aop:pointcut expression="execution(* com.bie.service.impl.*.*(..))" id="transactionPointcut"></aop:pointcut> <!--
切入点应用到什么通知:
1:advice-ref:应用什么通知
2:pointcut-ref在那个切入点应用这个通知;
-->
<aop:advisor advice-ref="transactionAdvice" pointcut-ref="transactionPointcut"/>
</aop:config> </beans>

7:配置好之后开始写实体类po下面的实体类;(注解方式配置实体类,配置如下所示):

 package com.bie.po;

 import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table; /**
* @author 作者:别先生
* @version 创建时间:2017年6月8日 上午11:55:43
* 类说明
* 1:使用注解完成实体类的配置
* 2:用户对应数据库的t_user表
*/
@Entity
@Table(name = "t_user")
public class User { private Integer id;//主键编号
private String name;//姓名
private String account;//账号
private String password;//密码 //设置主键,然后设置主键自增
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="t_userId")
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
} @Column(name="t_userName")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} @Column(name="t_userAccount")
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
} @Column(name="t_userPwd")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
} }

8:配置一下struts2的配置文件,配置如下所示:

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"> <struts>
<!-- struts2-core-2.3.8.jar ==》org.apache.struts2==》default.properties --> <!-- 表示struts2的action由spring来生成 -->
<constant name="struts.objectFactory" value="spring"></constant> </struts>

9:配置好上面的验证一下,将项目加载到tomcat中,然后启动tomcat看看是否报错,我这里不报错,就不做多叙述了;

至此,ssh注解版框架就搭建成功,接下来就可以进行简单测试了......

10:测试的话,先写一个index.jsp页面,页面代码如下所示:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
//获取绝对路径路径 :路径path
String path = request.getContextPath();
//基本路径:http://localhost:8080/
String basePath = request.getScheme() +"://"
+ request.getServerName()
+":" +request.getServerPort() + path + "/";
//保存到session中
session.setAttribute("basePath", basePath);
%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath %>" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试crm</title>
</head>
<body> <a href="${basePath }user/queryById.action?userId=1">点击查看个人信息</a>
<h1>个人信息如下所示:</h1>
<ul>
<li>用户编号:${user.userId }</li>
<li>用户姓名:${user.userName }</li>
<li>用户账号:${user.userAccount }</li>
<li>用户密码:${user.userPwd }</li>
<li>用户部门:${user.dept.deptName }</li>
</ul> </body>
</html>

11:页面点击超链接之后访问到struts2的action层,下面先给出action层的代码;

 package com.bie.action;

 import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired; import com.bie.po.User;
import com.bie.service.UserInfoService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport; /**
* @author 作者:别先生
* @version 创建时间:2017年6月8日 下午4:27:30
* 类说明
*/
@ParentPackage("struts-default")
@Namespace("/user")
public class UserAction extends ActionSupport{ private static final long serialVersionUID = 1L; //自动注入到ioc容器中
@Autowired
private UserInfoService userInfoService; private int id;
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
} @Action(
value = "queryById",
results = {
@Result(name="success",location="/index.jsp")
}
)
public String queryById(){ //调用service层的方法进行查询
User user = userInfoService.queryById(id); //将查询的信息保存到session中
ActionContext.getContext().getSession().put("user", user); return "success";
} }

12:数据传输到action中,action对数据进行封装之后传到service层进行数据业务逻辑处理,这里写一下service层的代码;对service层的代码和dao层的代码先写接口,然后再写实现接口的类;

 package com.bie.service;

 import com.bie.po.User;

 /**
* @author 作者:别先生
* @version 创建时间:2017年6月8日 下午3:43:03
* 类说明
*/ public interface UserInfoService { /***
* 根据用户编号查询
* @param id
* @return
*/
public User queryById(int id);
}
 package com.bie.service.impl;

 import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import com.bie.dao.UserInfoDao;
import com.bie.po.User;
import com.bie.service.UserInfoService; /**
* @author 作者:别先生
* @version 创建时间:2017年6月8日 下午3:43:13
* 类说明
*/
@Service
public class UserInfoServiceImpl implements UserInfoService{ //自动注入到ioc容器中
@Autowired
private UserInfoDao userInfoDao; public User queryById(int id) { //直接调用dao层的方法查询之后返回到action层
return userInfoDao.queryById(id);
} }

13:数据传输到dao层之后开始和数据库里的数据表进行交互和操作;

 package com.bie.dao;

 import com.bie.po.User;

 /**
* @author 作者:别先生
* @version 创建时间:2017年6月8日 下午4:35:20
* 类说明
*/ public interface UserInfoDao { /**
* 根据用户编号进行查询
* @param userId
* @return
*/
public User queryById(int userId);
}
 package com.bie.dao.impl;

 import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository; import com.bie.dao.UserInfoDao;
import com.bie.po.User; /**
* @author 作者:别先生
* @version 创建时间:2017年6月8日 下午4:35:46
* 类说明
*/
@Repository
public class UserInfoDaoImpl implements UserInfoDao{ //自动注入到ioc容器中
@Autowired
private SessionFactory sessionFactory; public User queryById(int id) { User user = (User) sessionFactory.getCurrentSession().get(User.class, id); return user;
} }

演示效果如下所示:

struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)

struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)

ssh注解版框架搭建先到这吧,以后有机会再深学吧。时间过的挺快的,马上就该出去找工作了......

上一篇:Sicily 2005.Lovely Number


下一篇:VirtualBox添加共享文件夹