forked from iSafeBlue/TrackRay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
357 additions
and
50 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
base/src/main/java/com/trackray/base/annotation/Function.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.trackray.base.annotation; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* @author 浅蓝 | ||
* @email [email protected] | ||
* @since 2019/1/8 12:28 | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
public @interface Function { | ||
String value() default ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
package com.trackray.base.annotation; | ||
|
||
/** | ||
* @author 浅蓝 | ||
* @email [email protected] | ||
* @since 2019/1/8 12:28 | ||
*/ | ||
public @interface Param { | ||
String key () default ""; | ||
String defaultValue() default ""; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
base/src/main/java/com/trackray/base/plugin/MVCPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.trackray.base.plugin; | ||
|
||
import com.trackray.base.annotation.Function; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Map; | ||
|
||
/** | ||
* MVC插件类 | ||
* @author 浅蓝 | ||
* @email [email protected] | ||
* @since 2019/4/2 16:33 | ||
*/ | ||
public abstract class MVCPlugin extends CommonPlugin<ModelAndView>{ | ||
|
||
protected ModelAndView model; | ||
protected String function; | ||
|
||
@Function | ||
public abstract void index(); | ||
|
||
@Override | ||
public boolean check(Map<String, Object> param) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public ModelAndView start() { | ||
boolean flag = false; | ||
Method target = null; | ||
Method[] methods = this.getClass().getMethods(); | ||
|
||
for (Method method : methods) { | ||
Function func = method.getAnnotation(Function.class); | ||
if (func!=null) | ||
{ | ||
String value = func.value(); | ||
if (StringUtils.isEmpty(value)) | ||
value = method.getName();//如果不填写function注解的value则认为mapping是方法名 | ||
if(function.equals(value)){ | ||
flag = true; | ||
target = method; | ||
break; | ||
} | ||
} | ||
} | ||
String pluginKey = this.currentPlugin().value();//插件对象在spring中的id | ||
|
||
if (flag){ | ||
try { | ||
target.invoke(this, null); | ||
model.setViewName(pluginKey.concat("/"+model.getViewName())); // 如果功能执行正常 那在viewName则为:插件id/视图名 | ||
} catch (Exception e) { | ||
model.setViewName("common/error"); | ||
model.addObject("msg",e.getMessage()); | ||
} | ||
|
||
}else{ | ||
try { | ||
this.getClass().getMethod("index",null).invoke(this, null);//执行默认的index方法 | ||
model.setViewName(pluginKey.concat("/"+model.getViewName())); // 如果功能执行正常 那在viewName则为:插件id/视图名 | ||
} catch (Exception e) { | ||
model.setViewName("common/error"); | ||
model.addObject("msg",e.getMessage()); | ||
} | ||
} | ||
|
||
return model; | ||
} | ||
|
||
public void setFunction(String function) { | ||
this.function = function; | ||
} | ||
|
||
public void setModel(ModelAndView model) { | ||
this.model = model; | ||
} | ||
|
||
|
||
} |
31 changes: 31 additions & 0 deletions
31
module/src/main/java/com/trackray/module/plugin/ios/mvcTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.trackray.module.plugin.ios; | ||
|
||
import com.trackray.base.annotation.Function; | ||
import com.trackray.base.annotation.Plugin; | ||
import com.trackray.base.annotation.Rule; | ||
import com.trackray.base.plugin.MVCPlugin; | ||
|
||
/** | ||
* @author 浅蓝 | ||
* @email [email protected] | ||
* @since 2019/4/2 17:34 | ||
*/ | ||
@Rule | ||
@Plugin(value = "mvcTest", | ||
title = "mvc类插件测试", | ||
author = "blue") | ||
public class mvcTest extends MVCPlugin{ | ||
|
||
@Function("test.html") | ||
public void test(){ | ||
model.addObject("msg","这是一个测试插件"); | ||
model.setViewName("test"); | ||
} | ||
|
||
|
||
@Override | ||
public void index() { | ||
model.addObject("msg","index page"); | ||
model.setViewName("index"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
|
||
<h1>Error</h1> | ||
<li th:text="${msg}"></li> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
</head> | ||
<body>index.html | ||
<li th:text="${msg}"></li> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
</head> | ||
<body>test.html | ||
<li th:text="${msg}"></li> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.