Skip to content

Commit

Permalink
第一次
Browse files Browse the repository at this point in the history
  • Loading branch information
yyalc committed Jun 29, 2017
1 parent f24998c commit 0135f14
Show file tree
Hide file tree
Showing 23 changed files with 261 additions and 10 deletions.
29 changes: 29 additions & 0 deletions bin/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>smartframework</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>
4 changes: 4 additions & 0 deletions bin/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
8 changes: 8 additions & 0 deletions bin/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
4 changes: 4 additions & 0 deletions bin/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
4 changes: 4 additions & 0 deletions bin/.settings/org.eclipse.wst.common.project.facet.core.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.7"/>
</faceted-project>
66 changes: 66 additions & 0 deletions bin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.zol</groupId>
<artifactId>smartframework</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>smartframework</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.33</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.33</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>commons-dbutils</groupId>
<artifactId>commons-dbutils</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions src/main/java/com/zol/smartframework/annotation/Action.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.zol.smartframework.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* 创建时间:2017年6月29日
* @author suzhihui
* 用于标识控制器方法
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Action {

}
17 changes: 17 additions & 0 deletions src/main/java/com/zol/smartframework/annotation/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.zol.smartframework.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* 创建时间:2017年6月29日
* @author suzhihui
* 用于标识控制器
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Controller {

}
17 changes: 17 additions & 0 deletions src/main/java/com/zol/smartframework/annotation/Inject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.zol.smartframework.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* 创建时间:2017年6月29日
* @author suzhihui
* 用于依赖注入
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Inject {

}
17 changes: 17 additions & 0 deletions src/main/java/com/zol/smartframework/annotation/Service.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.zol.smartframework.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* 创建时间:2017年6月29日
* @author suzhihui
* 用于标识服务层类
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Service {

}
64 changes: 54 additions & 10 deletions src/main/java/com/zol/smartframework/util/ClassUtil.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.zol.smartframework.util;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -36,7 +44,7 @@ public static Class<?> loadClass(String classname,boolean isInitialized){
}

//获取指定包名下的所有类
public static Class<Set<?>> getClassSet(String packagename){
public static Set<Class<?>> getClassSet(String packagename){
Set<Class<?>> classSet=new HashSet<>();
try {
Enumeration<URL> urls=getClassLoader().getResources(packagename.replace(".", "/"));
Expand All @@ -47,25 +55,61 @@ public static Class<Set<?>> getClassSet(String packagename){
String packagePath=url.getPath().replaceAll("%20", "");
addClass(classSet, packagePath, packagename);
}else if("jar".equals(protocol)){

JarURLConnection connection=(JarURLConnection) url.openConnection();
if(null!=connection){
JarFile jarFile=connection.getJarFile();
Enumeration<JarEntry> entrys= jarFile.entries();
while(entrys.hasMoreElements()){
JarEntry jarEntry=entrys.nextElement();
String jarEntryName=jarEntry.getName();
if(jarEntryName.endsWith(".class")){
String classname=jarEntryName.substring(0,jarEntryName.lastIndexOf(".")).replaceAll("/", ".");
doAddClass(classSet, classname);
}
}
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
LOGGER.error("get class set failure", e);
throw new RuntimeException(e);
}
return null;
return classSet;
}

private static void addClass(Set<Class<?>> set,String packagePath,String packagename){

File[] files=new File(packagePath).listFiles(new FileFilter() {

@Override
public boolean accept(File file) {
return (file.isFile()&&file.getName().endsWith(".class"))||file.isDirectory();
}
});
for(File f:files){
String filename=f.getName();
if(f.isFile()){
String classname=filename.substring(0, filename.lastIndexOf("."));
if(StringUtil.isNotEmpty(classname)){
classname=packagename+"."+classname;
}
doAddClass(set, classname);
}else{
String subPackagePath=filename;
if(StringUtil.isNotEmpty(subPackagePath)){
subPackagePath=packagePath+"/"+subPackagePath;
}
String subPackageName=filename;
if(StringUtil.isNotEmpty(packagename)){
subPackageName=packagename+"."+subPackageName;
}
addClass(set, subPackagePath, subPackageName);
}
}
}

private static void doAddClass(Set<Class<?>> set,String classname){

Class<?> cls=loadClass(classname, false);
set.add(cls);
}

public static void main(String[] args) {
System.out.println("aabbccbbdd".replace("bb", "22"));
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/zol/smartframework/util/StringUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.zol.smartframework.util;

import org.apache.commons.lang3.StringUtils;

/**
* 创建时间:2017年6月29日
* @author suzhihui
*/
public class StringUtil {

//判断字符串是否为空
public static boolean isEmpty(String str){
if(null!=str){
str=str.trim();
}
return StringUtils.isEmpty(str);
}

//判断字符串是否非空
public static boolean isNotEmpty(String str){
return !isEmpty(str);
}

}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified target/classes/com/zol/smartframework/util/ClassUtil.class
Binary file not shown.
Binary file not shown.

0 comments on commit 0135f14

Please sign in to comment.