onlyxx
4 years ago
commit
760f7ab0c3
22 changed files with 737 additions and 0 deletions
@ -0,0 +1,128 @@
|
||||
apply plugin: 'java' |
||||
|
||||
|
||||
ext { |
||||
/** |
||||
* 项目中依赖的jar的路径 |
||||
* 1.如果依赖的jar需要打包到zip中,放置在lib根目录下 |
||||
* 2.如果依赖的jar仅仅是编译时需要,防止在lib下子目录下即可 |
||||
*/ |
||||
libPath = "$projectDir/../webroot/WEB-INF/lib" |
||||
|
||||
/** |
||||
* 是否对插件的class进行加密保护,防止反编译 |
||||
*/ |
||||
guard = true |
||||
|
||||
def pluginInfo = getPluginInfo() |
||||
pluginPre = "fine-plugin" |
||||
pluginName = pluginInfo.id |
||||
pluginVersion = pluginInfo.version |
||||
|
||||
outputPath = "$projectDir/../webroot/WEB-INF/plugins/plugin-" + pluginName + "-1.0/classes" |
||||
} |
||||
|
||||
group = 'com.fr.plugin' |
||||
version = '10.0' |
||||
sourceCompatibility = '8' |
||||
|
||||
sourceSets { |
||||
main { |
||||
java.outputDir = file(outputPath) |
||||
output.resourcesDir = file(outputPath) |
||||
} |
||||
} |
||||
|
||||
ant.importBuild("encrypt.xml") |
||||
//定义ant变量 |
||||
ant.projectDir = projectDir |
||||
ant.references["compile.classpath"] = ant.path { |
||||
fileset(dir: libPath, includes: '**/*.jar') |
||||
fileset(dir: ".", includes: "**/*.jar") |
||||
} |
||||
|
||||
classes.dependsOn('clean') |
||||
|
||||
task copyFiles(type: Copy, dependsOn: 'classes') { |
||||
from outputPath |
||||
into "$projectDir/classes" |
||||
} |
||||
|
||||
task preJar(type: Copy, dependsOn: guard ? 'compile_encrypt_javas' : 'compile_plain_javas') { |
||||
from "$projectDir/classes" |
||||
into "$projectDir/transform-classes" |
||||
include "**/*.*" |
||||
} |
||||
jar.dependsOn("preJar") |
||||
classes.dependsOn("copyPluginXML") |
||||
|
||||
task copyPluginXML(type: Copy) { |
||||
print "copyed plugin.xml file" |
||||
from "$projectDir/plugin.xml" |
||||
into file("$projectDir/../webroot/WEB-INF/plugins/plugin-" + pluginName + "-1.0/") |
||||
} |
||||
task makeJar(type: Jar, dependsOn: preJar) { |
||||
from fileTree(dir: "$projectDir/transform-classes") |
||||
baseName pluginPre |
||||
appendix pluginName |
||||
version pluginVersion |
||||
destinationDir = file("$buildDir/libs") |
||||
|
||||
doLast() { |
||||
delete file("$projectDir/classes") |
||||
delete file("$projectDir/transform-classes") |
||||
} |
||||
} |
||||
|
||||
task copyFile(type: Copy, dependsOn: ["makeJar"]) { |
||||
from "$buildDir/libs" |
||||
from("$projectDir/lib") { |
||||
include "*.jar" |
||||
} |
||||
from "$projectDir/plugin.xml" |
||||
into file("$buildDir/temp/plugin") |
||||
} |
||||
|
||||
task zip(type: Zip, dependsOn: ["copyFile"]) { |
||||
from "$buildDir/temp/plugin" |
||||
destinationDir file("$buildDir/install") |
||||
baseName pluginPre |
||||
appendix pluginName |
||||
version pluginVersion |
||||
} |
||||
|
||||
//控制build时包含哪些文件,排除哪些文件 |
||||
processResources { |
||||
// exclude everything |
||||
// 用*.css没效果 |
||||
// exclude '**/*.css' |
||||
// except this file |
||||
// include 'xx.xml' |
||||
} |
||||
|
||||
/*读取plugin.xml中的version*/ |
||||
|
||||
def getPluginInfo() { |
||||
def xmlFile = file("plugin.xml") |
||||
if (!xmlFile.exists()) { |
||||
return ["id": "none", "version": "1.0.0"] |
||||
} |
||||
def plugin = new XmlParser().parse(xmlFile) |
||||
def version = plugin.version[0].text() |
||||
def id = plugin.id[0].text() |
||||
return ["id": id, "version": version] |
||||
} |
||||
|
||||
repositories { |
||||
mavenLocal() |
||||
maven { |
||||
url = uri('http://mvn.finedevelop.com/repository/maven-public/') |
||||
} |
||||
} |
||||
|
||||
dependencies { |
||||
//使用本地jar |
||||
implementation fileTree(dir: 'lib', include: ['**/*.jar']) |
||||
implementation fileTree(dir: libPath, include: ['**/*.jar']) |
||||
} |
||||
|
Binary file not shown.
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<project> |
||||
<target name="compile_encrypt_javas" depends="copyFiles"> |
||||
<echo message="加密文件"/> |
||||
<echo message="${projectDir}"/> |
||||
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask"> |
||||
<classpath refid="compile.classpath"/> |
||||
</taskdef> |
||||
<pretreatment baseDir="${projectDir}"/> |
||||
</target> |
||||
<target name="compile_plain_javas" depends="copyFiles"> |
||||
</target> |
||||
</project> |
Binary file not shown.
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<plugin> |
||||
<id>com.fr.plugin.zzl.db.config</id> |
||||
<name><![CDATA[插件数据库访问和配置演示]]></name> |
||||
<active>yes</active> |
||||
<version>1.0</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>author</vendor> |
||||
<description><![CDATA[通过数据库接口访问数据库]]></description> |
||||
<change-notes><![CDATA[ |
||||
[2018-08-01]修改一点问题。<br/> |
||||
[2018-07-31]初始化插件。<br/> |
||||
]]></change-notes> |
||||
<!-- 插件生命周期声明--> |
||||
<lifecycle-monitor class="com.fr.plugin.MyLife"/> |
||||
<!---设计器上用的访问数据库--> |
||||
<!-- <extra-core>--> |
||||
<!-- <DBAccessProvider class="com.fr.plugin.MyDBAccessProvider"/>--> |
||||
<!-- </extra-core>--> |
||||
|
||||
<!---decision网页服务中的数据库访问--> |
||||
<extra-decision> |
||||
<DecisionDBAccessProvider class="com.fr.plugin.MyDecisionDBAccessProvider"/> |
||||
</extra-decision> |
||||
|
||||
<extra-decision> |
||||
<HttpHandlerProvider class="com.fr.plugin.MyHttpProvider"/> |
||||
<URLAliasProvider class="com.fr.plugin.MyURLAlias2Provider"/> |
||||
</extra-decision> |
||||
<!--国际化注册--> |
||||
<extra-core> |
||||
<LocaleFinder class="com.fr.plugin.MyLocalFinder"/> |
||||
</extra-core> |
||||
<function-recorder class="com.fr.plugin.MyDecisionDBAccessProvider"/> |
||||
</plugin> |
@ -0,0 +1,50 @@
|
||||
package com.fr.plugin; |
||||
|
||||
|
||||
import com.fr.decision.plugin.db.AbstractDecisionDBAccessProvider; |
||||
import com.fr.plugin.dao.MyDao; |
||||
import com.fr.plugin.entity.MyEntity; |
||||
import com.fr.plugin.transform.ExecuteFunctionRecord; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.stable.db.accessor.DBAccessor; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.dao.DAOProvider; |
||||
|
||||
//第一步类 继承AbstractDecisionDBAccessProvider
|
||||
@FunctionRecorder |
||||
public class MyDecisionDBAccessProvider extends AbstractDecisionDBAccessProvider { |
||||
|
||||
//第二步 注册数据库访问类
|
||||
@Override |
||||
@ExecuteFunctionRecord |
||||
public DAOProvider[] registerDAO() { |
||||
return new DAOProvider[]{ |
||||
//注意这里是匿名类
|
||||
new DAOProvider() { |
||||
@Override |
||||
public Class getEntityClass() { |
||||
return MyEntity.class; |
||||
} |
||||
|
||||
@Override |
||||
public Class<? extends BaseDAO> getDAOClass() { |
||||
return MyDao.class; |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
|
||||
//第三步新建一个DBAccessor 静态变量
|
||||
private static DBAccessor dbAccessor = null; |
||||
|
||||
//第四步写一个公开的静态方法去获取DBAccessor
|
||||
public static DBAccessor getDbAccessor() { |
||||
return dbAccessor; |
||||
} |
||||
|
||||
//第五步 重写数据库访问器注入函数(当数据库访问器准备好之后由fr注入到这里)
|
||||
@Override |
||||
public void onDBAvailable(DBAccessor dbAccessor) { |
||||
MyDecisionDBAccessProvider.dbAccessor = dbAccessor; |
||||
} |
||||
} |
@ -0,0 +1,6 @@
|
||||
package com.fr.plugin; |
||||
|
||||
public class MyFunctionConstants { |
||||
|
||||
public static final String PLUGIN_ID = "com.fr.plugin.zzl.db.config"; |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fr.plugin; |
||||
|
||||
import com.fr.decision.fun.HttpHandler; |
||||
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider; |
||||
import com.fr.plugin.http.AddApi; |
||||
import com.fr.plugin.http.ListApi; |
||||
import com.fr.plugin.http.ModApi; |
||||
|
||||
public class MyHttpProvider extends AbstractHttpHandlerProvider { |
||||
@Override |
||||
public HttpHandler[] registerHandlers() { |
||||
return new HttpHandler[]{ |
||||
new ListApi(), |
||||
new AddApi(), |
||||
new ModApi() |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.fr.plugin; |
||||
|
||||
import com.fr.plugin.config.MyConfig; |
||||
import com.fr.plugin.config.MySimpleConfig; |
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
|
||||
public class MyLife extends AbstractPluginLifecycleMonitor { |
||||
@Override |
||||
public void afterRun(PluginContext pluginContext) { |
||||
MyConfig.getInstance();//初始化激活一下插件配置
|
||||
MySimpleConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public void beforeStop(PluginContext pluginContext) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,10 @@
|
||||
package com.fr.plugin; |
||||
|
||||
import com.fr.stable.fun.impl.AbstractLocaleFinder; |
||||
|
||||
public class MyLocalFinder extends AbstractLocaleFinder { |
||||
@Override |
||||
public String find() { |
||||
return "com/fr/plugin/my18n"; |
||||
} |
||||
} |
@ -0,0 +1,20 @@
|
||||
package com.fr.plugin; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractURLAliasProvider; |
||||
import com.fr.decision.webservice.url.alias.URLAlias; |
||||
import com.fr.decision.webservice.url.alias.URLAliasFactory; |
||||
import com.fr.plugin.transform.ExecuteFunctionRecord; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
|
||||
@FunctionRecorder |
||||
public class MyURLAlias2Provider extends AbstractURLAliasProvider { |
||||
@Override |
||||
@ExecuteFunctionRecord |
||||
public URLAlias[] registerAlias() { |
||||
return new URLAlias[]{ |
||||
URLAliasFactory.createPluginAlias("/createMyData","/add",true), |
||||
URLAliasFactory.createPluginAlias("/editorMyData","/mod",true), |
||||
URLAliasFactory.createPluginAlias("/listMyData","/list",true), |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,53 @@
|
||||
package com.fr.plugin.config; |
||||
|
||||
import com.fr.config.ConfigContext; |
||||
import com.fr.config.DefaultConfiguration; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
//第一步类继承自DefaultConfiguration
|
||||
public class MyConfig extends DefaultConfiguration { |
||||
private static MyConfig config = null; |
||||
|
||||
//第二步写一个单例访问器(相当于注册配置和初始化)
|
||||
public static MyConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(MyConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
//补充,可以通过重写这个父类实现来实现在数据库中配置的namespace
|
||||
@Override |
||||
public String getNameSpace() { |
||||
return "zzlMyConfig"; |
||||
} |
||||
|
||||
//第三步 注册要写的配置
|
||||
private Conf<Integer> minSource = Holders.simple(60); |
||||
private Conf<Integer> maxSource = Holders.simple(100); |
||||
|
||||
//第四步生成对应配置的get和set,注意这里要手动将Conf<*> 直接改成 *
|
||||
// public void setApiUrl(Conf<String> apiUrl) {
|
||||
// this.apiUrl = apiUrl;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
public Integer getMinSource() { |
||||
return minSource.get(); |
||||
} |
||||
|
||||
public void setMinSource(Integer minSource) { |
||||
this.minSource.set(minSource); |
||||
} |
||||
|
||||
public Integer getMaxSource() { |
||||
return maxSource.get(); |
||||
} |
||||
|
||||
public void setMaxSource(Integer maxSource) { |
||||
this.maxSource.set(maxSource); |
||||
} |
||||
} |
@ -0,0 +1,85 @@
|
||||
package com.fr.plugin.config; |
||||
|
||||
import com.fr.config.*; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
@Visualization(category = "Plugin-Config_Demo") |
||||
public class MySimpleConfig extends DefaultConfiguration { |
||||
private static volatile MySimpleConfig config = null; |
||||
|
||||
public static MySimpleConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(MySimpleConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
|
||||
@Identifier(value = "text", name = "Plugin-Config_Property_Text", description = "Plugin-Config_Property_Text_Description", status = Status.SHOW) |
||||
private Conf<String> text = Holders.simple(StringUtils.EMPTY); |
||||
|
||||
@Identifier(value = "count", name = "Plugin-Config_Property_Count", description = "Plugin-Config_Property_Count_Description", status = Status.SHOW) |
||||
private Conf<Integer> count = Holders.simple(100); |
||||
|
||||
@Identifier(value = "price", name = "Plugin-Config_Property_Price", description = "Plugin-Config_Property_Price_Description", status = Status.SHOW) |
||||
private Conf<Double> price = Holders.simple(1000.0); |
||||
|
||||
@Identifier(value = "time", name = "Plugin-Config_Property_Time", description = "Plugin-Config_Property_Time_Description", status = Status.SHOW) |
||||
private Conf<Long> time = Holders.simple(99999999L); |
||||
|
||||
@Identifier(value = "student", name = "Plugin-Config_Property_Student", description = "Plugin-Config_Property_Student_Description", status = Status.SHOW) |
||||
private Conf<Boolean> student = Holders.simple(true); |
||||
|
||||
public String getText() { |
||||
return text.get(); |
||||
} |
||||
|
||||
public void setText(String text) { |
||||
this.text.set(text); |
||||
} |
||||
|
||||
public Integer getCount() { |
||||
return count.get(); |
||||
} |
||||
|
||||
public void setCount(Integer count) { |
||||
this.count.set(count); |
||||
} |
||||
|
||||
public Double getPrice() { |
||||
return price.get(); |
||||
} |
||||
|
||||
public void setPrice(Double price) { |
||||
this.price.set(price); |
||||
} |
||||
|
||||
public Long getTime() { |
||||
return time.get(); |
||||
} |
||||
|
||||
public void setTime(Long time) { |
||||
this.time.set(time); |
||||
} |
||||
|
||||
public Boolean getStudent() { |
||||
return student.get(); |
||||
} |
||||
|
||||
public void setStudent(Boolean student) { |
||||
this.student.set(student); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
MySimpleConfig cloned = (MySimpleConfig) super.clone(); |
||||
cloned.text = (Conf<String>) text.clone(); |
||||
cloned.count = (Conf<Integer>) count.clone(); |
||||
cloned.price = (Conf<Double>) price.clone(); |
||||
cloned.time = (Conf<Long>) time.clone(); |
||||
cloned.student = (Conf<Boolean>) student.clone(); |
||||
return cloned; |
||||
} |
||||
} |
@ -0,0 +1,17 @@
|
||||
package com.fr.plugin.dao; |
||||
|
||||
import com.fr.plugin.entity.MyEntity; |
||||
import com.fr.stable.db.dao.BaseDAO; |
||||
import com.fr.stable.db.session.DAOSession; |
||||
|
||||
|
||||
public class MyDao extends BaseDAO<MyEntity> { |
||||
public MyDao(DAOSession daoSession) { |
||||
super(daoSession); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<MyEntity> getEntityClass() { |
||||
return MyEntity.class; |
||||
} |
||||
} |
@ -0,0 +1,59 @@
|
||||
package com.fr.plugin.entity; |
||||
|
||||
import com.fr.stable.db.entity.BaseEntity; |
||||
import com.fr.third.javax.persistence.Column; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.javax.persistence.Table; |
||||
|
||||
import java.util.Date; |
||||
|
||||
//第一步添加这两个注解,特别是table的name属性要唯一,并将类继承到BaseEntity,会自动生产id字段
|
||||
@Entity |
||||
@Table( |
||||
name = "zzl_my_table" |
||||
) |
||||
public class MyEntity extends BaseEntity { |
||||
|
||||
//第二步注册要使用的字段加上@Column注解
|
||||
@Column( |
||||
name = "userName", |
||||
unique = true |
||||
// scale = 0,
|
||||
// length = 255
|
||||
) |
||||
private String userName; |
||||
|
||||
@Column( |
||||
name = "source" |
||||
) |
||||
private Integer source; |
||||
@Column( |
||||
name = "createTime" |
||||
) |
||||
private Date createTime; |
||||
|
||||
//第三步生成对应的get和set
|
||||
public String getUserName() { |
||||
return userName; |
||||
} |
||||
|
||||
public void setUserName(String userName) { |
||||
this.userName = userName; |
||||
} |
||||
|
||||
public Integer getSource() { |
||||
return source; |
||||
} |
||||
|
||||
public void setSource(Integer source) { |
||||
this.source = source; |
||||
} |
||||
|
||||
public Date getCreateTime() { |
||||
return createTime; |
||||
} |
||||
|
||||
public void setCreateTime(Date createTime) { |
||||
this.createTime = createTime; |
||||
} |
||||
} |
@ -0,0 +1,77 @@
|
||||
package com.fr.plugin.http; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.MyDecisionDBAccessProvider; |
||||
import com.fr.plugin.config.MyConfig; |
||||
import com.fr.plugin.dao.MyDao; |
||||
import com.fr.plugin.entity.MyEntity; |
||||
import com.fr.stable.db.accessor.DBAccessor; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.Date; |
||||
import java.util.UUID; |
||||
|
||||
public class AddApi extends BaseHttpHandler { |
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/add"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { |
||||
DBAccessor dbAccessor = MyDecisionDBAccessProvider.getDbAccessor(); |
||||
//通过这两个函数获取的参数可以避免中文乱码和空指针
|
||||
String userName = WebUtils.getHTTPRequestParameter(httpServletRequest, "userName"); |
||||
Integer source = WebUtils.getHTTPRequestIntParameter(httpServletRequest, "source"); |
||||
//使用配置
|
||||
MyConfig myConfig = MyConfig.getInstance(); |
||||
Integer minSource = myConfig.getMinSource(); |
||||
Integer maxSource = myConfig.getMaxSource(); |
||||
|
||||
//参数校验
|
||||
if(source<minSource){ |
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put("msg", "add source fail ,source lees than "+minSource); |
||||
jsonObject.put("code", 100); |
||||
WebUtils.printAsJSON(httpServletResponse, jsonObject); |
||||
return; |
||||
} |
||||
|
||||
if(source>maxSource){ |
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put("msg", "add source fail ,source bigger than "+maxSource); |
||||
jsonObject.put("code", 101); |
||||
WebUtils.printAsJSON(httpServletResponse, jsonObject); |
||||
return; |
||||
} |
||||
MyEntity myEntity = new MyEntity(); |
||||
myEntity.setSource(source); |
||||
myEntity.setUserName(userName); |
||||
myEntity.setId(UUID.randomUUID().toString()); |
||||
myEntity.setCreateTime(new Date()); |
||||
|
||||
//执行新增操作
|
||||
dbAccessor.runDMLAction(daoContext -> { |
||||
daoContext.getDAO(MyDao.class).add(myEntity); |
||||
return null; |
||||
}); |
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put("msg", "success"); |
||||
jsonObject.put("code", 200); |
||||
WebUtils.printAsJSON(httpServletResponse, jsonObject); |
||||
} |
||||
} |
@ -0,0 +1,56 @@
|
||||
package com.fr.plugin.http; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONArrayWriter; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.json.JSONObjectWriter; |
||||
import com.fr.plugin.MyDecisionDBAccessProvider; |
||||
import com.fr.plugin.dao.MyDao; |
||||
import com.fr.plugin.entity.MyEntity; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.db.accessor.DBAccessor; |
||||
import com.fr.stable.db.action.DBAction; |
||||
import com.fr.stable.db.dao.DAOContext; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.condition.QueryCondition; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.List; |
||||
|
||||
public class ListApi extends BaseHttpHandler { |
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/list"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { |
||||
DBAccessor dbAccessor = MyDecisionDBAccessProvider.getDbAccessor(); |
||||
String userName = httpServletRequest.getParameter("userName"); |
||||
List<MyEntity> entityList = dbAccessor.runQueryAction(daoContext -> { |
||||
QueryCondition queryCondition = QueryFactory.create(); |
||||
if (StringUtils.isNotBlank(userName) ) { |
||||
queryCondition.addRestriction(RestrictionFactory.eq("userName", userName)); |
||||
} |
||||
List<MyEntity> entityList1 = daoContext.getDAO(MyDao.class).find(queryCondition); |
||||
return entityList1; |
||||
}); |
||||
JSONArray jsonArray = JSONArray.create(entityList); |
||||
WebUtils.printAsJSON(httpServletResponse, jsonArray); |
||||
} |
||||
} |
@ -0,0 +1,63 @@
|
||||
package com.fr.plugin.http; |
||||
|
||||
import com.fr.decision.fun.impl.BaseHttpHandler; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.MyDecisionDBAccessProvider; |
||||
import com.fr.plugin.dao.MyDao; |
||||
import com.fr.plugin.entity.MyEntity; |
||||
import com.fr.stable.db.accessor.DBAccessor; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
import com.fr.third.springframework.web.bind.annotation.RequestMethod; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.Date; |
||||
import java.util.UUID; |
||||
|
||||
public class ModApi extends BaseHttpHandler { |
||||
@Override |
||||
public RequestMethod getMethod() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public String getPath() { |
||||
return "/mod"; |
||||
} |
||||
|
||||
@Override |
||||
public boolean isPublic() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { |
||||
DBAccessor dbAccessor = MyDecisionDBAccessProvider.getDbAccessor(); |
||||
//通过这两个函数获取的参数可以避免中文乱码和空指针
|
||||
String userName = WebUtils.getHTTPRequestParameter(httpServletRequest, "userName"); |
||||
Integer source = WebUtils.getHTTPRequestIntParameter(httpServletRequest, "source"); |
||||
//先查找要更新的用户
|
||||
MyEntity entity = dbAccessor.runQueryAction(daoContext -> daoContext.getDAO(MyDao.class) |
||||
.findOne(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))) |
||||
); |
||||
if (entity != null) { |
||||
entity.setSource(source); |
||||
dbAccessor.runDMLAction(daoContext -> { |
||||
//执行更新操作
|
||||
daoContext.getDAO(MyDao.class).update(entity); |
||||
return null; |
||||
}); |
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put("msg", "success"); |
||||
jsonObject.put("code", 200); |
||||
WebUtils.printAsJSON(httpServletResponse, jsonObject); |
||||
} else { |
||||
JSONObject jsonObject = new JSONObject(); |
||||
jsonObject.put("msg", "user not find"); |
||||
jsonObject.put("code", -1); |
||||
WebUtils.printAsJSON(httpServletResponse, jsonObject); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
Plugin-Config_Demo=MyConfig |
||||
Plugin-Config_Property_Text=Account |
||||
Plugin-Config_Property_Count=Count |
||||
Plugin-Config_Property_Text_Description=This is a text property. |
||||
Plugin-Config_Property_Count_Description=This is a int property. |
||||
Plugin-Config_Group=Plugin |
||||
Plugin-Config_Property_Price=Price |
||||
Plugin-Config_Property_Price_Description=This is a price property. |
||||
Plugin-Config_Property_Time=Time |
||||
Plugin-Config_Property_Time_Description=This is a time proeprty. |
||||
Plugin-Config_Property_Student=Student |
||||
Plugin-Config_Property_Student_Description=This is a bool property. |
@ -0,0 +1,12 @@
|
||||
Plugin-Config_Demo=\u793A\u4F8B\u63D2\u4EF6 |
||||
Plugin-Config_Property_Text=\u8D26\u53F7 |
||||
Plugin-Config_Property_Count=\u6570\u91CF |
||||
Plugin-Config_Property_Text_Description=\u8FD9\u662F\u4E00\u4E2A\u6587\u672C\u7C7B\u578B\u7684\u914D\u7F6E\u5C5E\u6027\u3002 |
||||
Plugin-Config_Property_Count_Description=\u8FD9\u662F\u4E00\u4E2A\u6574\u6570\u7C7B\u578B\u7684\u914D\u7F6E\u5C5E\u6027\u3002 |
||||
Plugin-Config_Group=\u63D2\u4EF6\u914D\u7F6E |
||||
Plugin-Config_Property_Price=\u4EF7\u683C |
||||
Plugin-Config_Property_Price_Description=\u8FD9\u662F\u7528\u6765\u8BBE\u7F6E\u4EF7\u683C\u7684\u3002 |
||||
Plugin-Config_Property_Time=\u65F6\u95F4 |
||||
Plugin-Config_Property_Time_Description=\u8FD9\u662F\u7528\u6765\u8BBE\u7F6E\u6709\u6548\u65F6\u95F4\u7684 |
||||
Plugin-Config_Property_Student=\u5B66\u751F |
||||
Plugin-Config_Property_Student_Description=\u8FD9\u662F\u7528\u6765\u8BBE\u7F6E\u662F\u5426\u4E3A\u5B66\u751F\u7684\u3002 |
Loading…
Reference in new issue