SSH整合(二)

本次整合基于上篇SSH整合的博客上写的:

链接: https://blog.csdn.net/weixin_45180769/article/details/99677704

User模块

User实体类

package com.ningjie.user.entity;

import com.ningjie.base.entity.BaseEntity;

public class User extends BaseEntity {

	private static final long serialVersionUID = 6566515100091330894L;
	
	private String uname;
	private String upwd;
	public String getUname() {
		return uname;
	}
	public void setUname(String uname) {
		this.uname = uname;
	}
	public String getUpwd() {
		return upwd;
	}
	public void setUpwd(String upwd) {
		this.upwd = upwd;
	}
	public User(String uname, String upwd) {
		super();
		this.uname = uname;
		this.upwd = upwd;
	}
	public User() {
		super();
	}
	@Override
	public String toString() {
		return "User [uname=" + uname + ", upwd=" + upwd + "]";
	}

}

User实体类的映射文件User.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 table="t_vue_user" name="com.ningjie.user.entity.User">
		<id name="uname" type="java.lang.String" column="uname"></id>
		
		<property name="upwd" type="java.lang.String" column="pwd"></property>
	</class>
</hibernate-mapping>
 

实体类TreeNode

package com.ningjie.user.entity;

import com.ningjie.base.entity.BaseEntity;



public class TreeNode extends BaseEntity {

	private static final long serialVersionUID = 3404051699954127467L;
	
	private int treenodeid;
	private String treenodename;
	private int treenodetype;
	private int parentnodeid;
	private String url;
	private int position;
	private String icon;
	public int getTreenodeid() {
		return treenodeid;
	}
	public void setTreenodeid(int treenodeid) {
		this.treenodeid = treenodeid;
	}
	public String getTreenodename() {
		return treenodename;
	}
	public void setTreenodename(String treenodename) {
		this.treenodename = treenodename;
	}
	public int getTreenodetype() {
		return treenodetype;
	}
	public void setTreenodetype(int treenodetype) {
		this.treenodetype = treenodetype;
	}
	public int getParentnodeid() {
		return parentnodeid;
	}
	public void setParentnodeid(int parentnodeid) {
		this.parentnodeid = parentnodeid;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public int getPosition() {
		return position;
	}
	public void setPosition(int position) {
		this.position = position;
	}
	public String getIcon() {
		return icon;
	}
	public void setIcon(String icon) {
		this.icon = icon;
	}
	public TreeNode(int treenodeid, String treenodename, int treenodetype, int parentnodeid, String url, int position,
			String icon) {
		super();
		this.treenodeid = treenodeid;
		this.treenodename = treenodename;
		this.treenodetype = treenodetype;
		this.parentnodeid = parentnodeid;
		this.url = url;
		this.position = position;
		this.icon = icon;
	}
	public TreeNode() {
		super();
	}
	@Override
	public String toString() {
		return "TreeNode [treenodeid=" + treenodeid + ", treenodename=" + treenodename + ", treenodetype="
				+ treenodetype + ", parentnodeid=" + parentnodeid + ", url=" + url + ", position=" + position
				+ ", icon=" + icon + "]";
	}
}

实体类TreeNode的映射文件TreeNode.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 table="t_vue_tree_node" name="com.ningjie.user.entity.TreeNode">
		<id name="treenodeid" type="java.lang.Integer" column="tree_node_id">
			<generator class="increment"></generator>
		</id>
		
		<property name="treenodename" type="java.lang.String" column="tree_node_name"></property>
		<property name="treenodetype" type="java.lang.Integer" column="tree_node_type"></property>
		<property name="parentnodeid" type="java.lang.Integer" column="parent_node_id"></property>
		<property name="url" type="java.lang.String" column="url"></property>
		<property name="position" type="java.lang.Integer" column="position"></property>
		<property name="icon" type="java.lang.String" column="icon"></property>
	</class>
</hibernate-mapping>

UserBiz

package com.ningjie.user.biz;

import java.util.List;

import com.ningjie.user.entity.TreeNode;
import com.ningjie.user.entity.User;


public interface UserBiz {
	public List<User> list(User user);
	public int add(User user);
	public List<TreeNode> listNode();

}


UserBizImpl

package com.ningjie.user.biz.impl;

import java.util.List;

import com.ningjie.user.biz.UserBiz;
import com.ningjie.user.dao.UserDao;
import com.ningjie.user.entity.TreeNode;
import com.ningjie.user.entity.User;


public class UserBizImpl implements UserBiz {
	
