commit 6502c36e23d39df29f9daf6274068141f8ecff10 Author: lyf666 Date: Tue Feb 21 14:38:18 2017 +0800 . diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5bf9d39 --- /dev/null +++ b/.gitignore @@ -0,0 +1,73 @@ +# Created by .ignore support plugin (hsz.mobi) +### Maven template +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +### Java template +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml + +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +*.iml +.idea \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e821cf5 --- /dev/null +++ b/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + + cn.cloudowr + ywxj.shangbao + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5 + + 1.8 + 1.8 + + + + org.eclipse.jetty + jetty-maven-plugin + 9.4.0.v20161208 + + stop + 5206 + + / + + 5 + + 4206 + 60000 + + + + + + + + com.jfinal + jfinal + 3.0 + + + com.jfinal + jetty-server + 8.1.8 + + + + + + + + com.alibaba + fastjson + 1.2.24 + + + + + + + + org.mongodb + mongo-java-driver + 3.4.2 + + + cn.cloudowr + sdk + 1.3.4 + + + \ No newline at end of file diff --git a/src/main/java/cn/cloudowr/ywxj/shangbao/Config.java b/src/main/java/cn/cloudowr/ywxj/shangbao/Config.java new file mode 100644 index 0000000..5a5f53e --- /dev/null +++ b/src/main/java/cn/cloudowr/ywxj/shangbao/Config.java @@ -0,0 +1,88 @@ +package cn.cloudowr.ywxj.shangbao; + +import cn.cloudowr.sdk.JQueryParameterFilter; +import cn.cloudowr.sdk.jfinal.ErrorInterceptor; +import com.jfinal.config.*; +import com.jfinal.template.Engine; +import com.mongodb.MongoClient; +import com.mongodb.MongoCredential; +import com.mongodb.ServerAddress; +import com.mongodb.client.MongoDatabase; + +import java.util.Arrays; + +/** + * Created by lyf66 on 2017/2/18. + */ +public class Config extends JFinalConfig{ + private static MongoDatabase mongoDatabase; + + public static MongoDatabase getMongoDatabase() { + return mongoDatabase; + } + + @Override + public void configConstant(Constants me) { + } + + @Override + public void configRoute(Routes me) { + me.add("/", Controller.class); + } + + @Override + public void configEngine(Engine me) { + + } + + @Override + public void configPlugin(Plugins me) { +// String db_type = PropKit.get(ConstConfig.db_type_key); +// DruidPlugin druidPlugin = new DruidPlugin( +// PropKit.get(ConstConfig.db_connection_jdbcUrl), +// PropKit.get(ConstConfig.db_connection_userName), +// PropKit.get(ConstConfig.db_connection_passWord), +// PropKit.get(ConstConfig.db_connection_driverClass)); +// +// druidPlugin.set( +// PropKit.getInt(ConstConfig.db_initialSize), +// PropKit.getInt(ConstConfig.db_minIdle), +// PropKit.getInt(ConstConfig.db_maxActive)); +// +// druidPlugin.addFilter(new StatFilter()); +// WallFilter wall = new WallFilter(); +// wall.setDbType(db_type); +// WallConfig config = new WallConfig(); +// config.setFunctionCheck(false); // 支持数据库函数 +// wall.setConfig(config); +// druidPlugin.addFilter(wall); +// +// ActiveRecordPlugin arp = new ActiveRecordPlugin(ConstConfig.db_dataSource_main, druidPlugin); +// //arp.setTransactionLevel(4);//事务隔离级别 +// boolean devMode = PropKit.getBoolean(ConstConfig.config_devMode); +// arp.setDevMode(devMode); // 设置开发模式 +// arp.setShowSql(devMode); // 是否显示SQL +// +// arp.setDialect(new MysqlDialect()); +// me.add(druidPlugin); // 多数据源继续添加 + } + + @Override + public void configInterceptor(Interceptors me) { + me.add(new JQueryParameterFilter()); + me.add(new ErrorInterceptor()); + } + + @Override + public void configHandler(Handlers me) { + + } + + @Override + public void afterJFinalStart() { + MongoCredential mongoCredential = MongoCredential.createCredential("root", "admin", "CoWR1111".toCharArray()); + MongoClient mongoClient = new MongoClient(new ServerAddress("120.24.5.249", 3717), Arrays.asList(mongoCredential)); + mongoDatabase = mongoClient.getDatabase("dict"); + } + +} diff --git a/src/main/java/cn/cloudowr/ywxj/shangbao/Controller.java b/src/main/java/cn/cloudowr/ywxj/shangbao/Controller.java new file mode 100644 index 0000000..905eaa7 --- /dev/null +++ b/src/main/java/cn/cloudowr/ywxj/shangbao/Controller.java @@ -0,0 +1,21 @@ +package cn.cloudowr.ywxj.shangbao; + +import cn.cloudowr.sdk.jfinal.AbsController; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import org.bson.Document; + +/** + * Created by lyf66 on 2017/2/20. + */ +public class Controller extends AbsController{ + public void ping() { + renderText("ywxj.shangbao pong"); + } + @Override + public MongoCollection getCollection() { + MongoDatabase mongoDataBase = Config.getMongoDatabase(); + MongoCollection collection = mongoDataBase.getCollection("shangbao"); + return collection; + } +} diff --git a/src/main/java/cn/cloudowr/ywxj/shangbao/Main.java b/src/main/java/cn/cloudowr/ywxj/shangbao/Main.java new file mode 100644 index 0000000..03e25c9 --- /dev/null +++ b/src/main/java/cn/cloudowr/ywxj/shangbao/Main.java @@ -0,0 +1,12 @@ +package cn.cloudowr.ywxj.shangbao; + +import com.jfinal.core.JFinal; + +/** + * Created by lyf66 on 2017/2/16. + */ +public class Main { + public static void main(String[] args) { + JFinal.start("src/main/webapp", 4206, "/"); + } +} diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..518c0ca --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,18 @@ + + + + cn.cloudowr.ywxj.shangbao + com.jfinal.core.JFinalFilter + + configClass + cn.cloudowr.ywxj.shangbao.Config + + + + cn.cloudowr.ywxj.shangbao + /* + + \ No newline at end of file diff --git a/src/main/webapp/doc/api.txt b/src/main/webapp/doc/api.txt new file mode 100644 index 0000000..8b95823 --- /dev/null +++ b/src/main/webapp/doc/api.txt @@ -0,0 +1,37 @@ +//model +shangbao { + id, + countycode required, + usetype required, + ...other +} +//route +index ( + pageSize optional default 20, + pageNum optional default 1, + json optional + ) { + special json: { + key: $ex //exists + key: $nex //not exists + key: $revalue //模糊查询,例:$re^te te开头的value + } + return dict list json +} +show (id required) { + return dict json +} +save (json required) { + return saved dict json with id +} +update (id required, json required) { + json { + $set: {k,v...}, + $unset: [k1,k2...], + $rename: {k,newK...} + } + return {result : true or false} +} +delete (id required) { + return {result: true or false} +} \ No newline at end of file