//接口的实现类
import java.util.ArrayList;
import java.util.List;
public class UserServiceImpl implements IUserService {
@Override
public List getAllUser() {
System.out.println("--------getAllUser----------");
return new ArrayList<>();
}
@Override
public boolean saveUser(T user) {
System.out.println("--------saveUser----------");
return true;
}
@Override
public boolean deleteUser(int uid) {
System.out.println("--------deleteUser----------");
return false;
}
@Override
public boolean updateUser(T obj) {
System.out.println("--------updateUser----------");
return true;
}
}
public class MyAspect {
public void before(){
System.out.println("********before**********");
}
public void after(){
System.out.println("********after**********");
}
}
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
public class UserFactory {
public static IUserService getUserService(){
IUserService us = new UserservcieImpl();
MyAspect ma = new MyAspect();
/**
*
* 使用Proxy类的静态方法newProxyInstance来实现对于目标对象us的代理
* 目的是在原本us可以做的事情之前和之后可以做额外的事情
*
*/
IUserService ius = (IUserService) Proxy.newProxyInstance(UserFactory.class.getClassLoader(), us.getClass().getInterfaces(), new InvocationHandler() {
/**
* 代理对象调用的回掉方法
* @param proxy 代理对象
* @param method 被代理的方法
* @param args 被代理方法的参数列表对象
* @return 每个方法的最终返回值
* @throws Throwable
*/
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
ma.before();
Object obj = method.invoke(us, args);
ma.after();
return obj;
}
});
return ius;
}
}
import org.junit.Test;
public class TestAOP02 {
@Test
public void testAOP02(){
// IUserService us = new UserServiceImpl<>();
Object o = new Object();
// System.out.println(us.getAllUser());
// System.out.println(us.saveUser(o));
// System.out.println(us.deleteUser(1));
// System.out.println(us.updateUser(o));
System.out.println("==============");
IUserService ius = UserFactory.getUserService();
System.out.println(ius.getAllUser());
System.out.println(ius.saveUser(o));
System.out.println(ius.deleteUser(1));
System.out.println(ius.updateUser(o));
}
}
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestAOP03 {
@Test
public void testAOP03(){
ApplicationContext ac = new ClassPathXmlApplicationContext("com/qfedu/aop03/beans.xml");
IUserService us = ac.getBean("proxy", IUserService.class);
Object o = new Object();
System.out.println(us.getAllUser());
System.out.println(us.deleteUser(1));
System.out.println(us.saveUser(o));
System.out.println(us.updateUser(o));
}
}
同生成的做法一样,添加和移除类成员只要去修改fields和methods中的元素即可。这里我们拿一个简单的类做例子,下面这个Task类,我们来移除isNeedRemove方法,并且添加一个int 类型的addedField属性。
package asm.core;
/**
* Created by yunshen.ljy on 2015/6/
交换两个数字的方法有以下三种 ,其中第一种最常用
/*
输出最小的一个数
*/
public class jiaohuan1 {
public static void main(String[] args) {
int a =4;
int b = 3;
if(a<b){
// 第一种交换方式
int tmep =
1. Kafka提供了两种Consumer API
High Level Consumer API
Low Level Consumer API(Kafka诡异的称之为Simple Consumer API,实际上非常复杂)
在选用哪种Consumer API时,首先要弄清楚这两种API的工作原理,能做什么不能做什么,能做的话怎么做的以及用的时候,有哪些可能的问题
CompositeChannelBuffer体现了Netty的“Transparent Zero Copy”
查看API(
http://docs.jboss.org/netty/3.2/api/org/jboss/netty/buffer/package-summary.html#package_description)
可以看到,所谓“Transparent Zero Copy”是通
// this need android:minSdkVersion="11"
getActionBar().setDisplayHomeAsUpEnabled(true);
@Override
public boolean onOptionsItemSelected(MenuItem item) {
$(document).ready(function () {
var request = {
QueryString :
function (val) {
var uri = window.location.search;
var re = new RegExp("" + val + "=([^&?]*)", &
ArticleSelect类在命名空间HoverTree.Model中可以认为是文章查询条件类,用于存放查询文章时的条件,例如HvtId就是文章的id。HvtIsShow就是文章的显示属性,当为-1是,该条件不产生作用,当为0时,查询不公开显示的文章,当为1时查询公开显示的文章。HvtIsHome则为是否在首页显示。HoverTree系统源码完全开放,开发环境为Visual Studio 2013
1. php 类
I found this class looking for something else actually but I remembered I needed some while ago something similar and I never found one. I'm sure it will help a lot of developers who try to
Design pattern for graph processing.
Since we consider a large number of graph-processing algorithms, our initial design goal is to decouple our implementations from the graph representation