	private UserDao userDao ;
	
	
	

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	@Override
	public List<User> list(User user) {
		return userDao.list(user);
	}

	@Override
	public int add(User user) {
		// TODO Auto-generated method stub
		return userDao.add(user);
	}

	@Override
	public List<TreeNode> listNode() {
		// TODO Auto-generated method stub
		return userDao.listNode();
	}

}

UserDao

package com.ningjie.user.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.query.Query;
import org.springframework.orm.hibernate5.HibernateCallback;

import com.ningjie.base.dao.BaseDao;
import com.ningjie.base.util.StringUtils;
import com.ningjie.user.entity.TreeNode;
import com.ningjie.user.entity.User;


public class UserDao extends BaseDao {

	private static final long serialVersionUID = -1213415622340269960L;
	
	public List<User> list(User user){
		
		return this.getHibernateTemplate().execute(new HibernateCallback<List<User>>() {

			@Override
			public List<User> doInHibernate(Session arg0) throws HibernateException {
				Query query = arg0.createQuery("from User");
				String uname = user.getUname();
				String upwd = user.getUpwd();
				if(StringUtils.isNotBlank(uname)&& StringUtils.isNotBlank(upwd)) {
						 query = arg0.createQuery("from User where uname = :uname and upwd = :upwd ");
						 query.setParameter("uname", uname);
						 query.setParameter("upwd", upwd);
				}
				return query.list();
			}
		});
	}
	
	public int add(User user) {
		Serializable a = this.getHibernateTemplate().save(user);
		int n = 0;
		if(StringUtils.isNotBlank(a+"")) {
			n=1;
		}
		return  n;
	}
	
	public List<TreeNode> listNode(){
		
		return this.getHibernateTemplate().execute(new HibernateCallback<List<TreeNode>>() {

			@Override
			public List<TreeNode> doInHibernate(Session session) throws HibernateException {
				return session.createQuery("from TreeNode").list();
			}
		});
	}
	
	

}

UserAction

package com.ningjie.user.web;

import java.util.List;

import com.ningjie.base.web.BaseAction;
import com.ningjie.user.biz.UserBiz;
import com.ningjie.user.entity.TreeNode;
import com.ningjie.user.entity.User;
import com.opensymphony.xwork2.ModelDriven;

public class UserAction extends BaseAction implements ModelDriven<User> {

	private static final long serialVersionUID = -1655051258255282376L;
	
	private User user = new User();
	
	private UserBiz userBiz ;
	
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}


	
	
	public String dologin() {
		
		List<User> list = userBiz.list(user);
		if(list.size()>0) {
			System.out.println("登录成功");
		}
		else {
			System.out.println("登录失败,用户名或密码错误");
		}
		return null;
	}
	
	public String addUser() {
		
		int n = userBiz.add(user);
		if(n>0) {
			System.out.println("注册成功");
		}
		else {
			System.out.println("注册失败");
		}
		
		return null;
	}

	public String  list() {
		
		List<User> list = userBiz.list(user);
		for (User user : list) {
			System.out.println(user);
		}
		
		return null;
	}
	
	public String listNode() {
		List<TreeNode> listNode = userBiz.listNode();
		for (TreeNode treeNode : listNode) {
			System.out.println(treeNode);
		}
		
		return null;
	}
	





	public UserBiz getUserBiz() {
		return userBiz;
	}



	public void setUserBiz(UserBiz userBiz) {
		this.userBiz = userBiz;
	}



	@Override
	public User getModel() {
		// TODO Auto-generated method stub
		return user;
	}
}

Articles模块

实体类Articles

package com.ningjie.article.entity;

