ssh2项目、2月9日

struts2.1.6 dojo插件 下载在面

jsp上使用:

<%@ taglib uri="/struts-dojo-tags" prefix="sx" %> 

 页面必须引入

  <sx:head/>

 调用dojo的时间控件

<sx:datetimepicker label="" name="employee.joindate"></sx:datetimepicker>

 

spring aop annotation 介绍

 

package com.cxl.spring.annotation;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class SecurityHandler {
	//这个应该是定义 切入点
	//表达式  *有无返回值 add*  方法开头   (..)有参无参数都可以
	//定义pointcut 名称就是alladdmethod 方法不能有返回值和参数 该方法就是一个标示符
	@Pointcut("execution(* com.struts2.service.impl.*.get*(..)) || execution(* com.struts2.service.impl.*.delete*(..))")
	private void allAddMethod(){}
	
	
	
	/**
	 * 定义advice ,标示在那个切入点 切入
	 * 
	 * before 在之前切入
	 */
	@Before("allAddMethod()")
	private void checkSecurity(JoinPoint joinPoint)
	{
		System.out.println("方法名字"+joinPoint.getSignature().getName());
		
		Object []args=joinPoint.getArgs();
		for(int i=0;i<args.length;i++)
		{
			System.out.println("参数名字"+args[i]);
		}		
		
		
		
		System.out.println("我的第一个aop实现了");
	}

}

 

 

定义一个 类 用annotation 进行注解 里面有个2个方法  一个是 定义point插入的 位置, 一个是定义执行的内容

详细见上面的注释

 

然后再application里注入这个bean 如

<bean id="aop" class="com.cxl.spring.annotation.SecurityHandler" />

 另外注意的是application对spring annotation支持 还需要加 入

	<!--启用aspectj 对spring annotation支持-->
     <aop:aspectj-autoproxy  />

然后把切面 配置入

<bean id="aop" class="com.cxl.spring.annotation.SecurityHandler" />

 

其中配置文件还要引入些xml的 xsd 的aop xml文件 要在我们的系统文件内找到这个

路径在spring2.5.6/dist/resources 加入aop的 xsd文件

 

最后修改application的头文件为:

<?xml version="1.0" encoding="GBK"?>
<!-- 指定Spring配置文件的Schema信息 -->
<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:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
	http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
	http://www.springframework.org/schema/aop 
	http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

 

事务管理 示例代码

 

 <!-- 配置Hibernate的局部事务管理器,使用HibernateTransactionManager类 -->
<!-- 该类实现PlatformTransactionManager接口,是针对Hibernate的特定实现-->
<bean id="transactionManager" class=
	"org.springframework.orm.hibernate3.HibernateTransactionManager">
	<!-- 配置HibernateTransactionManager时需要依注入SessionFactory的引用 -->
	<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- 配置事务传播特性-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
 <tx:method name="add*" propagation="REQUIRED"  />
 <tx:method name="del*" propagation="REQUIRED"  />
<tx:method name="modify*" propagation="REQUIRED"  />
<!-- 其他方法 -->
<tx:method name="*" read-only="false" />
</tx:attributes>
</tx:advice>

<!-- 配置哪些类的 哪些方法参加事务 xml配置 -->
<aop:config>
<aop:pointcut  id="classPathdo" expression="execution(* com.struts2.service.impl.EmployeeMgrImpl.get*(..)) || execution(* com.struts2.service.impl.EmployeeMgrImpl.del*(..))" />
<aop:advisor pointcut-ref="classPathdo" advice-ref="txAdvice" />

</aop:config>

 

struts2内要想在jsp内的标签使用 动态的<%%> 变量 必须吧 变量放入到request.setAttribute() 然后在${}访问

${}是可以放到""双引号内的

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值