diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/.gitignore b/APIJSON-Java-Server/APIJSONDemo_oracle/.gitignore new file mode 100644 index 000000000..b83d22266 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/apijson-demo.iml b/APIJSON-Java-Server/APIJSONDemo_oracle/apijson-demo.iml new file mode 100644 index 000000000..e34a907a0 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/apijson-demo.iml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/libs/apijson-library-2.1.0-SNAPSHOT.jar b/APIJSON-Java-Server/APIJSONDemo_oracle/libs/apijson-library-2.1.0-SNAPSHOT.jar new file mode 100644 index 000000000..126e51725 Binary files /dev/null and b/APIJSON-Java-Server/APIJSONDemo_oracle/libs/apijson-library-2.1.0-SNAPSHOT.jar differ diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/libs/postgresql-42.2.4.jar b/APIJSON-Java-Server/APIJSONDemo_oracle/libs/postgresql-42.2.4.jar new file mode 100644 index 000000000..4f747bea0 Binary files /dev/null and b/APIJSON-Java-Server/APIJSONDemo_oracle/libs/postgresql-42.2.4.jar differ diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/pom.xml b/APIJSON-Java-Server/APIJSONDemo_oracle/pom.xml new file mode 100644 index 000000000..be41cf7f1 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/pom.xml @@ -0,0 +1,110 @@ + + + 4.0.0 + + apijson.demo.server + apijson-demo + 2.1.0-SNAPSHOT + jar + + APIJSONDemo + Demo project for APIJSON Server + + + org.springframework.boot + spring-boot-starter-parent + 1.4.1.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.jyaml + jyaml + 1.3 + + + + ojdbc6 + ojdbc6 + 1.0 + + + + + + + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba + fastjson + 1.2.21 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + + + spring-snapshots + http://repo.spring.io/snapshot + true + + + spring-milestones + http://repo.spring.io/milestone + true + + + + + spring-snapshots + http://repo.spring.io/snapshot + + + spring-milestones + http://repo.spring.io/milestone + + + + diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/APIJSONApplication.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/APIJSONApplication.java new file mode 100644 index 000000000..55a555eed --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/APIJSONApplication.java @@ -0,0 +1,53 @@ +package apijson.demo.server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + + +/**application + * @author Lemon + */ +@SpringBootApplication +public class APIJSONApplication { + + public static void main(String[] args) throws Exception { + SpringApplication.run(APIJSONApplication.class, args); + System.out.println("\n\n\n\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON >>>>>>>>>>>>>>>>>>>>>>>>\n"); + System.out.println("开始测试:远程函数 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); + System.out.println("\n完成测试:远程函数 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + System.out.println("\n\n\n开始测试:请求校验 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); + System.out.println("\n完成测试:请求校验 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + System.out.println("\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON已启动 >>>>>>>>>>>>>>>>>>>>>>>>\n"); + } + + + + //支持JavaScript跨域请求<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /** + * 跨域过滤器 + * @return + */ + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } + /**CORS跨域配置 + * @return + */ + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + corsConfiguration.addAllowedOrigin("*"); //允许的域名或IP地址 + corsConfiguration.addAllowedHeader("*"); //允许的请求头 + corsConfiguration.addAllowedMethod("*"); //允许的HTTP请求方法 + corsConfiguration.setAllowCredentials(true); //允许发送跨域凭据,前端Axios存取JSESSIONID必须要 + return corsConfiguration; + } + //支持JavaScript跨域请求 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/Controller.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/Controller.java new file mode 100644 index 000000000..2dec3b670 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/Controller.java @@ -0,0 +1,861 @@ +package apijson.demo.server; + +import static zuo.biao.apijson.RequestMethod.DELETE; +import static zuo.biao.apijson.RequestMethod.GET; +import static zuo.biao.apijson.RequestMethod.GETS; +import static zuo.biao.apijson.RequestMethod.HEAD; +import static zuo.biao.apijson.RequestMethod.HEADS; +import static zuo.biao.apijson.RequestMethod.POST; +import static zuo.biao.apijson.RequestMethod.PUT; + +import java.net.URLDecoder; +import java.util.Random; +import java.util.concurrent.TimeoutException; + +import javax.servlet.http.HttpSession; + +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.alibaba.fastjson.JSONObject; + +import apijson.demo.server.model.BaseModel; +import apijson.demo.server.model.Comment; +import apijson.demo.server.model.Moment; +import apijson.demo.server.model.Privacy; +import apijson.demo.server.model.User; +import apijson.demo.server.model.Verify; +import zuo.biao.apijson.JSON; +import zuo.biao.apijson.JSONResponse; +import zuo.biao.apijson.Log; +import zuo.biao.apijson.RequestMethod; +import zuo.biao.apijson.StringUtil; +import zuo.biao.apijson.server.JSONRequest; +import zuo.biao.apijson.server.exception.ConditionErrorException; +import zuo.biao.apijson.server.exception.ConflictException; +import zuo.biao.apijson.server.exception.NotExistException; +import zuo.biao.apijson.server.exception.OutOfRangeException; + + +/**request controller + *
建议全通过HTTP POST来请求: + *
1.减少代码 - 客户端无需写HTTP GET,PUT等各种方式的请求代码 + *
2.提高性能 - 无需URL encode和decode + *
3.调试方便 - 建议使用 APIJSON在线测试工具 或 Postman + * @author Lemon + */ +@RestController +@RequestMapping("") +public class Controller { + private static final String TAG = "Controller"; + + //通用接口,非事务型操作 和 简单事务型操作 都可通过这些接口自动化实现<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**获取 + * @param request 只用String,避免encode后未decode + * @param session + * @return + * @see {@link RequestMethod#GET} + */ + @PostMapping(value = "get") + public String get(@RequestBody String request, HttpSession session) { + return new DemoParser(GET).setSession(session).parse(request); + } + + /**计数 + * @param request 只用String,避免encode后未decode + * @param session + * @return + * @see {@link RequestMethod#HEAD} + */ + @PostMapping("head") + public String head(@RequestBody String request, HttpSession session) { + return new DemoParser(HEAD).setSession(session).parse(request); + } + + /**限制性GET,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求 + * @param request 只用String,避免encode后未decode + * @param session + * @return + * @see {@link RequestMethod#GETS} + */ + @PostMapping("gets") + public String gets(@RequestBody String request, HttpSession session) { + return new DemoParser(GETS).setSession(session).parse(request); + } + + /**限制性HEAD,request和response都非明文,浏览器看不到,用于对安全性要求高的HEAD请求 + * @param request 只用String,避免encode后未decode + * @param session + * @return + * @see {@link RequestMethod#HEADS} + */ + @PostMapping("heads") + public String heads(@RequestBody String request, HttpSession session) { + return new DemoParser(HEADS).setSession(session).parse(request); + } + + /**新增 + * @param request 只用String,避免encode后未decode + * @param session + * @return + * @see {@link RequestMethod#POST} + */ + @PostMapping("post") + public String post(@RequestBody String request, HttpSession session) { + return new DemoParser(POST,true).setSession(session).parse(request); + } + + /**修改 + * @param request 只用String,避免encode后未decode + * @param session + * @return + * @see {@link RequestMethod#PUT} + */ + @PostMapping("put") + public String put(@RequestBody String request, HttpSession session) { + return new DemoParser(PUT,true).setSession(session).parse(request); + } + + /**删除 + * @param request 只用String,避免encode后未decode + * @param session + * @return + * @see {@link RequestMethod#DELETE} + */ + @PostMapping("delete") + public String delete(@RequestBody String request, HttpSession session) { + return new DemoParser(DELETE,true).setSession(session).parse(request); + } + + + /**获取 + * 只为兼容HTTP GET请求,推荐用HTTP POST,可删除 + * @param request 只用String,避免encode后未decode + * @param session + * @return + * @see {@link RequestMethod#GET} + */ + @RequestMapping("get/{request}") + public String openGet(@PathVariable String request, HttpSession session) { + try { + request = URLDecoder.decode(request, StringUtil.UTF_8); + } catch (Exception e) { + // Parser会报错 + } + return get(request, session); + } + + /**计数 + * 只为兼容HTTP GET请求,推荐用HTTP POST,可删除 + * @param request 只用String,避免encode后未decode + * @param session + * @return + * @see {@link RequestMethod#HEAD} + */ + @RequestMapping("head/{request}") + public String openHead(@PathVariable String request, HttpSession session) { + try { + request = URLDecoder.decode(request, StringUtil.UTF_8); + } catch (Exception e) { + // Parser会报错 + } + return head(request, session); + } + + + //通用接口,非事务型操作 和 简单事务型操作 都可通过这些接口自动化实现>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + + + + + + + + + + + public static final String USER_; + public static final String PRIVACY_; + public static final String MOMENT_; + public static final String COMMENT_; + public static final String VERIFY_; //加下划线后缀是为了避免 Verify 和 verify 都叫VERIFY,分不清 + static { + USER_ = User.class.getSimpleName(); + PRIVACY_ = Privacy.class.getSimpleName(); + MOMENT_ = Moment.class.getSimpleName(); + COMMENT_ = Comment.class.getSimpleName(); + VERIFY_ = Verify.class.getSimpleName(); + } + + public static final String VERSION = JSONRequest.KEY_VERSION; + public static final String COUNT = JSONResponse.KEY_COUNT; + public static final String TOTAL = JSONResponse.KEY_TOTAL; + + public static final String RANGE = "range"; + + public static final String ID = "id"; + public static final String USER_ID = "userId"; + public static final String CURRENT_USER_ID = "currentUserId"; + + public static final String NAME = "name"; + public static final String PHONE = "phone"; + public static final String PASSWORD = "password"; + public static final String _PASSWORD = "_password"; + public static final String _PAY_PASSWORD = "_payPassword"; + public static final String OLD_PASSWORD = "oldPassword"; + public static final String VERIFY = "verify"; + + public static final String SEX = "sex"; + public static final String TYPE = "type"; + public static final String WAY = "way"; + public static final String CONTENT = "content"; + + + + + + public static final String DATE_UP = "date+";//同 "date ASC" + public static final String DATE_DOWN = "date-";//同 "date DESC" + + public static final String ID_AT = ID + "@"; + public static final String USER_ID_AT = USER_ID + "@"; + public static final String MOMENT_ID_AT = "momentId@"; + public static final String COMMENT_ID_AT = "commentId@"; + + public static final String ID_IN = ID + "{}"; + public static final String USER_ID_IN = USER_ID + "{}"; + public static final String MOMENT_ID_IN = "momentId{}"; + public static final String COMMENT_ID_IN = "commentId{}"; + + public static final String NAME_SEARCH = NAME + "$"; + public static final String PHONE_SEARCH = PHONE + "$"; + public static final String CONTENT_SEARCH = CONTENT + "$"; + + + + public static final String COLUMNS_USER_SIMPLE = "id,name"; + public static final String COLUMNS_USER = "id,sex,name,head"; + + + + + /**生成验证码,修改为post请求 + * @param request + * @return + */ + @PostMapping("post/verify") + public JSONObject postVerify(@RequestBody String request) { + JSONObject requestObject = null; + int type; + String phone; + try { + requestObject = DemoParser.parseRequest(request); + type = requestObject.getIntValue(TYPE); + phone = requestObject.getString(PHONE); + } catch (Exception e) { + return DemoParser.extendErrorResult(requestObject, e); + } + + new DemoParser(DELETE, true).parse(newVerifyRequest(type, phone, null)); + + JSONObject response = new DemoParser(POST, true).parseResponse( + newVerifyRequest(type, phone, "" + (new Random().nextInt(9999) + 1000))); + + JSONObject verify = null; + try { + verify = response.getJSONObject(VERIFY_); + } catch (Exception e) { + // TODO: handle exception + } + if (verify == null || JSONResponse.isSuccess(verify.getIntValue(JSONResponse.KEY_CODE)) == false) { + new DemoParser(DELETE, true).parseResponse(new JSONRequest(new Verify(type, phone))); + return response; + } + + //TODO 这里直接返回验证码,方便测试。实际上应该只返回成功信息,验证码通过短信发送 + JSONObject object = new JSONObject(); + object.put(TYPE, type); + object.put(PHONE, phone); + return getVerify(JSON.toJSONString(object)); + } + + /**获取验证码 + * @param request + * @return + */ + @PostMapping("gets/verify") + public JSONObject getVerify(@RequestBody String request) { + JSONObject requestObject = null; + int type; + String phone; + try { + requestObject = DemoParser.parseRequest(request); + type = requestObject.getIntValue(TYPE); + phone = requestObject.getString(PHONE); + } catch (Exception e) { + return DemoParser.extendErrorResult(requestObject, e); + } + return new DemoParser(GETS, true).parseResponse(newVerifyRequest(type, phone, null)); + } + + /**校验验证码 + * @param request + * @return + */ + @PostMapping("heads/verify") + public JSONObject headVerify(@RequestBody String request) { + JSONObject requestObject = null; + int type; + String phone; + String verify; + try { + requestObject = DemoParser.parseRequest(request); + type = requestObject.getIntValue(TYPE); + phone = requestObject.getString(PHONE); + verify = requestObject.getString(VERIFY); + } catch (Exception e) { + return DemoParser.extendErrorResult(requestObject, e); + } + return headVerify(type, phone, verify); + } + + /**校验验证码 + * @author Lemon + * @param type + * @param phone + * @param code + * @return + */ + public JSONObject headVerify(int type, String phone, String code) { + JSONResponse response = new JSONResponse( + new DemoParser(GETS, true).parseResponse( + new JSONRequest( + new Verify(type, phone) + .setVerify(code) + ).setTag(VERIFY_) + ) + ); + Verify verify = response.getObject(Verify.class); + if (verify == null) { + return DemoParser.newErrorResult(StringUtil.isEmpty(code, true) + ? new NotExistException("验证码不存在!") : new ConditionErrorException("手机号或验证码错误!")); + } + + //验证码过期 + long time = BaseModel.getTimeMillis(verify.getDate()); + long now = System.currentTimeMillis(); + if (now > 60*1000 + time) { + new DemoParser(DELETE, true).parseResponse( + new JSONRequest(new Verify(type, phone)).setTag(VERIFY_) + ); + return DemoParser.newErrorResult(new TimeoutException("验证码已过期!")); + } + + return new JSONResponse( + new DemoParser(HEADS, true).parseResponse( + new JSONRequest(new Verify(type, phone).setVerify(code)) + ) + ); + } + + + + /**新建一个验证码请求 + * @param phone + * @param verify + * @return + */ + private JSONObject newVerifyRequest(int type, String phone, String verify) { + return new JSONRequest(new Verify(type, phone).setVerify(verify)).setTag(VERIFY_); + } + + + public static final String LOGIN = "login"; + + public static final int LOGIN_TYPE_PASSWORD = 0;//密码登录 + public static final int LOGIN_TYPE_VERIFY = 1;//验证码登录 + /**用户登录 + * @param request 只用String,避免encode后未decode + * @return + * @see + *
+		{
+			"type": 0,  //登录方式,非必须  0-密码 1-验证码
+			"phone": "13000082001",
+			"password": "1234567",
+			"version": 1 //全局版本号,非必须
+		}
+	 * 
+ */ + @PostMapping(LOGIN) + public JSONObject login(@RequestBody String request, HttpSession session) { + JSONObject requestObject = null; + boolean isPassword; + String phone; + String password; + int version; + try { + requestObject = DemoParser.parseRequest(request); + + isPassword = requestObject.getIntValue(TYPE) == LOGIN_TYPE_PASSWORD;//登录方式 + phone = requestObject.getString(PHONE);//手机 + password = requestObject.getString(PASSWORD);//密码 + + if (StringUtil.isPhone(phone) == false) { + throw new IllegalArgumentException("手机号不合法!"); + } + + if (isPassword) { + if (StringUtil.isPassword(password) == false) { + throw new IllegalArgumentException("密码不合法!"); + } + } else { + if (StringUtil.isVerify(password) == false) { + throw new IllegalArgumentException("验证码不合法!"); + } + } + + //全局版本号 + version = requestObject.getIntValue(VERSION); + requestObject.remove(VERSION); + } catch (Exception e) { + return DemoParser.extendErrorResult(requestObject, e); + } + + + + //手机号是否已注册 + JSONObject phoneResponse = new DemoParser(HEADS, true).parseResponse( + new JSONRequest( + new Privacy().setPhone(phone) + ) + ); + JSONResponse response = new JSONResponse(phoneResponse).getJSONResponse(PRIVACY_); + if (JSONResponse.isSuccess(response) == false) { + return response; + } + if(JSONResponse.isExist(response) == false) { + return DemoParser.newErrorResult(new NotExistException("手机号未注册")); + } + + //根据phone获取User + JSONObject privacyResponse = new DemoParser(GETS, true).parseResponse( + new JSONRequest( + new Privacy().setPhone(phone) + ) + ); + response = new JSONResponse(privacyResponse); + + Privacy privacy = response == null ? null : response.getObject(Privacy.class); + long userId = privacy == null ? 0 : BaseModel.value(privacy.getId()); + if (userId <= 0) { + return privacyResponse; + } + + //校验凭证 + if (isPassword) {//password密码登录 + response = new JSONResponse( + new DemoParser(HEADS, true).parseResponse( + new JSONRequest(new Privacy(userId).setPassword(password)) + ) + ); + } else {//verify手机验证码登录 + response = new JSONResponse(headVerify(Verify.TYPE_LOGIN, phone, password)); + } + if (JSONResponse.isSuccess(response) == false) { + return response; + } + response = response.getJSONResponse(isPassword ? PRIVACY_ : VERIFY_); + if (JSONResponse.isExist(response) == false) { + return DemoParser.newErrorResult(new ConditionErrorException("账号或密码错误")); + } + + response = new JSONResponse( + new DemoParser(GETS, true).parseResponse( + new JSONRequest(new User(userId)) + ) + ); + User user = new User(userId); + if (user == null || BaseModel.value(user.getId()) != userId) { + return DemoParser.newErrorResult(new NullPointerException("服务器内部错误")); + } + + //登录状态保存至session + session.setAttribute(USER_ID, userId);//用户id + session.setAttribute(TYPE, isPassword ? LOGIN_TYPE_PASSWORD : LOGIN_TYPE_VERIFY);//登录方式 + session.setAttribute(USER_, user);//用户 + session.setAttribute(PRIVACY_, privacy);//用户隐私信息 + session.setAttribute(VERSION, version);//全局默认版本号 + // session.setMaxInactiveInterval(1*60);//设置session过期时间 + + return response; + } + + /**退出登录,清空session + * @param session + * @return + */ + @PostMapping("logout") + public JSONObject logout(HttpSession session) { + long userId; + try { + userId = DemoVerifier.getVisitorId(session);//必须在session.invalidate();前! + Log.d(TAG, "logout userId = " + userId + "; session.getId() = " + (session == null ? null : session.getId())); + session.invalidate(); + } catch (Exception e) { + return DemoParser.newErrorResult(e); + } + + JSONObject result = DemoParser.newSuccessResult(); + JSONObject user = DemoParser.newSuccessResult(); + user.put(ID, userId); + user.put(COUNT, 1); + result.put(USER_, user); + + return result; + } + + + private static final String REGISTER = "register"; + /**注册 + * @param request 只用String,避免encode后未decode + * @return + * @see + *
+		{
+			"Privacy": {
+				"phone": "13000082222",
+				"_password": "123456"
+			},
+			"User": {
+				"name": "APIJSONUser"
+			},
+			"verify": "1234"
+		}
+	 * 
+ */ + @PostMapping(REGISTER) + public JSONObject register(@RequestBody String request) { + JSONObject requestObject = null; + + JSONObject privacyObj; + + String phone; + String verify; + String password; + try { + requestObject = DemoParser.parseRequest(request); + privacyObj = requestObject.getJSONObject(PRIVACY_); + + phone = StringUtil.getString(privacyObj.getString(PHONE)); + verify = requestObject.getString(VERIFY); + password = privacyObj.getString(_PASSWORD); + + if (StringUtil.isPhone(phone) == false) { + return newIllegalArgumentResult(requestObject, PRIVACY_ + "/" + PHONE); + } + if (StringUtil.isPassword(password) == false) { + return newIllegalArgumentResult(requestObject, PRIVACY_ + "/" + _PASSWORD); + } + if (StringUtil.isVerify(verify) == false) { + return newIllegalArgumentResult(requestObject, VERIFY); + } + } catch (Exception e) { + return DemoParser.extendErrorResult(requestObject, e); + } + + + JSONResponse response = new JSONResponse(headVerify(Verify.TYPE_REGISTER, phone, verify)); + if (JSONResponse.isSuccess(response) == false) { + return response; + } + //手机号或验证码错误 + if (JSONResponse.isExist(response.getJSONResponse(VERIFY_)) == false) { + return DemoParser.extendErrorResult(response, new ConditionErrorException("手机号或验证码错误!")); + } + + + + //生成User和Privacy + if (StringUtil.isEmpty(requestObject.getString(JSONRequest.KEY_TAG), true)) { + requestObject.put(JSONRequest.KEY_TAG, REGISTER); + } + response = new JSONResponse( + new DemoParser(POST).setNoVerifyLogin(true).parseResponse(requestObject) + ); + + //验证User和Privacy + User user = response.getObject(User.class); + long userId = user == null ? 0 : BaseModel.value(user.getId()); + Privacy privacy = response.getObject(Privacy.class); + long userId2 = privacy == null ? 0 : BaseModel.value(privacy.getId()); + Exception e = null; + if (userId <= 0 || userId != userId2) { //id不同 + e = new Exception("服务器内部错误!写入User或Privacy失败!"); + } + + if (e != null) { //出现错误,回退 + new DemoParser(DELETE, true).parseResponse( + new JSONRequest(new User(userId)) + ); + new DemoParser(DELETE, true).parseResponse( + new JSONRequest(new Privacy(userId2)) + ); + } + + return response; + } + + + /** + * @param requestObject + * @param key + * @return + */ + public static JSONObject newIllegalArgumentResult(JSONObject requestObject, String key) { + return newIllegalArgumentResult(requestObject, key, null); + } + /** + * @param requestObject + * @param key + * @param msg 详细说明 + * @return + */ + public static JSONObject newIllegalArgumentResult(JSONObject requestObject, String key, String msg) { + return DemoParser.extendErrorResult(requestObject + , new IllegalArgumentException(key + ":value 中value不合法!" + StringUtil.getString(msg))); + } + + + /**设置密码 + * @param request 只用String,避免encode后未decode + * @return + * @see + *
+	    使用旧密码修改
+		{
+			"oldPassword": 123456,
+			"Privacy":{
+			  "id": 13000082001,
+			  "_password": "1234567"
+			}
+		}
+		或使用手机号+验证码修改
+		{
+			"verify": "1234",
+			"Privacy":{
+			  "phone": "13000082001",
+			  "_password": "1234567"
+			}
+		}
+	 * 
+ */ + @PostMapping("put/password") + public JSONObject putPassword(@RequestBody String request){ + JSONObject requestObject = null; + String oldPassword; + String verify; + + int type = Verify.TYPE_PASSWORD; + + JSONObject privacyObj; + long userId; + String phone; + String password; + try { + requestObject = DemoParser.parseRequest(request); + oldPassword = StringUtil.getString(requestObject.getString(OLD_PASSWORD)); + verify = StringUtil.getString(requestObject.getString(VERIFY)); + + requestObject.remove(OLD_PASSWORD); + requestObject.remove(VERIFY); + + privacyObj = requestObject.getJSONObject(PRIVACY_); + if (privacyObj == null) { + throw new IllegalArgumentException(PRIVACY_ + " 不能为空!"); + } + userId = privacyObj.getLongValue(ID); + phone = privacyObj.getString(PHONE); + password = privacyObj.getString(_PASSWORD); + + if (StringUtil.isEmpty(password, true)) { //支付密码 + type = Verify.TYPE_PAY_PASSWORD; + password = privacyObj.getString(_PAY_PASSWORD); + if (StringUtil.isNumberPassword(password) == false) { + throw new IllegalArgumentException(PRIVACY_ + "/" + _PAY_PASSWORD + ":value 中value不合法!"); + } + } else { //登录密码 + if (StringUtil.isPassword(password) == false) { + throw new IllegalArgumentException(PRIVACY_ + "/" + _PASSWORD + ":value 中value不合法!"); + } + } + } catch (Exception e) { + return DemoParser.extendErrorResult(requestObject, e); + } + + + if (StringUtil.isPassword(oldPassword)) { + if (userId <= 0) { //手机号+验证码不需要userId + return DemoParser.extendErrorResult(requestObject, new IllegalArgumentException(ID + ":value 中value不合法!")); + } + if (oldPassword.equals(password)) { + return DemoParser.extendErrorResult(requestObject, new ConflictException("新旧密码不能一样!")); + } + + //验证旧密码 + Privacy privacy = new Privacy(userId); + if (type == Verify.TYPE_PASSWORD) { + privacy.setPassword(oldPassword); + } else { + privacy.setPayPassword(oldPassword); + } + JSONResponse response = new JSONResponse( + new DemoParser(HEAD, true).parseResponse( + new JSONRequest(privacy) + ) + ); + if (JSONResponse.isExist(response.getJSONResponse(PRIVACY_)) == false) { + return DemoParser.extendErrorResult(requestObject, new ConditionErrorException("账号或原密码错误,请重新输入!")); + } + } + else if (StringUtil.isPhone(phone) && StringUtil.isVerify(verify)) { + JSONResponse response = new JSONResponse(headVerify(type, phone, verify)); + if (JSONResponse.isSuccess(response) == false) { + return response; + } + if (JSONResponse.isExist(response.getJSONResponse(VERIFY_)) == false) { + return DemoParser.extendErrorResult(response, new ConditionErrorException("手机号或验证码错误!")); + } + response = new JSONResponse( + new DemoParser(GET, true).parseResponse( + new JSONRequest( + new Privacy().setPhone(phone) + ) + ) + ); + Privacy privacy = response.getObject(Privacy.class); + long id = privacy == null ? 0 : BaseModel.value(privacy.getId()); + privacyObj.remove(PHONE); + privacyObj.put(ID, id); + + requestObject.put(PRIVACY_, privacyObj); + } else { + return DemoParser.extendErrorResult(requestObject, new IllegalArgumentException("请输入合法的 旧密码 或 手机号+验证码 !")); + } + //TODO 上线版加上 password = MD5Util.MD5(password); + + + // requestObject.put(JSONRequest.KEY_TAG, "Password"); + //修改密码 + return new DemoParser(PUT, true).parseResponse(requestObject); + } + + + + /**充值/提现 + * @param request 只用String,避免encode后未decode + * @param session + * @return + * @see + *
+		{
+			"Privacy": {
+				"id": 82001,
+				"balance+": 100,
+				"_payPassword": "123456"
+			}
+		}
+	 * 
+ */ + @PostMapping("put/balance") + public JSONObject putBalance(@RequestBody String request, HttpSession session) { + JSONObject requestObject = null; + JSONObject privacyObj; + long userId; + String payPassword; + double change; + try { + DemoVerifier.verifyLogin(session); + requestObject = new DemoParser(PUT).setRequest(DemoParser.parseRequest(request)).parseCorrectRequest(); + + privacyObj = requestObject.getJSONObject(PRIVACY_); + if (privacyObj == null) { + throw new NullPointerException("请设置 " + PRIVACY_ + "!"); + } + userId = privacyObj.getLongValue(ID); + payPassword = privacyObj.getString(_PAY_PASSWORD); + change = privacyObj.getDoubleValue("balance+"); + + if (userId <= 0) { + throw new IllegalArgumentException(PRIVACY_ + "." + ID + ":value 中value不合法!"); + } + if (StringUtil.isPassword(payPassword) == false) { + throw new IllegalArgumentException(PRIVACY_ + "." + _PAY_PASSWORD + ":value 中value不合法!"); + } + } catch (Exception e) { + return DemoParser.extendErrorResult(requestObject, e); + } + + //验证密码<<<<<<<<<<<<<<<<<<<<<<< + + privacyObj.remove("balance+"); + JSONResponse response = new JSONResponse( + new DemoParser(HEADS, true).setSession(session).parseResponse( + new JSONRequest(PRIVACY_, privacyObj) + ) + ); + response = response.getJSONResponse(PRIVACY_); + if (JSONResponse.isExist(response) == false) { + return DemoParser.extendErrorResult(requestObject, new ConditionErrorException("支付密码错误!")); + } + + //验证密码>>>>>>>>>>>>>>>>>>>>>>>> + + + //验证金额范围<<<<<<<<<<<<<<<<<<<<<<< + + if (change == 0) { + return DemoParser.extendErrorResult(requestObject, new OutOfRangeException("balance+的值不能为0!")); + } + if (Math.abs(change) > 10000) { + return DemoParser.extendErrorResult(requestObject, new OutOfRangeException("单次 充值/提现 的金额不能超过10000元!")); + } + + //验证金额范围>>>>>>>>>>>>>>>>>>>>>>>> + + if (change < 0) {//提现 + response = new JSONResponse( + new DemoParser(GETS, true).parseResponse( + new JSONRequest( + new Privacy(userId) + ) + ) + ); + Privacy privacy = response == null ? null : response.getObject(Privacy.class); + long id = privacy == null ? 0 : BaseModel.value(privacy.getId()); + if (id != userId) { + return DemoParser.extendErrorResult(requestObject, new Exception("服务器内部错误!")); + } + + if (BaseModel.value(privacy.getBalance()) < -change) { + return DemoParser.extendErrorResult(requestObject, new OutOfRangeException("余额不足!")); + } + } + + + privacyObj.remove(_PAY_PASSWORD); + privacyObj.put("balance+", change); + requestObject.put(PRIVACY_, privacyObj); + requestObject.put(JSONRequest.KEY_TAG, PRIVACY_); + //不免验证,里面会验证身份 + return new DemoParser(PUT).setSession(session).parseResponse(requestObject); + } + + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoFunction.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoFunction.java new file mode 100644 index 000000000..912472eb6 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoFunction.java @@ -0,0 +1,412 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import javax.servlet.http.HttpSession; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +import apijson.demo.server.model.BaseModel; +import apijson.demo.server.model.Comment; +import zuo.biao.apijson.JSONResponse; +import zuo.biao.apijson.Log; +import zuo.biao.apijson.RequestMethod; +import zuo.biao.apijson.RequestRole; +import zuo.biao.apijson.StringUtil; +import zuo.biao.apijson.server.Function; +import zuo.biao.apijson.server.JSONRequest; +import zuo.biao.apijson.server.NotNull; + + +/**可远程调用的函数类 + * @author Lemon + */ +public class DemoFunction extends Function implements FunctionList { + private static final String TAG = "DemoFunction"; + + private final HttpSession session; + public DemoFunction(HttpSession session) { + this.session = session; + } + + public static void test() throws Exception { + int i0 = 1, i1 = -2; + JSONObject request = new JSONObject(); + request.put("id", 10); + request.put("i0", i0); + request.put("i1", i1); + JSONArray arr = new JSONArray(); + arr.add(new JSONObject()); + request.put("arr", arr); + + JSONArray array = new JSONArray(); + array.add(1);//new JSONObject()); + array.add(2);//new JSONObject()); + array.add(4);//new JSONObject()); + array.add(10);//new JSONObject()); + request.put("array", array); + + request.put("position", 1); + request.put("@position", 0); + + request.put("key", "key"); + JSONObject object = new JSONObject(); + object.put("key", true); + request.put("object", object); + + + Log.i(TAG, "plus(1,-2) = " + new DemoFunction(null).invoke(request, "plus(i0,i1)")); + Log.i(TAG, "count([1,2,4,10]) = " + new DemoFunction(null).invoke(request, "countArray(array)")); + Log.i(TAG, "isContain([1,2,4,10], 10) = " + new DemoFunction(null).invoke(request, "isContain(array,id)")); + Log.i(TAG, "getFromArray([1,2,4,10], 0) = " + new DemoFunction(null).invoke(request, "getFromArray(array,@position)")); + Log.i(TAG, "getFromObject({key:true}, key) = " + new DemoFunction(null).invoke(request, "getFromObject(object,key)")); + + } + + + + + /**反射调用 + * @param request + * @param function 例如get(object,key),参数只允许引用,不能直接传值 + * @return + */ + public Object invoke(JSONObject request, String function) throws Exception { + //TODO 不允许调用invoke,避免死循环 + // if (function.startsWith("invoke(")) { + // + // } + return invoke(this, request, function); + } + + + + /** + * @param request + * @return + * @throws Exception + */ + public Object verifyIdList(@NotNull JSONObject request, @NotNull String idList) throws Exception { + Object obj = request.get(idList); + if (obj instanceof Collection == false) { + throw new IllegalArgumentException(idList + " 不符合 Array 类型! 结构必须是 [] !"); + } + JSONArray array = (JSONArray) obj; + if (array != null) { + for (int i = 0; i < array.size(); i++) { + if (array.get(i) instanceof Long == false && array.get(i) instanceof Integer == false) { + throw new IllegalArgumentException(idList + " 内字符 " + array.getString(i) + " 不符合 Long 类型!"); + } + } + } + return null; + } + + + /** + * @param request + * @return + * @throws Exception + */ + public Object verifyURLList(@NotNull JSONObject request, @NotNull String urlList) throws Exception { + Object obj = request.get(urlList); + if (obj instanceof Collection == false) { + throw new IllegalArgumentException(urlList + " 不符合 Array 类型! 结构必须是 [] !"); + } + JSONArray array = (JSONArray) obj; + if (array != null) { + for (int i = 0; i < array.size(); i++) { + if (StringUtil.isUrl(array.getString(i)) == false) { + throw new IllegalArgumentException(urlList + " 内字符 " + array.getString(i) + " 不符合 URL 格式!"); + } + } + } + return null; + } + + /**判断array是否为空 + * @param request + * @param array + * @return + */ + public int deleteChildComment(@NotNull JSONObject rq, @NotNull String toId) throws Exception { + long tid = rq.getLongValue(toId); + if (tid <= 0 || rq.getIntValue(JSONResponse.KEY_COUNT) <= 0) { + return 0; + } + + //递归获取到全部子评论id + + JSONRequest request = new JSONRequest(); + + //Comment<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + JSONRequest comment = new JSONRequest(); + comment.put("id{}", getChildCommentIdList(tid)); + request.put("Comment", comment); + + //Comment>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + JSONObject rp = new DemoParser(RequestMethod.DELETE).setNoVerify(true).parseResponse(request); + + JSONObject c = rp.getJSONObject("Comment"); + return c == null ? 0 : c.getIntValue(JSONResponse.KEY_COUNT); + } + + + private JSONArray getChildCommentIdList(long tid) { + + JSONArray arr = new JSONArray(); + + JSONRequest request = new JSONRequest(); + + //Comment-id[]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + JSONRequest idItem = new JSONRequest(); + + //Comment<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + JSONRequest comment = new JSONRequest(); + comment.put("toId", tid); + comment.setColumn("id"); + idItem.put("Comment", comment); + //Comment>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + request.putAll(idItem.toArray(0, 0, "Comment-id")); + //Comment-id[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + JSONObject rp = new DemoParser().setNoVerify(true).parseResponse(request); + + JSONArray a = rp.getJSONArray("Comment-id[]"); + if (a != null) { + arr.addAll(a); + + JSONArray a2; + for (int i = 0; i < a.size(); i++) { + + a2 = getChildCommentIdList(a.getLongValue(i)); + if (a2 != null) { + arr.addAll(a2); + } + } + } + + return arr; + } + + + /**TODO 仅用来测试 "key-()":"getIdList()" 和 "key()":"getIdList()" + * @param request + * @return JSONArray 只能用JSONArray,用long[]会在SQLConfig解析崩溃 + * @throws Exception + */ + public JSONArray getIdList(@NotNull JSONObject request) throws Exception { + return new JSONArray(new ArrayList(Arrays.asList(12, 15, 301, 82001, 82002, 38710))); + } + + + /**TODO 仅用来测试 "key-()":"verifyAccess()" + * @param request + * @return + * @throws Exception + */ + public Object verifyAccess(@NotNull JSONObject request) throws Exception { + long userId = request.getLongValue(zuo.biao.apijson.JSONObject.KEY_USER_ID); + RequestRole role = RequestRole.get(request.getString(zuo.biao.apijson.JSONObject.KEY_ROLE)); + if (role == RequestRole.OWNER && userId != DemoVerifier.getVisitorId(session)) { + throw new IllegalAccessException("登录用户与角色OWNER不匹配!"); + } + return null; + } + + + + + + public double plus(@NotNull JSONObject request, String i0, String i1) { + return request.getDoubleValue(i0) + request.getDoubleValue(i1); + } + public double minus(@NotNull JSONObject request, String i0, String i1) { + return request.getDoubleValue(i0) - request.getDoubleValue(i1); + } + public double multiply(@NotNull JSONObject request, String i0, String i1) { + return request.getDoubleValue(i0) * request.getDoubleValue(i1); + } + public double divide(@NotNull JSONObject request, String i0, String i1) { + return request.getDoubleValue(i0) / request.getDoubleValue(i1); + } + + //判断是否为空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**判断array是否为空 + * @param request + * @param array + * @return + */ + @Override + public boolean isArrayEmpty(@NotNull JSONObject request, String array) { + return BaseModel.isEmpty(request.getJSONArray(array)); + } + /**判断object是否为空 + * @param request + * @param object + * @return + */ + @Override + public boolean isObjectEmpty(@NotNull JSONObject request, String object) { + return BaseModel.isEmpty(request.getJSONObject(object)); + } + //判断是否为空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + //判断是否为包含 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**判断array是否包含value + * @param request + * @param array + * @param value + * @return + */ + @Override + public boolean isContain(@NotNull JSONObject request, String array, String value) { + //解决isContain((List) [82001,...], (Integer) 82001) == false及类似问题, list元素可能是从数据库查到的bigint类型的值 + // return BaseModel.isContain(request.getJSONArray(array), request.get(value)); + + //不用准确的的 request.getString(value).getClass() ,因为Long值转Integer崩溃,而且转成一种类型本身就和字符串对比效果一样了。 + List list = com.alibaba.fastjson.JSON.parseArray(request.getString(array), String.class); + return list != null && list.contains(request.getString(value)); + } + /**判断object是否包含key + * @param request + * @param object + * @param key + * @return + */ + @Override + public boolean isContainKey(@NotNull JSONObject request, String object, String key) { + return BaseModel.isContainKey(request.getJSONObject(object), request.getString(key)); + } + /**判断object是否包含value + * @param request + * @param object + * @param value + * @return + */ + @Override + public boolean isContainValue(@NotNull JSONObject request, String object, String value) { + return BaseModel.isContainValue(request.getJSONObject(object), request.get(value)); + } + //判断是否为包含 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + //获取集合长度 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**获取数量 + * @param request + * @param array + * @return + */ + @Override + public int countArray(@NotNull JSONObject request, String array) { + return BaseModel.count(request.getJSONArray(array)); + } + /**获取数量 + * @param request + * @param object + * @return + */ + @Override + public int countObject(@NotNull JSONObject request, String object) { + return BaseModel.count(request.getJSONObject(object)); + } + //获取集合长度 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + //根据键获取值 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**获取 + ** @param request + * @param array + * @param position + * @return + */ + @Override + public Object getFromArray(@NotNull JSONObject request, String array, String position) { + return BaseModel.get(request.getJSONArray(array), request.getIntValue(position)); + } + /**获取 + * @param request + * @param object + * @param key + * @return + */ + @Override + public Object getFromObject(@NotNull JSONObject request, String object, String key) { + return BaseModel.get(request.getJSONObject(object), request.getString(key)); + } + //根据键获取值 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + //获取非基本类型对应基本类型的非空值 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**获取非空值 + * @param request + * @param value + * @return + */ + @Override + public boolean booleanValue(@NotNull JSONObject request, String value) { + return request.getBooleanValue(value); + } + /**获取非空值 + * @param request + * @param value + * @return + */ + @Override + public int intValue(@NotNull JSONObject request, String value) { + return request.getIntValue(value); + } + /**获取非空值 + * @param request + * @param value + * @return + */ + @Override + public long longValue(@NotNull JSONObject request, String value) { + return request.getLongValue(value); + } + /**获取非空值 + * @param request + * @param value + * @return + */ + @Override + public float floatValue(@NotNull JSONObject request, String value) { + return request.getFloatValue(value); + } + /**获取非空值 + * @param request + * @param value + * @return + */ + @Override + public double doubleValue(@NotNull JSONObject request, String value) { + return request.getDoubleValue(value); + } + //获取非基本类型对应基本类型的非空值 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + +} \ No newline at end of file diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoObjectParser.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoObjectParser.java new file mode 100644 index 000000000..7ba7b2da3 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoObjectParser.java @@ -0,0 +1,77 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server; + +import javax.servlet.http.HttpSession; +import javax.validation.constraints.NotNull; + +import com.alibaba.fastjson.JSONObject; + +import zuo.biao.apijson.RequestMethod; +import zuo.biao.apijson.StringUtil; +import zuo.biao.apijson.server.AbstractObjectParser; +import zuo.biao.apijson.server.Parser; +import zuo.biao.apijson.server.SQLConfig; + + +/**简化Parser,getObject和getArray(getArrayConfig)都能用 + * @author Lemon + */ +public abstract class DemoObjectParser extends AbstractObjectParser { + + static { + COMPILE_MAP.put("phone", StringUtil.PATTERN_PHONE); + COMPILE_MAP.put("email", StringUtil.PATTERN_EMAIL); + COMPILE_MAP.put("idCard", StringUtil.PATTERN_ID_CARD); + } + + + private DemoFunction function; + /**for single object + * @param parentPath + * @param request + * @param name + * @throws Exception + */ + public DemoObjectParser(HttpSession session, @NotNull JSONObject request, String parentPath, String name, SQLConfig arrayConfig) throws Exception { + super(request, parentPath, name, arrayConfig); + function = new DemoFunction(session); + } + + @Override + public DemoObjectParser setMethod(RequestMethod method) { + super.setMethod(method); + return this; + } + + @Override + public DemoObjectParser setParser(Parser parser) { + super.setParser(parser); + return this; + } + + @Override + public SQLConfig newSQLConfig() throws Exception { + return DemoSQLConfig.newSQLConfig(method, table, sqlRequest, joinList); + } + + + @Override + public Object onFunctionParse(JSONObject json, String fun) throws Exception { + return function.invoke(json, fun); + } + + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoParser.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoParser.java new file mode 100644 index 000000000..dea1439f7 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoParser.java @@ -0,0 +1,133 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server; + +import javax.servlet.http.HttpSession; + +import com.alibaba.fastjson.JSONObject; + +import zuo.biao.apijson.RequestMethod; +import zuo.biao.apijson.server.AbstractParser; +import zuo.biao.apijson.server.JSONRequest; +import zuo.biao.apijson.server.SQLConfig; +import zuo.biao.apijson.server.SQLCreator; +import zuo.biao.apijson.server.SQLExecutor; +import zuo.biao.apijson.server.Structure; +import zuo.biao.apijson.server.Verifier; + +import java.io.FileNotFoundException; + + +/**请求解析器 + * @author Lemon + */ +public class DemoParser extends AbstractParser implements SQLCreator { + + + public DemoParser() { + super(); + } + public DemoParser(RequestMethod method) { + super(method); + } + public DemoParser(RequestMethod method, boolean noVerify) { + super(method, noVerify); + } + + protected HttpSession session; + public HttpSession getSession() { + return session; + } + public AbstractParser setSession(HttpSession session) { + this.session = session; + setVisitor(DemoVerifier.getVisitor(session)); + return this; + } + + + @Override + public Verifier createVerifier() { + return new DemoVerifier(); + } + @Override + public SQLConfig createSQLConfig() { + try { + return new DemoSQLConfig(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return null; + } + } + @Override + public SQLExecutor createSQLExecutor() { + return new DemoSQLExecutor(); + } + + + + @Override + public DemoObjectParser createObjectParser(JSONObject request, String parentPath, String name, SQLConfig arrayConfig) throws Exception { + + return new DemoObjectParser(session, request, parentPath, name, arrayConfig) { + + //TODO 删除,onPUTArrayParse改用MySQL函数JSON_ADD, JSON_REMOVE等 + @Override + public JSONObject parseResponse(JSONRequest request) throws Exception { + DemoParser demoParser = new DemoParser(RequestMethod.GET); + demoParser.setSession(session); + // parser.setNoVerifyRequest(noVerifyRequest) + demoParser.setNoVerifyLogin(noVerifyLogin); + demoParser.setNoVerifyRole(noVerifyRole); + return demoParser.parseResponse(request); + } + + + // @Override + // protected DemoSQLConfig newQueryConfig() { + // if (itemConfig != null) { + // return itemConfig; + // } + // return super.newQueryConfig(); + // } + + //导致最多评论的(Strong 30个)的那个动态详情界面Android(82001)无姓名和头像,即User=null + // @Override + // protected void onComplete() { + // if (response != null) { + // putQueryResult(path, response);//解决获取关联数据时requestObject里不存在需要的关联数据 + // } + // } + + }.setMethod(requestMethod).setParser(this); + } + + + + @Override + protected void onVerifyContent() throws Exception { + //补充全局缺省版本号 + if (session != null && requestObject.getIntValue(JSONRequest.KEY_VERSION) <= 0) { + requestObject.put(JSONRequest.KEY_VERSION, session.getAttribute(JSONRequest.KEY_VERSION)); + } + super.onVerifyContent(); + } + + + @Override + public JSONObject parseCorrectRequest(JSONObject target) throws Exception { + return Structure.parseRequest(requestMethod, "", target, requestObject, this); + } + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoSQLConfig.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoSQLConfig.java new file mode 100644 index 000000000..7aec24835 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoSQLConfig.java @@ -0,0 +1,94 @@ +package apijson.demo.server; + +import java.io.FileNotFoundException; +import java.util.List; +import java.util.Map; + +import apijson.demo.server.config.ConfigYml; +import com.alibaba.fastjson.JSONObject; +import apijson.demo.server.model.Privacy; +import apijson.demo.server.model.User; +import org.springframework.stereotype.Component; +import zuo.biao.apijson.RequestMethod; +import zuo.biao.apijson.StringUtil; +import zuo.biao.apijson.server.AbstractSQLConfig; +import zuo.biao.apijson.server.Join; +import zuo.biao.apijson.server.SQLConfig; + + +/**SQL配置 + * @author Lemon + */ +@Component +public class DemoSQLConfig extends AbstractSQLConfig { + //表名映射,隐藏真实表名,对安全要求很高的表可以这么做 + static { + TABLE_KEY_MAP.put(User.class.getSimpleName(), "apijson_user"); + TABLE_KEY_MAP.put(Privacy.class.getSimpleName(), "apijson_privacy"); + } + + ConfigYml dataSourceConfig = new ConfigYml(); + Map dataSource = dataSourceConfig.read(); + + @Override + public String getDBUri() { + //TODO 改成你自己的 + return dataSource.get("url")+""; + } + @Override + public String getDBAccount() { + return dataSource.get("username")+""; + } + @Override + public String getDBPassword() { + return dataSource.get("password")+""; + } + @Override + public String getSchema() { + String s = super.getSchema(); + return StringUtil.isEmpty(s, true) ? dataSource.get("schema")+"" : s; //TODO 改成你自己的 + } + + @Override + public String getAlias() { //getTable 不能小写,因为Verifier用大小写敏感的名称判断权限 + return super.getAlias(); + } + + + public DemoSQLConfig() throws FileNotFoundException { + this(RequestMethod.GET); + } + public DemoSQLConfig(RequestMethod method) throws FileNotFoundException { + super(method); + } + public DemoSQLConfig(RequestMethod method, String table) throws FileNotFoundException { + super(method, table); + } + public DemoSQLConfig(RequestMethod method, int count, int page) throws FileNotFoundException { + super(method, count, page); + } + + + /**获取SQL配置 + * @param table + * @param request + * @return + * @throws Exception + */ + public static SQLConfig newSQLConfig(RequestMethod method, String table, JSONObject request, List joinList) throws Exception { + return newSQLConfig(method, table, request, joinList, new Callback() { + + @Override + public DemoSQLConfig getSQLConfig(RequestMethod method, String table) { + try { + return new DemoSQLConfig(method, table); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return null; + } + } + }); + } + + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoSQLExecutor.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoSQLExecutor.java new file mode 100644 index 000000000..7f10a5dab --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoSQLExecutor.java @@ -0,0 +1,113 @@ +package apijson.demo.server; + +import apijson.demo.server.config.ConfigYml; +import zuo.biao.apijson.Log; +import zuo.biao.apijson.server.AbstractSQLExecutor; +import zuo.biao.apijson.server.SQLConfig; + +import javax.validation.constraints.NotNull; +import java.sql.*; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/**executor for query(read) or update(write) MySQL database + * @author Lemon + */ +public class DemoSQLExecutor extends AbstractSQLExecutor { + private static final String TAG = "DemoSQLExecutor"; + static ConfigYml dataSourceConfig = new ConfigYml(); + static Map dataSource = dataSourceConfig.read(); + + static { + try { //加载驱动程序 + Class.forName(dataSource.get("driverclassame")+""); + Log.d(TAG, "成功加载 数据库 驱动!"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + + @Override + public ResultSet executeQuery(@NotNull SQLConfig config) throws Exception { + return getStatement(config).executeQuery(); + } + + @Override + public int executeUpdate(@NotNull SQLConfig config) throws Exception { + return getStatement(config).executeUpdate(); + } + + + //TODO String 改为 enum Database 解决大小写不一致(MySQL, mysql等)导致创建多余的 Connection + private Map connectionMap = new HashMap<>(); + /** + * @param config + * @return + * @throws Exception + */ + @SuppressWarnings("resource") + private PreparedStatement getStatement(@NotNull SQLConfig config) throws Exception { + Connection connection = connectionMap.get(config.getDatabase()); + if (connection == null || connection.isClosed()) { + Log.i(TAG, "select connection " + (connection == null ? " = null" : ("isClosed = " + connection.isClosed()))) ; + //只有一个数据库 +// if (DemoSQLConfig.DATABASE_POSTGRESQL.equalsIgnoreCase(config.getDatabase())) { //PostgreSQL,oracle 不允许 cross-database mysql直接连接会乱码 + connection = DriverManager.getConnection(config.getDBUri(), config.getDBAccount(), config.getDBPassword()); +// } else { +// connection = DriverManager.getConnection(config.getDBUri() + "?useUnicode=true&characterEncoding=UTF-8&user=" +// + config.getDBAccount() + "&password=" + config.getDBPassword()); +// } + connectionMap.put(config.getDatabase(), connection); + } + + PreparedStatement statement = connection.prepareStatement(config.getSQL(config.isPrepared())); //创建Statement对象 + List valueList = config.isPrepared() ? config.getPreparedValueList() : null; + + if (valueList != null && valueList.isEmpty() == false) { + + for (int i = 0; i < valueList.size(); i++) { +//只有一个数据库 +// if (DemoSQLConfig.DATABASE_POSTGRESQL.equalsIgnoreCase(config.getDatabase())) { +// statement.setObject(i + 1, valueList.get(i)); //PostgreSQL JDBC 不支持隐式类型转换 tinyint = varchar 报错 +// } +// else { + statement.setString(i + 1, "" + valueList.get(i)); //MySQL setObject 不支持 JSON 类型 +// } + } + } + return statement; + } + + + /**关闭连接,释放资源 + */ + @Override + public void close() { + super.close(); + + if (connectionMap == null) { + return; + } + Collection connections = connectionMap.values(); + + if (connections != null) { + for (Connection connection : connections) { + try { + if (connection != null && connection.isClosed() == false) { + connection.close(); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + connectionMap.clear(); + connectionMap = null; + } + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoVerifier.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoVerifier.java new file mode 100644 index 000000000..1654ae008 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/DemoVerifier.java @@ -0,0 +1,115 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server; + +import javax.servlet.http.HttpSession; +import javax.validation.constraints.NotNull; + +import apijson.demo.server.model.*; +import zuo.biao.apijson.Log; +import zuo.biao.apijson.MethodAccess; +import zuo.biao.apijson.server.AbstractVerifier; +import zuo.biao.apijson.server.Visitor; + + +/**权限验证器 + * @author Lemon + */ +public class DemoVerifier extends AbstractVerifier { + private static final String TAG = "DemoVerifier"; + + + public static final String KEY_PASSWORD = "password"; + public static final String KEY_LOGIN_PASSWORD = "loginPassword"; + public static final String KEY_PAY_PASSWORD = "payPassword"; + public static final String KEY_OLD_PASSWORD = "oldPassword"; + + + // > + // > + static { //注册权限 + ACCESS_MAP.put(User.class.getSimpleName(), getAccessMap(User.class.getAnnotation(MethodAccess.class))); + ACCESS_MAP.put(Privacy.class.getSimpleName(), getAccessMap(Privacy.class.getAnnotation(MethodAccess.class))); + ACCESS_MAP.put(Moment.class.getSimpleName(), getAccessMap(Moment.class.getAnnotation(MethodAccess.class))); + ACCESS_MAP.put(Comment.class.getSimpleName(), getAccessMap(Comment.class.getAnnotation(MethodAccess.class))); + ACCESS_MAP.put(Verify.class.getSimpleName(), getAccessMap(Verify.class.getAnnotation(MethodAccess.class))); + ACCESS_MAP.put(Login.class.getSimpleName(), getAccessMap(Login.class.getAnnotation(MethodAccess.class))); + ACCESS_MAP.put(Contract.class.getSimpleName(), getAccessMap(Contract.class.getAnnotation(MethodAccess.class))); + } + + + @NotNull + @Override + public DemoParser createParser() { + DemoParser parser = new DemoParser(); + parser.setVisitor(visitor); + return parser; + } + + @Override + public String getVisitorKey() { + return Controller.USER_; + } + + @Override + public String getVisitorIdKey() { + return Controller.USER_ID; + } + + @Override + public String getVisitorIdKey(String table) { + return Controller.USER_.equals(table) || Controller.PRIVACY_.equals(table) ? Controller.ID : getVisitorIdKey(); + } + + /**登录校验 + * @author + * @modifier Lemon + * @param session + * @throws Exception + */ + public static void verifyLogin(HttpSession session) throws Exception { + Log.d(TAG, "verifyLogin session.getId() = " + (session == null ? null : session.getId())); + new DemoVerifier().setVisitor(getVisitor(session)).verifyLogin(); + } + + + /**获取来访用户的id + * @author Lemon + * @param session + * @return + */ + public static long getVisitorId(HttpSession session) { + if (session == null) { + return 0; + } + Long id = (Long) session.getAttribute(Controller.USER_ID); + if (id == null) { + Visitor v = getVisitor(session); + id = v == null ? 0 : value(v.getId()); + session.setAttribute(Controller.USER_ID, id); + } + return value(id); + } + /**获取来访用户 + * @param session + * @return + */ + public static Visitor getVisitor(HttpSession session) { + return session == null ? null : (Visitor) session.getAttribute(Controller.USER_); + } + + + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/FunctionList.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/FunctionList.java new file mode 100644 index 000000000..548ed08a4 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/FunctionList.java @@ -0,0 +1,137 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server; + +import com.alibaba.fastjson.JSONObject; + +import zuo.biao.apijson.server.NotNull; + + +//TODO 新增 @FunctionList ,被它注解过的List可以传到 Funtion.invoke(FunctionList list, ...) +/**可远程调用的函数列表,暴露功能和使用方式,而不是具体的实现细节。 + * @author Lemon + */ +public interface FunctionList { + + //判断是否为空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**判断array是否为空 + * @param request + * @param array + * @return + */ + public boolean isArrayEmpty(@NotNull JSONObject request, String array); + /**判断object是否为空 + * @param request + * @param object + * @return + */ + public boolean isObjectEmpty(@NotNull JSONObject request, String object); + //判断是否为空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + //判断是否为包含 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**判断array是否包含value + * @param request + * @param array + * @param value + * @return + */ + public boolean isContain(@NotNull JSONObject request, String array, String value); + /**判断object是否包含key + * @param request + * @param object + * @param key + * @return + */ + public boolean isContainKey(@NotNull JSONObject request, String object, String key); + + /**判断object是否包含value + * @param request + * @param object + * @param value + * @return + */ + public boolean isContainValue(@NotNull JSONObject request, String object, String value); + //判断是否为包含 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + //获取集合长度 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**获取数量 + * @param request + * @param array + * @return + */ + public int countArray(@NotNull JSONObject request, String array); + /**获取数量 + * @param request + * @param object + * @return + */ + public int countObject(@NotNull JSONObject request, String object); + //获取集合长度 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + //根据键获取值 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**获取 + ** @param request + * @param array + * @param position + * @return + */ + public Object getFromArray(@NotNull JSONObject request, String array, String position); + /**获取 + * @param request + * @param object + * @param key + * @return + */ + public Object getFromObject(@NotNull JSONObject request, String object, String key); + //根据键获取值 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + //获取非基本类型对应基本类型的非空值 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**获取非空值 + * @param request + * @param value + * @return + */ + public boolean booleanValue(@NotNull JSONObject request, String value); + /**获取非空值 + * @param request + * @param value + * @return + */ + public int intValue(@NotNull JSONObject request, String value); + /**获取非空值 + * @param request + * @param value + * @return + */ + public long longValue(@NotNull JSONObject request, String value); + /**获取非空值 + * @param request + * @param value + * @return + */ + public float floatValue(@NotNull JSONObject request, String value); + /**获取非空值 + * @param request + * @param value + * @return + */ + public double doubleValue(@NotNull JSONObject request, String value); + //获取非基本类型对应基本类型的非空值 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +} \ No newline at end of file diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/StructureUtil.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/StructureUtil.java new file mode 100644 index 000000000..818b3d7ab --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/StructureUtil.java @@ -0,0 +1,114 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server; + +import com.alibaba.fastjson.JSONObject; + +import zuo.biao.apijson.JSON; +import zuo.biao.apijson.Log; +import zuo.biao.apijson.RequestMethod; +import zuo.biao.apijson.server.SQLConfig; +import zuo.biao.apijson.server.SQLCreator; +import zuo.biao.apijson.server.SQLExecutor; +import zuo.biao.apijson.server.Structure; + +import java.io.FileNotFoundException; + + +/**结构校验 + * @author Lemon + */ +public class StructureUtil { + private static final String TAG = "Structure"; + + + static final String requestString = "{\"Comment\":{\"DISALLOW\": \"id\", \"NECESSARY\": \"userId,momentId,content\"}, \"ADD\":{\"Comment:to\":{}}}"; + static final String responseString = "{\"User\":{\"REMOVE\": \"phone\", \"REPLACE\":{\"sex\":2}, \"ADD\":{\"name\":\"api\"}}, \"PUT\":{\"Comment:to\":{}}}"; + /**测试 + * @throws Exception + */ + public static void test() throws Exception { + JSONObject request; + + SQLCreator creator = new SQLCreator() { + + @Override + public SQLConfig createSQLConfig() { + try { + return new DemoSQLConfig(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return null; + } + } + + @Override + public SQLExecutor createSQLExecutor() { + return new apijson.demo.server.DemoSQLExecutor(); + } + }; + + try { + request = JSON.parseObject("{\"Comment\":{\"userId\":0}}"); + Log.d(TAG, "test parseRequest = " + Structure.parseRequest(RequestMethod.POST, "", JSON.parseObject(requestString), request, creator)); + } catch (Exception e) { + e.printStackTrace(); + } + try { + request = JSON.parseObject("{\"Comment\":{\"userId\":0, \"momentId\":0, \"content\":\"apijson\"}}"); + Log.d(TAG, "test parseRequest = " + Structure.parseRequest(RequestMethod.POST, "", JSON.parseObject(requestString), request, creator)); + } catch (Exception e) { + e.printStackTrace(); + } + try { + request = JSON.parseObject("{\"Comment\":{\"id\":0, \"userId\":0, \"momentId\":0, \"content\":\"apijson\"}}"); + Log.d(TAG, "test parseRequest = " + Structure.parseRequest(RequestMethod.POST, "", JSON.parseObject(requestString), request, creator)); + } catch (Exception e) { + e.printStackTrace(); + } + + + JSONObject response; + try { + response = JSON.parseObject("{\"User\":{\"userId\":0}}"); + Log.d(TAG, "test parseResponse = " + Structure.parseResponse(RequestMethod.GET, "", JSON.parseObject(responseString), response, creator, null)); + } catch (Exception e) { + e.printStackTrace(); + } + try { + response = JSON.parseObject("{\"User\":{\"userId\":0, \"phone\":\"12345678\"}}"); + Log.d(TAG, "test parseResponse = " + Structure.parseResponse(RequestMethod.GET, "", JSON.parseObject(responseString), response, creator, null)); + } catch (Exception e) { + e.printStackTrace(); + } + try { + response = JSON.parseObject("{\"User\":{\"userId\":0, \"phone\":\"12345678\", \"sex\":1}}"); + Log.d(TAG, "test parseResponse = " + Structure.parseResponse(RequestMethod.GET, "", JSON.parseObject(responseString), response, creator, null)); + } catch (Exception e) { + e.printStackTrace(); + } + try { + response = JSON.parseObject("{\"User\":{\"id\":0, \"name\":\"tommy\", \"phone\":\"12345678\", \"sex\":1}}"); + Log.d(TAG, "test parseResponse = " + Structure.parseResponse(RequestMethod.GET, "", JSON.parseObject(responseString), response,creator, null)); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + + + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/config/ConfigYml.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/config/ConfigYml.java new file mode 100644 index 000000000..9ca0b82ae --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/config/ConfigYml.java @@ -0,0 +1,27 @@ +package apijson.demo.server.config; + +import org.ho.yaml.Yaml; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.HashMap; +import java.util.Map; + +/** + * @author hjt + * @date 2018/8/30 + * @description + */ +public class ConfigYml { + public Map read() { + String fileName = this.getClass().getClassLoader().getResource("application.yml").getPath();//获取文件路径 + File dumpFile=new File(fileName); + Map father = null; + try { + father = Yaml.loadType(dumpFile, HashMap.class); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + return father; + } +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/BaseModel.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/BaseModel.java new file mode 100644 index 000000000..8dec7d729 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/BaseModel.java @@ -0,0 +1,304 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server.model; + +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.Map; + +import com.alibaba.fastjson.JSON; + +import zuo.biao.apijson.StringUtil; + +/**base model for reduce model codes + * @author Lemon + * @use extends BaseModel + */ +public abstract class BaseModel implements Serializable { + private static final long serialVersionUID = 1L; + + private Long id; //主键,唯一标识 + private Long userId; //对应User表中的id,外键 + private String date; //创建时间,JSON没有Date,TimeStamp类型,都会被转成Long,不能用! + + public Long getId() { + return id; + } + public BaseModel setId(Long id) { + this.id = id; + return this; + } + public Long getUserId() { + return userId; + } + public BaseModel setUserId(Long userId) { + this.userId = userId; + return this; + } + public String getDate() { + return date; + } + public BaseModel setDate(String date) { + this.date = date; + return this; + } + + + @Override + public String toString() { + return JSON.toJSONString(this); + } + + + /**获取当前时间戳 + * @return + */ + public static Timestamp currentTimeStamp() { + return new Timestamp(new Date().getTime()); + } + /**获取时间戳 TODO 判空? 还是要报错? + * @param time + * @return + */ + public static Timestamp getTimeStamp(String time) { + return Timestamp.valueOf(time); + } + /**获取时间毫秒值 TODO 判空? 还是要报错? + * @param time + * @return + */ + public static long getTimeMillis(String time) { + return StringUtil.isEmpty(time, true) ? 0 : getTimeStamp(time).getTime(); + } + + + //判断是否为空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**判断array是否为空 + * @param array + * @return + */ + public static boolean isEmpty(T[] array) { + return array == null || array.length <= 0; + } + /**判断collection是否为空 + * @param collection + * @return + */ + public static boolean isEmpty(Collection collection) { + return collection == null || collection.isEmpty(); + } + /**判断map是否为空 + * @param + * @param + * @param map + * @return + */ + public static boolean isEmpty(Map map) { + return map == null || map.isEmpty(); + } + //判断是否为空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + //判断是否包含 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**判断array是否包含a + * @param array + * @param a + * @return + */ + public static boolean isContain(T[] array, T a) { + return array == null ? false : Arrays.asList(array).contains(a); + } + /**判断collection是否包含object + * @param collection + * @param object + * @return + */ + public static boolean isContain(Collection collection, T object) { + return collection != null && collection.contains(object); + } + /**判断map是否包含key + * @param + * @param + * @param map + * @param key + * @return + */ + public static boolean isContainKey(Map map, K key) { + return map != null && map.containsKey(key); + } + /**判断map是否包含value + * @param + * @param + * @param map + * @param value + * @return + */ + public static boolean isContainValue(Map map, V value) { + return map != null && map.containsValue(value); + } + //判断是否为包含 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + //获取集合长度 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**获取数量 + * @param + * @param array + * @return + */ + public static int count(T[] array) { + return array == null ? 0 : array.length; + } + /**获取数量 + * @param + * @param collection List, Vector, Set等都是Collection的子类 + * @return + */ + public static int count(Collection collection) { + return collection == null ? 0 : collection.size(); + } + /**获取数量 + * @param + * @param + * @param map + * @return + */ + public static int count(Map map) { + return map == null ? 0 : map.size(); + } + //获取集合长度 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + //获取集合长度 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**获取 + * @param + * @param array + * @return + */ + public static T get(T[] array, int position) { + return position < 0 || position >= count(array) ? null : array[position]; + } + /**获取 + * @param + * @param collection List, Vector, Set等都是Collection的子类 + * @return + */ + @SuppressWarnings("unchecked") + public static T get(Collection collection, int position) { + return collection == null ? null : (T) get(collection.toArray(), position); + } + /**获取 + * @param + * @param + * @param map null ? null + * @param key null ? null : map.get(key); + * @return + */ + public static V get(Map map, K key) { + return key == null || map == null ? null : map.get(key); + } + //获取集合长度 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + + + //获取非基本类型对应基本类型的非空值 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< + /**获取非空值 + * @param value + * @return + */ + public static boolean value(Boolean value) { + return value == null ? false : value; + } + /**获取非空值 + * @param value + * @return + */ + public static int value(Integer value) { + return value == null ? 0 : value; + } + /**获取非空值 + * @param value + * @return + */ + public static long value(Long value) { + return value == null ? 0 : value; + } + /**获取非空值 + * @param value + * @return + */ + public static float value(Float value) { + return value == null ? 0 : value; + } + /**获取非空值 + * @param value + * @return + */ + public static double value(Double value) { + return value == null ? 0 : value; + } + //获取非基本类型对应基本类型的非空值 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /**index是否在arr长度范围内 + * @param index + * @param array + * @return + */ + public static boolean isIndexInRange(Integer index, Object[] array) { + return index != null && index >= 0 && index < count(array); + } + + /**获取在arr长度范围内的index + * defaultIndex = 0 + * @param index + * @param array + * @return + */ + public static int getIndexInRange(Integer index, Object[] array) { + return getIndexInRange(index, array, 0); + } + /**获取在arr长度范围内的index + * @param index + * @param array + * @param defaultIndex + * @return + */ + public static int getIndexInRange(Integer index, Object[] array, int defaultIndex) { + return isIndexInRange(index, array) ? index : defaultIndex; + } + + /**获取在arr长度范围内的index + * defaultIndex = 0 + * @param + * @param index + * @param array + * @return + */ + public static T getInRange(Integer index, T[] array) { + return getInRange(index, array, 0); + } + /**获取在arr长度范围内的index + * @param + * @param index + * @param array + * @param defaultIndex + * @return + */ + public static T getInRange(Integer index, T[] array, int defaultIndex) { + return get(array, getIndexInRange(index, array, defaultIndex)); + } + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Comment.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Comment.java new file mode 100644 index 000000000..d89d1f8f4 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Comment.java @@ -0,0 +1,24 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server.model; + +import zuo.biao.apijson.MethodAccess; + +/**评论 + * @author Lemon + */ +@MethodAccess +public class Comment { +} \ No newline at end of file diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Contract.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Contract.java new file mode 100644 index 000000000..f27592f63 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Contract.java @@ -0,0 +1,18 @@ +package apijson.demo.server.model; + +import zuo.biao.apijson.MethodAccess; + +import static zuo.biao.apijson.RequestRole.*; + +/** + * @author hjt + * @date 2018/8/28 + * @description + */ +@MethodAccess( + POST = {UNKNOWN, ADMIN}, + DELETE = {UNKNOWN,ADMIN,LOGIN,CONTACT,CIRCLE,OWNER} +) +public class Contract { + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Login.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Login.java new file mode 100644 index 000000000..7ef67793f --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Login.java @@ -0,0 +1,62 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server.model; + +import static zuo.biao.apijson.RequestRole.ADMIN; +import static zuo.biao.apijson.RequestRole.CONTACT; +import static zuo.biao.apijson.RequestRole.LOGIN; +import static zuo.biao.apijson.RequestRole.OWNER; +import static zuo.biao.apijson.RequestRole.UNKNOWN; + +import zuo.biao.apijson.MethodAccess; + +/**登录日志 + * @author Lemon + */ +@SuppressWarnings("serial") +@MethodAccess( + GET = {}, + HEAD = {}, + GETS = {UNKNOWN, LOGIN, CONTACT, OWNER, ADMIN}, + HEADS = {UNKNOWN, LOGIN, CONTACT, OWNER, ADMIN}, + POST = {ADMIN}, + PUT = {ADMIN}, + DELETE = {ADMIN} + ) +public class Login extends BaseModel { + + public static final int TYPE_PASSWORD = 0;//密码登录 + public static final int TYPE_VERIFY = 1;//验证码登录 + + private Integer type; + + public Login() { + super(); + } + public Login(long userId) { + this(); + setUserId(userId); + } + + + public Integer getType() { + return type; + } + public Login setType(Integer type) { + this.type = type; + return this; + } + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Moment.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Moment.java new file mode 100644 index 000000000..761c5a950 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Moment.java @@ -0,0 +1,32 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server.model; + +import static zuo.biao.apijson.RequestRole.ADMIN; +import static zuo.biao.apijson.RequestRole.CIRCLE; +import static zuo.biao.apijson.RequestRole.CONTACT; +import static zuo.biao.apijson.RequestRole.LOGIN; +import static zuo.biao.apijson.RequestRole.OWNER; + +import zuo.biao.apijson.MethodAccess; + +/**动态 + * @author Lemon + */ +@MethodAccess( + PUT = {LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}//TODO 还要细分,LOGIN,CONTACT只允许修改praiseUserIdList。数据库加role没用,应该将praiseUserIdList移到Praise表 + ) +public class Moment { +} \ No newline at end of file diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Privacy.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Privacy.java new file mode 100644 index 000000000..078867672 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Privacy.java @@ -0,0 +1,102 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server.model; + +import static zuo.biao.apijson.RequestRole.ADMIN; +import static zuo.biao.apijson.RequestRole.OWNER; +import static zuo.biao.apijson.RequestRole.UNKNOWN; + +import zuo.biao.apijson.MethodAccess; + +/** + * TODO 漏洞:如果GETS允许CONTACT,则CONTACT能看到自己的余额,tag可以不是Privacy-circle。 + * 所以需要在Request表中增加role字段。或者干脆这里GETS只允许OWNER, ADMIN,需要用其它角色查时走独立接口。 + */ +/**用户隐私信息 + * @author Lemon + */ +@MethodAccess( + GET = {}, + GETS = {OWNER, ADMIN}, + POST = {UNKNOWN, ADMIN}, + DELETE = {ADMIN} + ) +public class Privacy extends BaseModel { + private static final long serialVersionUID = 1L; + + public static final int PASSWORD_TYPE_LOGIN = 0; + public static final int PASSWORD_TYPE_PAY = 1; + + private String phone; //手机 + private String password; //登录密码,隐藏字段 + private String payPassword; //支付密码,隐藏字段 + private Double balance; //余额 + + public Privacy() { + super(); + } + + public Privacy(long id) { + this(); + setId(id); + } + + public Privacy(String phone, String password) { + this(); + setPhone(phone); + setPassword(password); + } + + + + public String getPhone() { + return phone; + } + public Privacy setPhone(String phone) { + this.phone = phone; + return this; + } + + /**get_password会转为password + * @return + */ + public String get__password() { + return password; + } + public Privacy setPassword(String password) { + this.password = password; + return this; + } + + /**get_PayPassword会转为PayPassword + * @return + */ + public String get__payPassword() { + return payPassword; + } + public Privacy setPayPassword(String payPassword) { + this.payPassword = payPassword; + return this; + } + + public Double getBalance() { + return balance; + } + public Privacy setBalance(Double balance) { + this.balance = balance; + return this; + } + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/User.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/User.java new file mode 100644 index 000000000..7e13f6280 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/User.java @@ -0,0 +1,103 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server.model; + +import static zuo.biao.apijson.RequestRole.ADMIN; +import static zuo.biao.apijson.RequestRole.UNKNOWN; + +import java.util.List; + +import zuo.biao.apijson.MethodAccess; +import zuo.biao.apijson.server.Visitor; + +/**用户开放信息 + * @author Lemon + */ +@MethodAccess( + POST = {UNKNOWN, ADMIN}, + DELETE = {ADMIN} + ) +public class User extends BaseModel implements Visitor { + private static final long serialVersionUID = 1L; + + public static final int SEX_MAIL = 0; + public static final int SEX_FEMALE = 1; + public static final int SEX_UNKNOWN = 2; + + + private Integer sex; //性别 + private String head; //头像url + private String name; //姓名 + private String tag; //标签 + private List pictureList; //照片列表 + private List contactIdList; //朋友列表 + + /**默认构造方法,JSON等解析时必须要有 + */ + public User() { + super(); + } + public User(long id) { + this(); + setId(id); + } + + public Integer getSex() { + return sex; + } + public User setSex(Integer sex) { + this.sex = sex; + return this; + } + public String getHead() { + return head; + } + public User setHead(String head) { + this.head = head; + return this; + } + public String getName() { + return name; + } + public User setName(String name) { + this.name = name; + return this; + } + public List getPictureList() { + return pictureList; + } + public User setPictureList(List pictureList) { + this.pictureList = pictureList; + return this; + } + + public String getTag() { + return tag; + } + public User setTag(String tag) { + this.tag = tag; + return this; + } + + public List getContactIdList() { + return contactIdList; + } + public User setContactIdList(List contactIdList) { + this.contactIdList = contactIdList; + return this; + } + + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Verify.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Verify.java new file mode 100644 index 000000000..b88cd2a98 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/Verify.java @@ -0,0 +1,88 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +package apijson.demo.server.model; + +import static zuo.biao.apijson.RequestRole.ADMIN; +import static zuo.biao.apijson.RequestRole.CIRCLE; +import static zuo.biao.apijson.RequestRole.CONTACT; +import static zuo.biao.apijson.RequestRole.LOGIN; +import static zuo.biao.apijson.RequestRole.OWNER; +import static zuo.biao.apijson.RequestRole.UNKNOWN; + +import zuo.biao.apijson.MethodAccess; + +/**验证码 + * @author Lemon + */ +@MethodAccess( + GET = {}, + HEAD = {}, + GETS = {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}, + HEADS = {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}, + POST = {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}, + PUT = {ADMIN}, + DELETE = {ADMIN} + ) +public class Verify extends BaseModel { + private static final long serialVersionUID = 1L; + + public static final int TYPE_LOGIN = 0; //登录 + public static final int TYPE_REGISTER = 1; //注册 + public static final int TYPE_PASSWORD = 2; //登录密码 + public static final int TYPE_PAY_PASSWORD = 3; //支付密码 + + private String phone; //手机 + private String verify; //验证码 + private Integer type; //验证类型 + + public Verify() { + super(); + } + /**type和phone为联合主键,必传 + * @param type + * @param phone + */ + public Verify(int type, String phone) { + this(); + setType(type); + setPhone(phone); + } + + + public String getVerify() { + return verify; + } + public Verify setVerify(String verify) { + this.verify = verify; + return this; + } + + public String getPhone() { + return phone; + } + public Verify setPhone(String phone) { + this.phone = phone; + return this; + } + + public Integer getType() { + return type; + } + public Verify setType(Integer type) { + this.type = type; + return this; + } + +} diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/package-info.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/package-info.java new file mode 100644 index 000000000..7a82728b7 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/model/package-info.java @@ -0,0 +1,26 @@ +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.*/ + +/** + * 服务端给出的model + * the names of classes equal the names of tables in Server database one by one, so do the variables and columns + * (name) : model <=> table + * (name, type) : variable <=> column + * @warn don't use any base type like int or char in models, use Integer and String instead + */ +/** + * @author Lemon + * + */ +package apijson.demo.server.model; \ No newline at end of file diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/package-info.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/package-info.java new file mode 100644 index 000000000..487e27c06 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/java/apijson/demo/server/package-info.java @@ -0,0 +1,8 @@ +/** + * 示例服务端工程包 + */ +/** + * @author Lemon + * + */ +package apijson.demo.server; \ No newline at end of file diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/resources/application.yml b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/resources/application.yml new file mode 100644 index 000000000..8a830750e --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/main/resources/application.yml @@ -0,0 +1,5 @@ +url: jdbc:oracle:thin:@192.168.2.155:1521:orcl +username: db3 +password: 123456 +driverclassame: oracle.jdbc.driver.OracleDriver +schema: db3 diff --git a/APIJSON-Java-Server/APIJSONDemo_oracle/src/test/java/zuo/biao/apijson/server/ApplicationTests.java b/APIJSON-Java-Server/APIJSONDemo_oracle/src/test/java/zuo/biao/apijson/server/ApplicationTests.java new file mode 100644 index 000000000..6dcfe9e64 --- /dev/null +++ b/APIJSON-Java-Server/APIJSONDemo_oracle/src/test/java/zuo/biao/apijson/server/ApplicationTests.java @@ -0,0 +1,17 @@ +package zuo.biao.apijson.server; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ApplicationTests { + + @Test + public void contextLoads() { + //TODO Test Case,包括GitHub README介绍和简版demo + } + +}