Skip to content

Commit 02c1dd0

Browse files
committed
Server:新增JFinal版的Demo工程 APIJSONFinal
1 parent d2d24f3 commit 02c1dd0

File tree

24 files changed

+2407
-1
lines changed

24 files changed

+2407
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# maven #
2+
target
3+
4+
logs
5+
6+
# eclipse #
7+
.settings
8+
.project
9+
.classpath
10+
.log
11+
12+
# windows #
13+
Thumbs.db
14+
15+
# Mac #
16+
.DS_Store
17+
18+
# Package Files #
19+
*.war
20+
*.ear
21+
22+
# idea #
23+
.idea
24+
*.iml
25+
26+
plan.txt
27+
28+
*.class
29+
30+
# Package Files #
31+
*.jar
32+
33+
34+
*.bak
35+
*.tmp
36+
*.log
37+
/bin/
38+
build.sh
39+
integration-repo
40+
/build/
41+
42+
# IDEA metadata and output dirs
43+
*.ipr
44+
*.iws
45+
46+
/webapp/WEB-INF/classes/
47+
/webapp/WEB-INF/test-classes/
48+
/webapp/WEB-INF/target/
49+
50+
a_little_config_pro.txt
51+
52+
dev_plan.txt
53+
54+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
#### 说明
3+
4+
关于项目需求定义, 请参考 https://gitee.com/how-to-do-it/hello-world/issues
5+
6+
#### 运行应用
7+
8+
打包
9+
10+
```
11+
mvn clean package
12+
```
13+
14+
运行
15+
16+
```
17+
java -jar helloworld.jar
18+
19+
在浏览器输入 localhost 即可访问
20+
```
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>htdi.jfinal</groupId>
5+
<artifactId>apijson-final</artifactId>
6+
<packaging>jar</packaging>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<name>APIJSON Demo based on JFinal</name>
9+
<url>http://maven.apache.org</url>
10+
<dependencies>
11+
12+
<dependency>
13+
<groupId>junit</groupId>
14+
<artifactId>junit</artifactId>
15+
<version>4.0</version>
16+
<scope>test</scope>
17+
</dependency>
18+
19+
<dependency>
20+
<groupId>com.jfinal</groupId>
21+
<artifactId>jfinal-undertow</artifactId>
22+
<version>1.4</version>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>com.jfinal</groupId>
27+
<artifactId>jfinal</artifactId>
28+
<version>3.5</version>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>mysql</groupId>
33+
<artifactId>mysql-connector-java</artifactId>
34+
<version>5.1.40</version>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>com.alibaba</groupId>
39+
<artifactId>fastjson</artifactId>
40+
<version>1.2.21</version>
41+
</dependency>
42+
43+
<!-- dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId>
44+
<version>1.2.16</version> </dependency -->
45+
</dependencies>
46+
<build>
47+
<!-- <finalName>helloworld</finalName> -->
48+
49+
<plugins>
50+
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-compiler-plugin</artifactId>
54+
<version>3.6.1</version>
55+
<configuration>
56+
<source>1.8</source>
57+
<target>1.8</target>
58+
<encoding>UTF-8</encoding>
59+
<!-- java8 保留参数名编译参数 -->
60+
<compilerArgument>-parameters</compilerArgument>
61+
<compilerArguments>
62+
<verbose />
63+
</compilerArguments>
64+
</configuration>
65+
</plugin>
66+
67+
<!-- 当项目的 web 资源在 src/main/webapp 下时,需要使用 maven-resources-plugin 将 web
68+
资源复制到 jar 包中去,注意打包的时候需要配置 engine: me.setBaseTemplatePath("webapp"); me.setToClassPathSourceFactory();
69+
如果 web 资源本身就放在 src/main/resources/webapp 之下,则不需要此插件 -->
70+
<plugin>
71+
<artifactId>maven-resources-plugin</artifactId>
72+
<version>3.1.0</version>
73+
<executions>
74+
<execution>
75+
<id>copy-webapp</id>
76+
<phase>process-sources</phase>
77+
<goals>
78+
<goal>copy-resources</goal>
79+
</goals>
80+
<configuration>
81+
<encoding>UTF-8</encoding>
82+
<outputDirectory>${basedir}/target/classes/webapp</outputDirectory>
83+
<resources>
84+
<resource>
85+
<directory>${basedir}/src/main/webapp</directory>
86+
<includes>
87+
<!-- <include>**/*.xml</include> -->
88+
<!-- <include>**/**</include> -->
89+
</includes>
90+
</resource>
91+
</resources>
92+
</configuration>
93+
</execution>
94+
</executions>
95+
</plugin>
96+
97+
<plugin>
98+
<groupId>org.apache.maven.plugins</groupId>
99+
<artifactId>maven-shade-plugin</artifactId>
100+
<version>3.2.1</version>
101+
<executions>
102+
<execution>
103+
<phase>package</phase>
104+
<goals>
105+
<goal>shade</goal>
106+
</goals>
107+
<configuration>
108+
<finalName>helloworld</finalName>
109+
<transformers>
110+
<transformer
111+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
112+
<mainClass>apijson.demo.server.AppRunnableConfig</mainClass>
113+
</transformer>
114+
115+
<!-- 下面的配置支持排除指定文件打包到 jar 之中,可以用于排除需要修改的配置文件以便于在外部的 config 目录下的 同名配置文件生效,建议使用
116+
Prop.appendIfExists(xxx_pro.txt) 在外部放一个非同名配置来覆盖开发环境的配置 则可以不用使用下面的配置,文档参考:
117+
http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#DontIncludeResourceTransformer -->
118+
<transformer
119+
implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
120+
<resources>
121+
<!-- <resource>jfinal-club-config-dev.txt</resource> -->
122+
<!-- <resource>.PDF</resource> -->
123+
<!-- <resource>READ.me</resource> -->
124+
</resources>
125+
</transformer>
126+
</transformers>
127+
</configuration>
128+
</execution>
129+
</executions>
130+
</plugin>
131+
132+
</plugins>
133+
</build>
134+
</project>
135+
136+
137+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package apijson.demo.server;
2+
3+
import com.jfinal.config.Constants;
4+
import com.jfinal.config.Handlers;
5+
import com.jfinal.config.Interceptors;
6+
import com.jfinal.config.JFinalConfig;
7+
import com.jfinal.config.Plugins;
8+
import com.jfinal.config.Routes;
9+
import com.jfinal.server.undertow.UndertowServer;
10+
import com.jfinal.template.Engine;
11+
12+
public class AppRunnableConfig extends JFinalConfig {
13+
14+
public static void main(String[] args) {
15+
UndertowServer.start(AppRunnableConfig.class);
16+
}
17+
18+
public void configRoute(Routes me) {
19+
me.add("/", Controller.class);
20+
}
21+
22+
public void configEngine(Engine me) {
23+
me.setBaseTemplatePath("webapp").setToClassPathSourceFactory();
24+
}
25+
26+
public void configConstant(Constants me) {}
27+
public void configPlugin(Plugins me) {}
28+
public void configInterceptor(Interceptors me) {}
29+
public void configHandler(Handlers me) {}
30+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package apijson.demo.server;
2+
3+
import static zuo.biao.apijson.RequestMethod.GET;
4+
5+
import com.jfinal.kit.HttpKit;
6+
7+
import apijson.demo.server.model.Privacy;
8+
import apijson.demo.server.model.User;
9+
import apijson.demo.server.model.Verify;
10+
import zuo.biao.apijson.JSONResponse;
11+
import zuo.biao.apijson.RequestMethod;
12+
import zuo.biao.apijson.server.JSONRequest;
13+
14+
public class Controller extends com.jfinal.core.Controller {
15+
16+
//通用接口,非事务型操作 和 简单事务型操作 都可通过这些接口自动化实现<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
17+
18+
19+
/**获取
20+
* @param request 只用String,避免encode后未decode
21+
* @param session
22+
* @return
23+
* @see {@link RequestMethod#GET}
24+
*/
25+
public void get() {
26+
renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest())));
27+
}
28+
29+
/**计数
30+
* @param request 只用String,避免encode后未decode
31+
* @param session
32+
* @return
33+
* @see {@link RequestMethod#HEAD}
34+
*/
35+
public void head() {
36+
renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest())));
37+
}
38+
39+
/**限制性GET,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求
40+
* @param request 只用String,避免encode后未decode
41+
* @param session
42+
* @return
43+
* @see {@link RequestMethod#GETS}
44+
*/
45+
public void gets() {
46+
renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest())));
47+
}
48+
49+
/**限制性HEAD,request和response都非明文,浏览器看不到,用于对安全性要求高的HEAD请求
50+
* @param request 只用String,避免encode后未decode
51+
* @param session
52+
* @return
53+
* @see {@link RequestMethod#HEADS}
54+
*/
55+
public void heads() {
56+
renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest())));
57+
}
58+
59+
/**新增
60+
* @param request 只用String,避免encode后未decode
61+
* @param session
62+
* @return
63+
* @see {@link RequestMethod#POST}
64+
*/
65+
public void post() {
66+
renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest())));
67+
}
68+
69+
/**修改
70+
* @param request 只用String,避免encode后未decode
71+
* @param session
72+
* @return
73+
* @see {@link RequestMethod#PUT}
74+
*/
75+
public void put() {
76+
renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest())));
77+
}
78+
79+
/**删除
80+
* @param request 只用String,避免encode后未decode
81+
* @param session
82+
* @return
83+
* @see {@link RequestMethod#DELETE}
84+
*/
85+
public void delete() {
86+
renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest())));
87+
}
88+
89+
90+
//通用接口,非事务型操作 和 简单事务型操作 都可通过这些接口自动化实现>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
91+
92+
93+
94+
public static final String USER_;
95+
public static final String PRIVACY_;
96+
public static final String VERIFY_; //加下划线后缀是为了避免 Verify 和 verify 都叫VERIFY,分不清
97+
static {
98+
USER_ = User.class.getSimpleName();
99+
PRIVACY_ = Privacy.class.getSimpleName();
100+
VERIFY_ = Verify.class.getSimpleName();
101+
}
102+
103+
public static final String VERSION = JSONRequest.KEY_VERSION;
104+
public static final String FORMAT = JSONRequest.KEY_FORMAT;
105+
public static final String COUNT = JSONResponse.KEY_COUNT;
106+
public static final String TOTAL = JSONResponse.KEY_TOTAL;
107+
108+
public static final String ID = "id";
109+
public static final String USER_ID = "userId";
110+
public static final String CURRENT_USER_ID = "currentUserId";
111+
112+
public static final String NAME = "name";
113+
public static final String PHONE = "phone";
114+
public static final String PASSWORD = "password";
115+
public static final String _PASSWORD = "_password";
116+
public static final String _PAY_PASSWORD = "_payPassword";
117+
public static final String OLD_PASSWORD = "oldPassword";
118+
public static final String VERIFY = "verify";
119+
120+
public static final String TYPE = "type";
121+
122+
}

0 commit comments

Comments
 (0)