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() 然后在${}访问
${}是可以放到""双引号内的