Skip to content

Commit 9cc8c3d

Browse files
author
vison.cao
committed
push
0 parents  commit 9cc8c3d

39 files changed

+1695
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target
2+
tomcat.*
3+
nb-configuration.xml

pom.xml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.vison.webmvc</groupId>
6+
<artifactId>web-mvc</artifactId>
7+
<packaging>war</packaging>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
13+
<maven.compiler.source>11</maven.compiler.source>
14+
<maven.compiler.target>11</maven.compiler.target>
15+
<java.version>11</java.version>
16+
<tomcat.version>9.0.26</tomcat.version>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>com.google.code.gson</groupId>
22+
<artifactId>gson</artifactId>
23+
<version>2.8.6</version>
24+
<type>jar</type>
25+
</dependency>
26+
<dependency>
27+
<groupId>javax.websocket</groupId>
28+
<artifactId>javax.websocket-api</artifactId>
29+
<version>1.1</version>
30+
<scope>provided</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.apache.tomcat.embed</groupId>
34+
<artifactId>tomcat-embed-core</artifactId>
35+
<version>${tomcat.version}</version>
36+
<scope>compile</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.apache.tomcat.embed</groupId>
40+
<artifactId>tomcat-embed-jasper</artifactId>
41+
<version>${tomcat.version}</version>
42+
<scope>compile</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.apache.logging.log4j</groupId>
46+
<artifactId>log4j-core</artifactId>
47+
<version>2.12.0</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.apache.logging.log4j</groupId>
51+
<artifactId>log4j-api</artifactId>
52+
<version>2.12.0</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.apache.tomcat</groupId>
56+
<artifactId>tomcat-websocket</artifactId>
57+
<version>${tomcat.version}</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.apache.tomcat.embed</groupId>
61+
<artifactId>tomcat-embed-el</artifactId>
62+
<version>${tomcat.version}</version>
63+
<scope>compile</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.reflections</groupId>
67+
<artifactId>reflections</artifactId>
68+
<version>0.9.12</version>
69+
</dependency>
70+
<dependency>
71+
<groupId>io.pebbletemplates</groupId>
72+
<artifactId>pebble</artifactId>
73+
<version>3.1.4</version>
74+
</dependency>
75+
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
76+
<dependency>
77+
<groupId>javax.persistence</groupId>
78+
<artifactId>javax.persistence-api</artifactId>
79+
<version>2.2</version>
80+
<scope>compile</scope>
81+
</dependency>
82+
<dependency>
83+
<groupId>mysql</groupId>
84+
<artifactId>mysql-connector-java</artifactId>
85+
<version>8.0.8-dmr</version>
86+
</dependency>
87+
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
88+
<dependency>
89+
<groupId>org.mybatis</groupId>
90+
<artifactId>mybatis</artifactId>
91+
<version>3.5.6</version>
92+
</dependency>
93+
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
94+
<dependency>
95+
<groupId>org.hibernate</groupId>
96+
<artifactId>hibernate-core</artifactId>
97+
<version>5.4.27.Final</version>
98+
</dependency>
99+
100+
<dependency>
101+
<groupId>javax.xml.bind</groupId>
102+
<artifactId>jaxb-api</artifactId>
103+
<version>2.3.0</version>
104+
</dependency>
105+
<dependency>
106+
<groupId>com.sun.activation</groupId>
107+
<artifactId>javax.activation</artifactId>
108+
<version>1.2.0</version>
109+
</dependency>
110+
<!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
111+
<dependency>
112+
<groupId>org.glassfish.jaxb</groupId>
113+
<artifactId>jaxb-runtime</artifactId>
114+
<version>2.3.3</version>
115+
</dependency>
116+
<!-- https://mvnrepository.com/artifact/antlr/antlr -->
117+
<dependency>
118+
<groupId>antlr</groupId>
119+
<artifactId>antlr</artifactId>
120+
<version>2.7.7</version>
121+
</dependency>
122+
<!-- https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy -->
123+
<dependency>
124+
<groupId>net.bytebuddy</groupId>
125+
<artifactId>byte-buddy</artifactId>
126+
<version>1.10.17</version>
127+
</dependency>
128+
129+
</dependencies>
130+
131+
<build>
132+
<finalName>webmvc</finalName>
133+
</build>
134+
</project>

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.vison.webmvc;
2+
3+
import java.io.File;
4+
import org.apache.catalina.Context;
5+
import org.apache.catalina.WebResourceRoot;
6+
import org.apache.catalina.startup.Tomcat;
7+
import org.apache.catalina.webresources.DirResourceSet;
8+
import org.apache.catalina.webresources.StandardRoot;
9+
import org.apache.logging.log4j.LogManager;
10+
import org.apache.logging.log4j.Logger;
11+
12+
/**
13+
*
14+
* @author vison.cao <visonforcoding@gmail.com>
15+
*/
16+
public class Application {
17+
18+
private static final Logger log = LogManager.getLogger(Application.class);
19+
20+
/**
21+
* @param args the command line arguments
22+
*/
23+
public static void main(String[] args) throws Exception {
24+
// 启动Tomcat:
25+
Tomcat tomcat = new Tomcat();
26+
tomcat.setPort(Integer.getInteger("port", 8081));
27+
log.info("hello");
28+
log.info("server run in http://localhost:8081");
29+
tomcat.getConnector();
30+
// 创建webapp:
31+
Context ctx = tomcat.addWebapp("", new File("src/main/webapp").getAbsolutePath());
32+
WebResourceRoot resources = new StandardRoot(ctx);
33+
resources.addPreResources(
34+
new DirResourceSet(resources, "/WEB-INF/classes", new File("target/classes").getAbsolutePath(), "/"));
35+
ctx.setResources(resources);
36+
tomcat.start();
37+
tomcat.getServer().await();
38+
}
39+
40+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.vison.webmvc;
2+
3+
/**
4+
*
5+
* @author vison.cao <visonforcoding@gmail.com>
6+
*/
7+
import com.vison.webmvc.config.App;
8+
import java.util.Optional;
9+
import java.util.HashMap;
10+
11+
/**
12+
*
13+
* @author vison.cao <visonforcoding@gmail.com>
14+
*/
15+
public class Response {
16+
17+
private int code;
18+
private String msg;
19+
private Object data;
20+
private String _uniq_req_no = App._uniq_req_no;
21+
22+
public Response(int code, String msg, Object data) {
23+
this.code = code;
24+
this.msg = msg;
25+
this.data = data;
26+
if (data == null) {
27+
this.data = new HashMap<>();
28+
}
29+
if (data instanceof Optional) {
30+
Optional d = (Optional) data;
31+
if (!d.isPresent()) {
32+
this.data = new HashMap();
33+
}
34+
}
35+
}
36+
37+
public Response(int code, String msg) {
38+
this.code = code;
39+
this.msg = msg;
40+
Object d = new HashMap<>();
41+
this.data = d;
42+
}
43+
44+
public void setCode(int code) {
45+
this.code = code;
46+
}
47+
48+
public void setMsg(String msg) {
49+
this.msg = msg;
50+
}
51+
52+
public void setData(Object data) {
53+
this.data = data;
54+
}
55+
56+
public int getCode() {
57+
return code;
58+
}
59+
60+
public String getMsg() {
61+
return msg;
62+
}
63+
64+
public Object getData() {
65+
return data;
66+
}
67+
68+
public String getUniq_req_no() {
69+
return App._uniq_req_no;
70+
}
71+
72+
public void setUniq_req_no(String _uniq_req_no) {
73+
this._uniq_req_no = _uniq_req_no;
74+
}
75+
76+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.vison.webmvc;
7+
8+
/**
9+
*
10+
* @author vison.cao <visonforcoding@gmail.com>
11+
*/
12+
public class ResponseCode {
13+
14+
public static Integer success = 0;
15+
public static Integer dbInsertFail = 101;
16+
public static Integer parametrErrror = 510;
17+
18+
/**
19+
* 未登录
20+
*/
21+
public static Integer unLogin = 401;
22+
23+
public static Integer loginFail = 402;
24+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.vison.webmvc;
2+
3+
import java.lang.reflect.Method;
4+
5+
/**
6+
*
7+
* @author vison.cao <visonforcoding@gmail.com>
8+
*/
9+
public class Test {
10+
11+
public static void main(String[] args) throws Exception {
12+
Class stdClass = Student.class;
13+
Method method = stdClass.getMethod("getScore", String.class);
14+
Object obj = stdClass.getDeclaredConstructor().newInstance();
15+
System.out.print(method.invoke(obj, "888"));
16+
}
17+
18+
}
19+
20+
class Student extends Person {
21+
22+
public int getScore(String type) {
23+
return 99;
24+
}
25+
26+
private int getGrade(int year) {
27+
return 1;
28+
}
29+
}
30+
31+
class Person {
32+
33+
public String getName() {
34+
return "Person";
35+
}
36+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.vison.webmvc;
2+
3+
import com.vison.webmvc.entity.User;
4+
import com.vison.webmvc.framework.HibernateLoader;
5+
import org.hibernate.Session;
6+
import org.hibernate.Transaction;
7+
8+
/**
9+
*
10+
* @author vison.cao <visonforcoding@gmail.com>
11+
*/
12+
public class TestHibernate {
13+
14+
/**
15+
* @param args the command line arguments
16+
*/
17+
public static void main(String[] args) {
18+
// TODO code application logic here
19+
Transaction transaction = null;
20+
try (Session session = HibernateLoader.getSessionFactory().openSession()) {
21+
// start a transaction
22+
transaction = session.beginTransaction();
23+
User user = new User();
24+
user.setName("vison");
25+
user.setEmail("visonforcoding@gmail.com");
26+
user.setCountry("赛德克巴莱");
27+
// save the student object
28+
session.save(user);
29+
// commit transaction
30+
transaction.commit();
31+
session.close();
32+
} catch (Exception e) {
33+
if (transaction != null) {
34+
transaction.rollback();
35+
}
36+
e.printStackTrace();
37+
}
38+
}
39+
40+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.vison.webmvc.config;
2+
3+
import org.reflections.Reflections;
4+
5+
/**
6+
*
7+
* @author vison.cao <visonforcoding@gmail.com>
8+
*/
9+
public class App {
10+
11+
public static final String SESSION_USER = "user"; // 用户对象
12+
public static String _uniq_req_no = null;
13+
public static String OrderNoIncKey = ":order:no";
14+
public static Reflections f;
15+
}

0 commit comments

Comments
 (0)