import com.ningjie.base.entity.BaseEntity;

public class Articles extends BaseEntity {

	private static final long serialVersionUID = -6188029223617912462L;
	
	
	private int id;
	private String title;
	private String body;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getBody() {
		return body;
	}
	public void setBody(String body) {
		this.body = body;
	}
	public Articles(int id, String title, String body) {
		super();
		this.id = id;
		this.title = title;
		this.body = body;
	}
	public Articles() {
		super();
	}
	@Override
	public String toString() {
		return "Articles [id=" + id + ", title=" + title + ", body=" + body + "]";
	}
	
	
	
	

}

实体类Articles的映射文件articles.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 table="t_vue_articles" name="com.ningjie.article.entity.Articles">
		<id name="id" type="java.lang.Integer" column="id">
			<generator class="increment"></generator>
		</id>
		
		<property name="title" type="java.lang.String" column="title"></property>
		<property name="body" type="java.lang.String" column="body"></property>
	</class>
</hibernate-mapping>

ArticlesBiz

package com.ningjie.article.biz;

import java.util.List;

import com.ningjie.article.entity.Articles;


public interface ArticlesBiz {
	public List<Articles> list();
	public int add(Articles articles);
	public int edit(Articles articles);
	public int delete(Articles articles);

}

ArticlesBizImpl

package com.ningjie.article.biz.impl;

import java.util.List;

import com.ningjie.article.biz.ArticlesBiz;
import com.ningjie.article.dao.ArticlesDao;
import com.ningjie.article.entity.Articles;



public class ArticlesBizImpl implements ArticlesBiz {
	
	private ArticlesDao articlesDao ;
	
	
	
	public ArticlesDao getArticlesDao() {
		return articlesDao;
	}

	public void setArticlesDao(ArticlesDao articlesDao) {
		this.articlesDao = articlesDao;
	}

	@Override
	public List<Articles> list() {
		// TODO Auto-generated method stub
		return articlesDao.list();
	}

	@Override
	public int add(Articles articles) {
		// TODO Auto-generated method stub
		return articlesDao.add(articles);
	}

	@Override
	public int edit(Articles articles) {
		// TODO Auto-generated method stub
		return articlesDao.edit(articles);
	}

	@Override
	public int delete(Articles articles) {
		// TODO Auto-generated method stub
		return articlesDao.delete(articles);
	}
	
	

}

ArticleDao

package com.ningjie.article.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate5.HibernateCallback;

import com.ningjie.article.entity.Articles;
import com.ningjie.base.dao.BaseDao;


public class ArticlesDao extends BaseDao {

	private static final long serialVersionUID = 6720176337331636573L;
	
	
	public List<Articles> list(){
		
		return this.getHibernateTemplate().execute(new HibernateCallback<List<Articles>>() {

			@Override
			public List<Articles> doInHibernate(Session session) throws HibernateException {
				
				
				return session.createQuery("from Articles").list();
			}
		});
	}
	
	
	public int add(Articles articles) {
		
		Serializable a = this.getHibernateTemplate().save(articles);
		return 1;
	}
	
	public int edit(Articles articles) {
		
		this.getHibernateTemplate().update(articles);
		
		return 1;
	}
	
	public int delete(Articles articles) {
		
		this.getHibernateTemplate().delete(articles);
			
		return 1;
	}
	

}

ArticlesAction

package com.ningjie.article.web;

import java.util.List;

import com.opensymphony.xwork2.ModelDriven;
import com.ningjie.article.biz.ArticlesBiz;
import com.ningjie.article.entity.Articles;
import com.ningjie.base.web.BaseAction;

public class ArticlesAction extends BaseAction implements ModelDriven<Articles> {

	private static final long serialVersionUID = 5944659149847110488L;
	
	private Articles articles = new Articles();
	
	private ArticlesBiz articlesBiz ;
	

	public ArticlesBiz getArticlesBiz() {
		return articlesBiz;
	}


	public void setArticlesBiz(ArticlesBiz articlesBiz) {
		this.articlesBiz = articlesBiz;
	}

	
	public String list() {
		List<Articles> list = articlesBiz.list();
		for (Articles a : list) {
			System.out.println(a);
		}
		
		return null;
	}
	
