Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
后端镜像
java镜像
Smart Framework
提交
c66349a1
S
Smart Framework
项目概览
后端镜像
/
java镜像
/
Smart Framework
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Smart Framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c66349a1
编写于
10月 17, 2014
作者:
黄
黄勇
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
v2.3.3-SNAPSHOT
- 改进:代码优化
上级
cbcac5ad
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
19 deletion
+19
-19
src/main/java/org/smart4j/framework/mvc/ActionHelper.java
src/main/java/org/smart4j/framework/mvc/ActionHelper.java
+10
-10
src/main/java/org/smart4j/framework/mvc/Requester.java
src/main/java/org/smart4j/framework/mvc/Requester.java
+2
-2
src/main/java/org/smart4j/framework/mvc/impl/DefaultHandlerMapping.java
...org/smart4j/framework/mvc/impl/DefaultHandlerMapping.java
+7
-7
未找到文件。
src/main/java/org/smart4j/framework/mvc/ActionHelper.java
浏览文件 @
c66349a1
...
...
@@ -23,15 +23,15 @@ public class ActionHelper {
/**
* Action Map(HTTP 请求与 Action 方法的映射)
*/
private
static
final
Map
<
Request
or
,
Handler
>
actionMap
=
new
LinkedHashMap
<
Requesto
r
,
Handler
>();
private
static
final
Map
<
Request
er
,
Handler
>
actionMap
=
new
LinkedHashMap
<
Requeste
r
,
Handler
>();
static
{
// 获取所有 Action 类
List
<
Class
<?>>
actionClassList
=
ClassHelper
.
getClassListByAnnotation
(
Action
.
class
);
if
(
CollectionUtil
.
isNotEmpty
(
actionClassList
))
{
// 定义两个 Action Map
Map
<
Request
or
,
Handler
>
commonActionMap
=
new
HashMap
<
Requesto
r
,
Handler
>();
// 存放普通 Action Map
Map
<
Request
or
,
Handler
>
regexpActionMap
=
new
HashMap
<
Requesto
r
,
Handler
>();
// 存放带有正则表达式的 Action Map
Map
<
Request
er
,
Handler
>
commonActionMap
=
new
HashMap
<
Requeste
r
,
Handler
>();
// 存放普通 Action Map
Map
<
Request
er
,
Handler
>
regexpActionMap
=
new
HashMap
<
Requeste
r
,
Handler
>();
// 存放带有正则表达式的 Action Map
// 遍历 Action 类
for
(
Class
<?>
actionClass
:
actionClassList
)
{
// 获取并遍历该 Action 类中所有的方法
...
...
@@ -49,7 +49,7 @@ public class ActionHelper {
}
}
private
static
void
handleActionMethod
(
Class
<?>
actionClass
,
Method
actionMethod
,
Map
<
Request
or
,
Handler
>
commonActionMap
,
Map
<
Requesto
r
,
Handler
>
regexpActionMap
)
{
private
static
void
handleActionMethod
(
Class
<?>
actionClass
,
Method
actionMethod
,
Map
<
Request
er
,
Handler
>
commonActionMap
,
Map
<
Requeste
r
,
Handler
>
regexpActionMap
)
{
// 判断当前 Action 方法是否带有 Request 注解
if
(
actionMethod
.
isAnnotationPresent
(
Request
.
Get
.
class
))
{
String
requestPath
=
actionMethod
.
getAnnotation
(
Request
.
Get
.
class
).
value
();
...
...
@@ -66,23 +66,23 @@ public class ActionHelper {
}
}
private
static
void
putActionMap
(
String
requestMethod
,
String
requestPath
,
Class
<?>
actionClass
,
Method
actionMethod
,
Map
<
Request
or
,
Handler
>
commonActionMap
,
Map
<
Requesto
r
,
Handler
>
regexpActionMap
)
{
private
static
void
putActionMap
(
String
requestMethod
,
String
requestPath
,
Class
<?>
actionClass
,
Method
actionMethod
,
Map
<
Request
er
,
Handler
>
commonActionMap
,
Map
<
Requeste
r
,
Handler
>
regexpActionMap
)
{
// 判断 Request Path 中是否带有占位符
if
(
requestPath
.
matches
(
".+\\{\\w+\\}.*"
))
{
// 将请求路径中的占位符 {\w+} 转换为正则表达式 (\\w+)
requestPath
=
StringUtil
.
replaceAll
(
requestPath
,
"\\{\\w+\\}"
,
"(\\\\w+)"
);
// 将 Request
o
r 与 Handler 放入 Regexp Action Map 中
regexpActionMap
.
put
(
new
Request
o
r
(
requestMethod
,
requestPath
),
new
Handler
(
actionClass
,
actionMethod
));
// 将 Request
e
r 与 Handler 放入 Regexp Action Map 中
regexpActionMap
.
put
(
new
Request
e
r
(
requestMethod
,
requestPath
),
new
Handler
(
actionClass
,
actionMethod
));
}
else
{
// 将 Request
o
r 与 Handler 放入 Common Action Map 中
commonActionMap
.
put
(
new
Request
o
r
(
requestMethod
,
requestPath
),
new
Handler
(
actionClass
,
actionMethod
));
// 将 Request
e
r 与 Handler 放入 Common Action Map 中
commonActionMap
.
put
(
new
Request
e
r
(
requestMethod
,
requestPath
),
new
Handler
(
actionClass
,
actionMethod
));
}
}
/**
* 获取 Action Map
*/
public
static
Map
<
Request
o
r
,
Handler
>
getActionMap
()
{
public
static
Map
<
Request
e
r
,
Handler
>
getActionMap
()
{
return
actionMap
;
}
}
src/main/java/org/smart4j/framework/mvc/Request
o
r.java
→
src/main/java/org/smart4j/framework/mvc/Request
e
r.java
浏览文件 @
c66349a1
...
...
@@ -6,12 +6,12 @@ package org.smart4j.framework.mvc;
* @author huangyong
* @since 1.0
*/
public
class
Request
o
r
{
public
class
Request
e
r
{
private
String
requestMethod
;
private
String
requestPath
;
public
Request
o
r
(
String
requestMethod
,
String
requestPath
)
{
public
Request
e
r
(
String
requestMethod
,
String
requestPath
)
{
this
.
requestMethod
=
requestMethod
;
this
.
requestPath
=
requestPath
;
}
...
...
src/main/java/org/smart4j/framework/mvc/impl/DefaultHandlerMapping.java
浏览文件 @
c66349a1
...
...
@@ -6,7 +6,7 @@ import java.util.regex.Pattern;
import
org.smart4j.framework.mvc.ActionHelper
;
import
org.smart4j.framework.mvc.Handler
;
import
org.smart4j.framework.mvc.HandlerMapping
;
import
org.smart4j.framework.mvc.Request
o
r
;
import
org.smart4j.framework.mvc.Request
e
r
;
/**
* 默认处理器映射
...
...
@@ -21,12 +21,12 @@ public class DefaultHandlerMapping implements HandlerMapping {
// 定义一个 Handler
Handler
handler
=
null
;
// 获取并遍历 Action 映射
Map
<
Request
o
r
,
Handler
>
actionMap
=
ActionHelper
.
getActionMap
();
for
(
Map
.
Entry
<
Request
o
r
,
Handler
>
actionEntry
:
actionMap
.
entrySet
())
{
// 从 Request
o
r 中获取 Request 相关属性
Request
or
requesto
r
=
actionEntry
.
getKey
();
String
requestMethod
=
request
o
r
.
getRequestMethod
();
String
requestPath
=
request
o
r
.
getRequestPath
();
// 正则表达式
Map
<
Request
e
r
,
Handler
>
actionMap
=
ActionHelper
.
getActionMap
();
for
(
Map
.
Entry
<
Request
e
r
,
Handler
>
actionEntry
:
actionMap
.
entrySet
())
{
// 从 Request
e
r 中获取 Request 相关属性
Request
er
requeste
r
=
actionEntry
.
getKey
();
String
requestMethod
=
request
e
r
.
getRequestMethod
();
String
requestPath
=
request
e
r
.
getRequestPath
();
// 正则表达式
// 获取请求路径匹配器(使用正则表达式匹配请求路径并从中获取相应的请求参数)
Matcher
requestPathMatcher
=
Pattern
.
compile
(
requestPath
).
matcher
(
currentRequestPath
);
// 判断请求方法与请求路径是否同时匹配
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录