ssh框架整合

1.创建目录结构
2.引入struts,hibernate,springjar包按照顺序
3.引入三个框架的配置文件。
4.hibernate+spring主要配置applicationContext.xml 连接池、sessionFactory、事务提交
5.struts+spring 将struts创建的action交给spring管理
需要引入struts-spring-plugin.jar  struts的配置文件设置action的包的扫描范围
6.配置spring扫描包的范围
7.完善前端页面、action、service、dao、entity(注意实体映射注解)
dao层需要依赖注入SessionFactory 注意不要忘了setget方法
hibernate.xml配置文件实体映射


框架调试
8.jar包去重 留下同名高版本的jar包

9.web.xml 配置struts过滤器 启动监听器(加载bean)


spring的配置文件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: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.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 扫描包的范围,自动扫描包下有相应注解的类,完成bean的装配-->
<context:component-scan base-package="org.sdibt.king"></context:component-scan>
<!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
     	<property name="driverClass" value="com.mysql.jdbc.Driver"></property>
     	<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test_ssh"></property>
     	<property name="user" value="root"></property>
     	<property name="password" value="3306"></property>
     	<property name="acquireIncrement" value="5"></property>  <!-- 当连接池中的连接用完时,C3P0一次性创建新连接的数目2 -->
     	<property name="initialPoolSize" value="10"></property>  <!-- 初始化时创建的连接数,必须在minPoolSize和maxPoolSize之间 -->
     	<property name="minPoolSize" value="5"></property>
     	<property name="maxPoolSize" value="20"></property>
     	<!-- 最大空闲时间,超过空闲时间的连接将被丢弃
     	[需要注意:mysql默认的连接时长为8小时(28800)【可在my.ini中添加 wait_timeout=30(单位秒)设置连接超时】,这里设置c3p0的超时必须<28800] 
     	-->
     	<property name="maxIdleTime" value="300"></property>  
     	<property name="idleConnectionTestPeriod" value="60"></property> <!-- 每60秒检查连接池中的空闲连接 -->
     	<property name="maxStatements" value="20"></property>  <!-- jdbc的标准参数  用以控制数据源内加载的PreparedStatement数量,但由于预缓存的Statement属 于单个Connection而不是整个连接 -->
     </bean>
    <!-- 配置sessionFactory -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<property name="configLocation"
			value="classpath:hibernate.cfg.xml">
		</property>
		<property name="dataSource" ref="dataSource"></property>
		<property name="namingStrategy">
			<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
		</property>
	</bean>
	<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
	<!-- 配置事务支持注解方式 -->
	<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

hibernate的配置文件hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
  <property name="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</property>
  <!-- 配置自动根据实体生成数据库的表一般设置成update,设置为create每次都会删除原来的表再新建一个表-->
  <property name="hibernate.hbm2ddl.auto">update</property>
  <!-- 显示生成的sql -->
  <property name="hibernate.show_sql">true</property>
  <!-- 格式化生成的sql -->
  <property name="hibernate.format_sql">true</property>
  <!-- 添加实体类 -->
  <mapping class="org.sdibt.king.entity.User"/>
 </session-factory>
</hibernate-configuration>

struts的配置文件struts.xml

<?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>
	  <!-- 增加struts搜索action的包范围 -->
	  <constant name="struts.convention.action.packages" value="org.sdibt.king.controller"/>
</struts>

web.xml

<?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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>web_08_ssh</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <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>
  <!-- 配置自定义过滤器必须放在struts过滤器之前配置-->
  <filter>
  	<filter-name>EncodingFilter</filter-name>
    <filter-class>org.sdibt.king.filter.EncodingFilter</filter-class>
  </filter>
  
  <filter-mapping>
  	<filter-name>EncodingFilter</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>
  <!-- 配置struts2过滤器 -->
  <filter>
  	<filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  
  <filter-mapping>
  	<filter-name>struts2</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>
  
</web-app>

controller层代码示例

@Controller
@Namespace("/user")
@ParentPackage("struts-default")
public class UserAction {
	@Resource
	private IUserService userService;//用户信息业务逻辑处理对象
	private User user;
	