	public String add() {
		articlesBiz.add(articles);
		
		return null;
	}
	public String edit() {
		articlesBiz.edit(articles);
		
	
		return null;
	}
	public String del() {
		articlesBiz.delete(articles);
	
		return null;
	}
	

	@Override
	public Articles getModel() {
		// TODO Auto-generated method stub
		return articles;
	}
	
	

}

spring-articles.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:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-aop-4.3.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">


<bean id="articlesDao" class="com.ningjie.article.dao.ArticlesDao" parent="baseDao" ></bean>
		<bean id="articlesBiz" class="com.ningjie.article.biz.impl.ArticlesBizImpl" parent="baseBiz" >
			<property name="articlesDao" ref="articlesDao"></property>
		</bean>
		
		<bean id="articlesAction" class="com.ningjie.article.web.ArticlesAction" parent="baseAction">
			<property name="articlesBiz" ref="articlesBiz"></property>
		</bean>
</beans>

spring-user.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:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
	
		<bean id="userDao" class="com.ningjie.user.dao.UserDao" parent="baseDao" ></bean>
		<bean id="userBiz" class="com.ningjie.user.biz.impl.UserBizImpl" parent="baseBiz" >
			<property name="userDao" ref="userDao"></property>
		</bean>
		
		<bean id="userAction" class="com.ningjie.user.web.UserAction" parent="baseAction">
			<property name="userBiz" ref="userBiz"></property>
		</bean>

</beans>

spring-context.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:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
       <import resource="spring-hibernate.xml"/>
       <import resource="spring-book.xml"/>
       <import resource="spring-user.xml"/>
        <import resource="spring-articles.xml"/>
       </beans>

