【 SSH 整合】Spring、Struts、Hibernate基本整合
applicationContext.xml
<?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"
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 "> <!-- 加载db.properties文件 -->
<bean id="config" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="locations" value="classpath*:*.properties"/>
</bean> <!-- 配置配置数据库信息(替代mybatis的配置文件conf.xml) -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driver}"></property>
<property name="url" value="${url}"></property>
<property name="username" value="${username}"></property>
<property name="password" value="${password}"></property>
<property name="initialSize" value="${initialSize}"></property>
<property name="maxActive" value="${maxActive}"></property>
<property name="maxIdle" value="${maxIdle}"></property>
<property name="minIdle" value="${minIdle}"></property>
</bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!-- //加载实体类的映射文件位置及名称 -->
<property name="mappingLocations" value="classpath:k/bean/*.hbm.xml"></property>
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean> <!--事务-->
<bean id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean> <!--开启注解配置-->
<context:annotation-config/> <!--配置 action-->
<bean name="/login" class="k.action.LoginAction" scope="prototype"/>
<bean name="/employee" class="k.action.EmployeeAction" scope="prototype"/> <!--配置 Service-->
<bean name="testService" class="k.service.TestService"/>
<bean name="employeeService" class="k.service.impl.EmployeeServiceImpl"/>
<bean name="departmentService" class="k.service.impl.DepartmentServiceImpl"/> </beans>
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans>
<form-bean name="employeeForm" type="k.form.EmployeeForm">
<form-property name="id" type="java.lang.Integer"></form-property>
<form-property name="name" type="java.lang.String"></form-property>
<form-property name="password" type="java.lang.String"></form-property>
</form-bean>
</form-beans> <global-forwards>
<forward name="ok" path="/WEB-INF/jsp/ok.jsp"></forward>
<forward name="err" path="/WEB-INF/jsp/err.jsp"></forward>
</global-forwards> <action-mappings>
<action name="employeeForm" path="/login" parameter="action" type="k.action.LoginAction"
scope="request" attribute="employeeForm" input="index.jsp" validate="false">
<forward name="main" path="/WEB-INF/jsp/main.jsp"></forward>
<forward name="loginJsp" path="/WEB-INF/jsp/login.jsp"></forward>
</action>
<action name="employeeForm" path="/employee" parameter="action" type="k.action.EmployeeAction"
scope="request" attribute="employeeForm" input="index.jsp" validate="false">
<forward name="addEmployeeUI" path="/WEB-INF/jsp/addEmployeeUI.jsp"></forward>
<forward name="loginJsp" path="/WEB-INF/jsp/login.jsp"></forward>
</action>
</action-mappings> <controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor"></set-property>
</controller> </struts-config>
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 配置Hibernate的基本属性 -->
<!-- 1.数据源配置到IOC容器中 -->
<!-- 2.关联的.hbm.xml也在IOC容器配置SessionFactory实例 -->
<!-- 3.配置Hibernate的基本属性:方言,SQL显示及格式化,生成数据表的策略以及二级缓存 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="cache.use_second_level_cache">true</property>
<property name="ache.provider_class">org.hibernate.cache.internal.DefaultCacheKeysFactory</property>
<property name="generate_statistics">true</property>
</session-factory>
</hibernate-configuration>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"> <!-- spring 初始化 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
<listener-class>k.listener.StartSystemListener</listener-class>
<!--<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>-->
</listener> <!-- struts 初始化 -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping> <!-- 配置请求过滤器,编码格式设为UTF-8,避免中文乱码-->
<filter>
<filter-name>springUtf8Encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>springUtf8Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--<filter>-->
<!--<filter-name>EncodingFilter</filter-name>-->
<!--<filter-class>k.listener.EncodingFilter</filter-class>-->
<!--</filter>-->
<!--<filter-mapping>-->
<!--<filter-name>EncodingFilter</filter-name>-->
<!--<url-pattern>/*</url-pattern>-->
<!--</filter-mapping>--> <!-- 懒加载 -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 以下3项参数与log4j的配置相关 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param> <context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener> </web-app>
db.properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
username=root
password=xxxx
initialSize=20
maxActive=500
maxIdle=2
minIdle=1
log4j.properties
log4j.rootLogger=ERROR, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.conversionPattern=%5p [%t] (%F:%L) - %m%n
EmployeeAction
package k.action; import k.domain.Department;
import k.domain.Employee;
import k.form.EmployeeForm;
import k.service.DepartmentService;
import k.service.EmployeeService;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date; public class EmployeeAction extends DispatchAction { @Resource
private EmployeeService employeeService;
@Resource
private DepartmentService departmentService; public ActionForward addEmployeeUI(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
return mapping.findForward("addEmployeeUI");
} public ActionForward addEmployee(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
EmployeeForm employeeForm = (EmployeeForm) form;
Employee employee = new Employee();
employee.setName(employeeForm.getName());
employee.setEmail(employeeForm.getEmail());
employee.setSalary(employeeForm.getSalary());
employee.setPassword(employeeForm.getPassword());
employee.setGrade(employeeForm.getGrade());
employee.setHireDate(new Date());
Department department = departmentService.getDepartmentbyEmployee(Integer.parseInt(employeeForm.getDepartment_id()));
employee.setDepartment(department);
try {
employeeService.addEmployee(employee);
} catch (Exception e) {
e.printStackTrace();
return mapping.findForward("err");
}
return mapping.findForward("ok");
}
}
LoginAction
package k.action; import k.domain.Employee;
import k.form.EmployeeForm;
import k.service.EmployeeService;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class LoginAction extends DispatchAction { @Resource
private EmployeeService employeeService; public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
return mapping.findForward("loginJsp");
} public ActionForward doLogin(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
EmployeeForm employeeOld = (EmployeeForm) form;
Employee employee = new Employee(Integer.parseInt(employeeOld.getId()), employeeOld.getPassword());
employee = employeeService.checkEmployee(employee);
if (employee != null) {
request.getSession().setAttribute("employee", employee);
return mapping.findForward("main");
}
return mapping.findForward("err");
} public ActionForward loginOut(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
return super.execute(mapping, form, request, response);
}
}
Department.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="k.domain.Department" table="t_department">
<!--<cache usage="read-write"></cache>-->
<id name="id" column="id" type="java.lang.Integer">
<generator class="native"></generator>
</id>
<property name="name" column="name" type="java.lang.String" length="64"></property>
<!-- 在客户映射文件中,表示所有联系人
使用set标签表示所有联系人
set标签里面有name属性:
属性值写在客户实体类里面表示联系人的set集合名称 inverse属性默认值:false不放弃关系维护
true 表示放弃关系维护
-->
<set name="employees" inverse="true" cascade="save-update,delete">
<!-- 一对多建表,有外键
hibernate机制:双向维护外键,在一和多那一方都配置外键
column属性值:外键名称
-->
<key column="department_id"></key>
<one-to-many class="k.domain.Employee"></one-to-many>
</set>
</class>
</hibernate-mapping>
Employee.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="k.domain.Employee" table="t_employee">
<id name="id" column="id" type="java.lang.Integer">
<!-- 设置数据库表id增长策略 native:生成表id值就是主键自动增长 uuid -->
<generator class="native"></generator>
</id>
<!-- 配置其他属性和表字段对应 name属性:实体类属性名称 column属性:生成表字段名称 -->
<property name="name" column="name" type="java.lang.String" length="64"></property>
<property name="email" column="email" type="java.lang.String" length="64"></property>
<property name="hireDate" column="hireDate" type="java.util.Date"></property>
<property name="salary" column="salary" type="java.lang.Float"></property>
<property name="password" column="password" type="java.lang.String" length="64"></property>
<property name="grade" column="grade" type="java.lang.Integer" length="3"></property>
<many-to-one name="department" class="k.domain.Department" column="department_id"></many-to-one>
</class>
</hibernate-mapping>
Department
package k.domain; import java.util.Set; public class Department {
private Integer id;
private String name;
private Set<Employee> employees; public Department() {
} public Department(String name) {
this.name = name;
} public Integer getId() { return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public Set<Employee> getEmployees() {
return employees;
} public void setEmployees(Set<Employee> employees) {
this.employees = employees;
}
}
Employee
package k.domain; import java.util.Date; public class Employee {
private Integer id;
private String name;
private String email;
private Date hireDate;
private Float salary;
private String password;
private Integer grade;
private Department department;
private String department_id; public Employee(Integer id, String name) {
this.id = id;
this.name = name;
} public Employee() {
} public Employee(String name, String password, String email, Date hireDate, Float salary, Integer grade) {
this.name = name;
this.email = email;
this.hireDate = hireDate;
this.salary = salary;
this.password = password;
this.grade = grade;
} public String getDepartment_id() {
return department_id;
} public void setDepartment_id(String department_id) {
this.department_id = department_id;
} public Integer getId() { return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
} public Date getHireDate() {
return hireDate;
} public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
} public Float getSalary() {
return salary;
} public void setSalary(Float salary) {
this.salary = salary;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public Integer getGrade() {
return grade;
} public void setGrade(Integer grade) {
this.grade = grade;
} public Department getDepartment() {
return department;
} public void setDepartment(Department department) {
this.department = department;
} }
EmployeeForm
package k.form; import org.apache.struts.action.ActionForm; import java.util.Date; public class EmployeeForm extends ActionForm {
private String id;
private String name;
private String email;
private Date hireDate;
private Float salary;
private String password;
private Integer grade;
private String department_id; public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
} public Date getHireDate() {
return hireDate;
} public void setHireDate(Date hireDate) {
this.hireDate = hireDate;
} public Float getSalary() {
return salary;
} public void setSalary(Float salary) {
this.salary = salary;
} public Integer getGrade() {
return grade;
} public void setGrade(Integer grade) {
this.grade = grade;
} public String getDepartment_id() {
return department_id;
} public void setDepartment_id(String department_id) {
this.department_id = department_id;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getId() {
return id;
} public void setId(String id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} }
EncodingFilter
package k.listener; import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import java.io.IOException; public class EncodingFilter extends HttpServlet implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
FilterChain filterChain) throws IOException, ServletException {
servletRequest.setCharacterEncoding("utf-8");
servletResponse.setCharacterEncoding("utf-8");
// System.out.println("========== set utf-8 ok ==========");
filterChain.doFilter(servletRequest, servletResponse);
} @Override
public void init(FilterConfig filterConfig) throws ServletException { }
}
StartSystemListener
package k.listener; import k.util.WebHelper; import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; public class StartSystemListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
//1.将项目上下文路径(request.getContextPath())放置到application域中.
ServletContext application = sce.getServletContext();
String app_path = application.getContextPath();
application.setAttribute("APP_PATH", app_path);
System.out.println("========== APP_PATH = " + app_path);
WebHelper.setApp_Path(app_path);
} @Override
public void contextDestroyed(ServletContextEvent sce) { }
}
DepartmentServiceImpl
package k.service.impl; import k.domain.Department;
import k.domain.Employee;
import k.service.DepartmentService;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource;
import java.io.Serializable; @Transactional
public class DepartmentServiceImpl implements DepartmentService { @Resource
private SessionFactory sessionFactory; @Override
public void addDepartment(Department department) {
Session session = sessionFactory.openSession();
// Transaction transaction = session.beginTransaction();
Serializable res = session.save(department);
// transaction.commit();
} @Override
public Department getDepartmentbyEmployee(Serializable id) {
Session session = sessionFactory.openSession();
Department department = session.get(Department.class, id);
return department;
}
}
EmployeeServiceImpl
package k.service.impl; import k.domain.Department;
import k.domain.Employee;
import k.service.EmployeeService;
import org.hibernate.*;
import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List; @Transactional
public class EmployeeServiceImpl implements EmployeeService { @Resource
private SessionFactory sessionFactory; @Override
public int addEmployee(Employee e) {
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
Serializable res = session.save(e);
transaction.commit();
return (Integer) res;
} @Override
public List<Employee> getList() {
return null;
} @Override
public int updateEmployee() {
return 0;
} @Override
public int delEmployee(Serializable id) {
return 0;
} @Override
public Employee checkEmployee(Employee e) {
Session session = sessionFactory.openSession();
Query sqlQuery = session.createQuery("from k.domain.Employee c where c.id=? ");
// SQLQuery sqlQuery = session.createSQLQuery("select * from t_employee where id=?");
sqlQuery.setParameter(0, e.getId());
// Hibernate.initialize(Department.class); //显示初始化懒加载
List<Employee> list = sqlQuery.list();
if (list.size() == 1) {
// Department department = list.get(0).getDepartment();
// String s1 = department.getId() + "===3" + department.getName();
// System.out.println(department.getId() + "===3" + department.getName());
return list.get(0);
}
return null;
}
}
DepartmentService
package k.service; import k.domain.Department;
import java.io.Serializable; public interface DepartmentService {
void addDepartment(Department department); Department getDepartmentbyEmployee(Serializable id);
}
EmployeeService
package k.service; import k.domain.Employee; import java.io.Serializable;
import java.util.List; public interface EmployeeService {
int addEmployee(Employee e); List<Employee> getList(); int updateEmployee(); int delEmployee(Serializable id); Employee checkEmployee(Employee e);
}
WebHelper
package k.util; import java.util.UUID; public class WebHelper { public static String getApp_Path() {
return APP_PATH;
} public static void setApp_Path(String appPath) {
APP_PATH = appPath;
} private static String APP_PATH = ""; public static String getNewFileName(String fileName) {
int beginIndex = fileName.lastIndexOf(".");
return UUID.randomUUID().toString() + fileName.substring(beginIndex, fileName.length());
}
}
addEmployeeUI.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>添加雇员</title>
</head>
<body>
<h1>添加雇员</h1>
<form action="${APP_PATH}/employee.do?action=addEmployee" method="post">
<table>
<tr>
<td>name:</td>
<td><input type="text" name="name" value="张三4"></td>
</tr>
<tr>
<td>email:</td>
<td><input type="text" name="email" value="zhangsan@qq.com"></td>
</tr>
<tr>
<td>salary:</td>
<td><input type="text" name="salary" value="5000"></td>
</tr>
<tr>
<td>password:</td>
<td><input type="password" name="password" value="1"></td>
</tr>
<tr>
<td>grade:</td>
<td><input type="text" name="grade" value="1"></td>
</tr>
<tr>
<td>department_id:</td>
<td><select name="department_id">
<option value="1" selected>部门1</option>
</select></td>
</tr>
<tr>
<td><input type="submit" name="sub1" value="添加"></td>
<td><input type="reset" name="reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html>
login.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>管理员登录</title>
</head>
<body>
<h1>管理员登录</h1>
<form action="${APP_PATH}/login.do?action=doLogin" method="post">
<table>
<tr>
<td>id:</td>
<td><input type="text" name="id" value="1"></td>
</tr>
<tr>
<td>name:</td>
<td><input type="text" name="name" value="1哈哈"></td>
</tr>
<tr>
<td>pwd:</td>
<td><input type="password" name="password" value="1"></td>
</tr>
<tr>
<td><input type="submit" name="sub1" value="登录"></td>
<td><input type="reset" name="reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html>
main.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>登录成功</title>
</head>
<body>
<h1>登录成功</h1>
<a href="${APP_PATH}/login.do?action=login">返回登录</a>
<h2>欢迎 【${employee.name}】 您所在的部门是 【${employee.getDepartment().getName()} 】请选择您要进行的操作</h2>
<a href="${APP_PATH}/employee.do?action=addEmployeeUI">添加雇员</a> <br/>
<a href="#">显示雇员</a> <br/>
<a href="#">查询雇员</a> <br/>
<a href="#">退出系统</a> <br/>
</body>
</html>
ok.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>成功</title>
</head>
<body>
<h1>成功</h1>
<a href="#">返回继续添加</a>
<a href="#">返回主界面</a>
<a href="${APP_PATH}/login.do?action=login">返回登录</a>
</body>
</html>
err.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>操作失败</title>
</head>
<body>
<h1>操作失败</h1>
<a href="#">操作失败,返回主界面</a>
<a href="${APP_PATH}/login.do?action=login">返回登录</a>
</body>
</html>
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<jsp:forward page="WEB-INF/jsp/login.jsp"></jsp:forward>
</body>
</html>
【 SSH 整合】Spring、Struts、Hibernate基本整合的更多相关文章
- 整合spring和hibernate框架
一)整合spring和hibernate框架整合要点:(1)数据源配置在Spring的配置文件中,供Spring和Hibernate框架共同使用:(2)不再需要hibernate.hbm.xml配置文 ...
- SSH(Spring SpringMVC Hibernate)框架整合
项目说明: 使用SSH(Spring SpringMVC Hibernate)框架整合添加部门功能 项目结构 1.导入依赖jar包 <!--单测--> <dependency&g ...
- Spring+Struts2+Hibernate的整合
这篇主要采用Maven搭建Spring+Struts2+Hibernate的整合项目,复习一下SSH框架,虽然spring提供自己的MVC框架, 但是Spring也提供和其他框架的无缝整合,采用组件形 ...
- spring和hibernate的整合
阅读目录 一.概述 二.整合步骤 1.大致步骤 2.具体分析 一.概述 Spring整合Hibernate有什么好处? 1.由IOC容器来管理Hibernate的SessionFactory 2.让H ...
- SSH(Spring Struts2 Hibernate)框架整合(注解版)
案例描述:使用SSH整合框架实现部门的添加功能 工程: Maven 数据库:Oracle 框架:Spring Struts2 Hibernate 案例架构: 1.依赖jar包 pom.xml < ...
- SSH(Spring Struts2 Hibernate)框架整合(xml版)
案例描述:使用SSH整合框架实现部门的添加功能 工程: Maven 数据库:Oracle 案例架构: 1.依赖jar包pom.xml <project xmlns="http://ma ...
- Spring+Struts2+Hibernate框架整合流程
一:基本步骤 新建Maven项目,导入相关依赖(推荐) 在WEB-INF的web.xml中进行配置 ————–Hibernate配置 —————- 创建entity包,创建数据库相关实体类 根据实体类 ...
- Spring 和 Hibernate的整合
问题 ,spring 和 hibernate 整合 如何整合 1. Spring 使用Hibernate的的SessionFactory 2. Hibernate使用Spring提供的声明式事务
- 【spring 6】Spring和Hibernate的整合:编程式事务
一.编程式事务简介 在 Spring 出现以前,编程式事务管理对基于 POJO 的应用来说是唯一选择.用过 Hibernate 的人都知道,我们需要在代码中显式调用beginTransaction() ...
- Spring+Struts+Hibernate 简介(转)
http://blog.csdn.net/slnqnd/article/details/1772910/ Struts2.0 +Hibernate 3.2 +Spring 2.0 一. ...
随机推荐
- vue.js 的cdn 链接的引用地址
引用地址有两种一种完整版,一种压缩版效果是一样的 https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js https://cdn.bootcss.com ...
- Proxy SwitchyOmega 使用黑名单和白名单
“黑名单”会告诉代理工具,黑名单(国外)里面的网站要使用代理:“白名单”会告诉代理工具,白名单(大陆网站)里面的网站直接连接,其余使用代理. 黑名单PAC 黑名单PAC两条(任选其一):https:/ ...
- 使用VSCode创建简单的Razor Webapp--1.入门
1.下载vscode,安装dotnet core sdk 在cmd中使用命令dotnet --version可以查看当前安装的版本 2.打开vscode,设置语言和扩展 在最左边的工具栏,点击最下面的 ...
- abp demo运行1
1.从官方网站下载demo 如下: https://aspnetboilerplate.com/Templates 填写响应的信息,下载demo 2.vs2017打开demo,如下图: 3.安装.ne ...
- PP: Toeplitz Inverse Covariance-Based Clustering of Multivariate Time Series Data
From: Stanford University; Jure Leskovec, citation 6w+; Problem: subsequence clustering. Challenging ...
- 一步步教你如何在Ubuntu虚拟机中安装QEMU并模拟模拟arm 开发环境(一)uImage u-boot(转)
初次接触qemu是因为工作的需要,有时候下了班,可能需要在家研究一些东西,因为博主用到arm环境,这时候博主比较小气,不愿花钱买开发板,当然博主在这里给大家的建议是,如果要真正学懂arm构架的相关知识 ...
- S3C2440的时钟原理
Crystal 无源晶体Oscillator 有源晶体(里面有有源器件) 无源晶振内只有一片按一定轴向切割的石英晶体薄片,供接入运放(或微处理器的XTAL端) 以形成振荡.有源晶振内带运放,工作在最佳 ...
- asm相关内容想下载(包括 jar 包)
网址:http://download.forge.ow2.org/asm/
- jsp报错java.io.IOException: Stream closed
在使用jsp的时候莫名其妙的抛出了这个异常,经过反复检查 去掉了网友们说的jsp使用流未关闭,以及tomcat版本冲突等原因,最后发现是书写格式的原因. 当时使用的代码如下 <jsp:inclu ...
- SpringBoot学习- 7、问题Could not autowire. No beans of 'xxxx' type found处理
SpringBoot学习足迹 这个问题网上有好多同学都提到这个问题,代码可以运行,但是就是有红线,强迫症不能忍 自己试验下 1.增加一个final编译一下,再删掉就不会出红线了 public clas ...