	/**
	 * 添加用户
	 * @return resultStr 指定跳转页面
	 */
	@Action(value="addUser",results={@Result(name="success",location="/add_success.jsp"),
			@Result(name="fail",location="/add_fail.jsp")})
	public String addUser(){
		String resultStr="";
		boolean result = userService.addUser(user);//添加一个用户
		//判断添加用户是否成功
		if(result==true){
			resultStr="success";
		}else{
			resultStr="fail";
		}
		return resultStr;
	}
	
	
	public IUserService getUserService() {
		return userService;
	}
	public void setUserService(IUserService userService) {
		this.userService = userService;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
}

service实现层代码示例

@Service
public class UserServiceImpl implements IUserService {
	@Resource
	private IUserDao userDao;//用户信息数据库操作对象


	public IUserDao getUserDao() {
		return userDao;
	}


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


	/**
	 * 添加用户信息
	 * @param user 用户对象
	 * return result 添加结果
	 */
	@Override
	@Transactional
	public boolean addUser(User user) {
		boolean result = userDao.saveUser(user);//保存用户信息
		return result;
	}
}

dao实现层代码示例

@Repository
public class UserDaoImpl implements IUserDao {
	@Resource
	private SessionFactory sessionFactory;//session工厂
	/**
	 * 保存用户信息
	 * @param user 用户对象
	 * return result 保存结果
	 */
	@Override
	public boolean saveUser(User user) {
		boolean result=true;//保存结果
		Session session=null;//session
		try {
			session = sessionFactory.getCurrentSession();//获取session
			session.save(user);//保存用户信息
		} catch (HibernateException e) {
			result=false;//保存失败
		}
		return result;
	}
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	} 
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在信号处理领域,DOA(Direction of Arrival)估计是一项关键技术,主要用于确定多个信号源到达接收阵列的方向。本文将详细探讨三种ESPRIT(Estimation of Signal Parameters via Rotational Invariance Techniques)算法在DOA估计中的实现,以及它们在MATLAB环境中的具体应用。 ESPRIT算法是由Paul Kailath等人于1986年提出的,其核心思想是利用阵列数据的旋转不变性来估计信号源的角度。这种算法相比传统的 MUSIC(Multiple Signal Classification)算法具有较低的计算复杂度,且无需进行特征值分解,因此在实际应用中颇具优势。 1. 普通ESPRIT算法 普通ESPRIT算法分为两个主要步骤:构造等效旋转不变系统和估计角度。通过空间平移(如延时)构建两个子阵列,使得它们之间的关系具有旋转不变性。然后,通过对子阵列数据进行最小二乘拟合,可以得到信号源的角频率估计,进一步转换为DOA估计。 2. 常规ESPRIT算法实现 在描述中提到的`common_esprit_method1.m`和`common_esprit_method2.m`是两种不同的普通ESPRIT算法实现。它们可能在实现细节上略有差异,比如选择子阵列的方式、参数估计的策略等。MATLAB代码通常会包含预处理步骤(如数据归一化)、子阵列构造、旋转不变性矩阵的建立、最小二乘估计等部分。通过运行这两个文件,可以比较它们在估计精度和计算效率上的异同。 3. TLS_ESPRIT算法 TLS(Total Least Squares)ESPRIT是对普通ESPRIT的优化,它考虑了数据噪声的影响,提高了估计的稳健性。在TLS_ESPRIT算法中,不假设数据噪声是高斯白噪声,而是采用总最小二乘准则来拟合数据。这使得算法在噪声环境下表现更优。`TLS_esprit.m`文件应该包含了TLS_ESPRIT算法的完整实现,包括TLS估计的步骤和旋转不变性矩阵的改进处理。 在实际应用中,选择合适的ESPRIT变体取决于系统条件,例如噪声水平、信号质量以及计算资源。通过MATLAB实现,研究者和工程师可以方便地比较不同算法的效果,并根据需要进行调整和优化。同时,这些代码也为教学和学习DOA估计提供了一个直观的平台,有助于深入理解ESPRIT算法的工作原理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值