spring-hibernate.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:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
	<!-- 1.注册数据库连接信息文件 2.配置数据库连接池(新的知识点) 3.配置sessionfactory 4.配置声明式事务(aop) 5.配置切面 6.配置通用模塊-->
	<!-- 1、注册jdbc相关的配置文件 -->
	<context:property-placeholder location="classpath:db.properties" />
	<!-- 2、配置数据库连接池C3P0 -->
	<!-- 注册数据库连接文件db.properties -->
	

	<!-- 配置c3p0连接池 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="user" value="${db.username}"></property>
		<property name="password" value="${db.password}"></property>
		<property name="driverClass" value="${db.driverClass}"></property>
		<property name="jdbcUrl" value="${db.jdbcUrl}"></property>

		<!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
		<property name="initialPoolSize" value="${db.initialPoolSize}"></property>
		<!--连接池中保留的最大连接数。Default: 15 -->
		<property name="maxPoolSize" value="${db.maxPoolSize}"></property>
		<!--连接池中保留的最小连接数。 -->
		<property name="minPoolSize" value="${db.minPoolSize}" />
		<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
		<property name="maxIdleTime" value="${db.maxIdleTime}" />

		<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
		<property name="acquireIncrement" value="${db.acquireIncrement}" />

		<!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 属于单个connection而不是整个连接池。 
			所以设置这个参数需要考虑到多方面的因素。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 
			0 -->
		<property name="maxStatements" value="${db.maxStatements}" />

		<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
		<property name="idleConnectionTestPeriod" value="${db.idleConnectionTestPeriod}" />

		<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
		<property name="acquireRetryAttempts" value="${db.acquireRetryAttempts}" />

		<!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效 保留,并在下次调用getConnection()的时候继续尝试获取连接。 
			如果设为true,那么在尝试 获取连接失败后该数据源将申明已断开并永久关闭。Default: false -->
		<property name="breakAfterAcquireFailure" value="${db.breakAfterAcquireFailure}" />

		<!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的 时候都将校验其有效性。建议使用idleConnectionTestPeriod 
			或automaticTestTable 等方法来提升连接测试的性能。Default: false -->
		<property name="testConnectionOnCheckout" value="${db.breakAfterAcquireFailure}" />
	</bean>

	<!-- 3、配置sessionfactory相关信息 -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
		<!-- 数据源 -->
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
		<!-- hibernate相关属性 -->
		<property name="hibernateProperties">
			<props>
				<prop key="dialect">org.hibernate.dialect.MySQLDialect</prop>
				<!--spring与Hibernate集成无法显示sql语句问题,请见集成后hibernate无法显示sql语句.txt -->
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">true</prop>
			</props>
		</property>
		<!-- 实体映射文件 -->
		<property name="mappingResources">
			<list>
				<value>com/ningjie/book/entity/book.hbm.xml</value>
				<value>com/ningjie/user/entity/User.hbm.xml</value>
				<value>com/ningjie/user/entity/TreeNode.hbm.xml</value>
				<value>com/ningjie/article/entity/Articles.hbm.xml</value>

			</list>
		</property>
	</bean>

	<!-- 4、配置事务 -->
	<!--声明式事务配置开始 -->
	<!-- 
		静态代理:
			一个代理对象->一个目标对象
			BookProxy(BookBizImpl+myMethodBeforeAdvice)->bookBiz
			OrderProxy(OrderBizImpl+myMethodBeforeAdvice2)->	OrderBiz
		
		动态代理:
			一个代理对象->多个目标对象
	 -->
	
	<!--1) 开启自动代理 -->
	<aop:aspectj-autoproxy />

	<!--2) 事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate5.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>

	<!--3) 定义事务特性 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="insert*" propagation="REQUIRED" />

			<tx:method name="edit*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />

			<tx:method name="del*" propagation="REQUIRED" />
			<tx:method name="remove*" propagation="REQUIRED" />

			<tx:method name="load*" propagation="REQUIRED" read-only="true" />
			<tx:method name="list*" propagation="REQUIRED" read-only="true" />
			<tx:method name="select*" propagation="REQUIRED" read-only="true" />
			<tx:method name="query*" propagation="REQUIRED" read-only="true" />

			<tx:method name="do*" propagation="REQUIRED" />
		</tx:attributes>
	</tx:advice>

	<!--4) 定义切入点 -->
	<aop:config>
		<!-- pointcut属性用来定义一个切入点,分成四个部分理解 [* ][*..][*Biz][.*(..)] -->
		<!-- A: 返回类型,*表示返回类型不限 -->
		<!-- B: 包名,*..表示包名不限 -->
		<!-- C: 类或接口名,*Biz表示类或接口必须以Biz结尾 -->
		<!-- D: 方法名和参数,*(..)表示方法名不限,参数类型和个数不限 -->
		<aop:advisor advice-ref="txAdvice" pointcut="execution(* *..*Biz.*(..))" />
	</aop:config>
	<!-- 声明式事务配置结束 -->

	<!-- 5、配置HibernateTemplate 可以看成session-->
	<bean class="org.springframework.orm.hibernate5.HibernateTemplate" id="hibernateTemplate">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<!-- 6、分模块开发(只配置base模块) -->
	<bean class="com.ningjie.base.entity.BaseEntity" abstract="true" id="baseEntity"></bean>
	<bean class="com.ningjie.base.dao.BaseDao" abstract="true" id="baseDao" >
		<property name="hibernateTemplate" ref="hibernateTemplate"></property>
	</bean>
	<bean class="com.ningjie.base.biz.BaseBiz" abstract="true" id="baseBiz"></bean>
	<bean class="com.ningjie.base.web.BaseAction" abstract="true" id="baseAction"></bean>
</beans>

struts-user.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
	"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
	<package name="user" extends="base" >
		<action name="user_*" class="userAction" method="{1}">
		</action>
	</package>
</struts>

struts-articles.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
	"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
	<package name="articles" extends="base" namespace="/articles">
		<action name="/articles_*" class="articlesAction" method="{1}">
			
		</action>
	</package>
</struts>

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
	"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
	<include file="struts-default.xml"></include>
	<include file="struts-base.xml"></include>
	<include file="struts-book.xml"></include>
	<include file="struts-user.xml"></include>
	<include file="struts-articles.xml"></include>
</struts>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值