用户工具

站点工具


light4j:apijson
  • 添加依赖
git clone https://gitee.com/APIJSON/APIJSON.git
//创建数据库apijson,导入MySQL目录下的sql脚本
mvn source:jar install -f APIJSON-Java-Server/APIJSONORM/pom.xml
mvn source:jar install -f APIJSON-Java-Server/APIJSONFramework/pom.xml
    <properties>
        <version.apijson>4.1.0</version.apijson>
    </properties>
		<dependency>
			<groupId>apijson.orm</groupId>
			<artifactId>apijson-orm</artifactId>
			<version>${version.apijson}</version>
		</dependency>
		<dependency>
			<groupId>apijson.framework</groupId>
			<artifactId>apijson-framework</artifactId>
			<version>${version.apijson}</version>
		</dependency>
  • 运行框架
final SqlConfig SQLCONFIG = new APIJSONSQLConfig() {
	public String getSchema() { return "apijson"; } //默认DBUri=jdbc:mysql://localhost:3306,schema=sys
	public String getDBPassword() { return "admin"; } //默认DBAccount=root,DBPassword=apijson
};
APIJSONApplication.DEFAULT_APIJSON_CREATOR = new APIJSONCreator() {
	public SQLConfig createSQLConfig() {
		return SQLCONFIG;
	}
};
Log.DEBUG = NumberUtil.parseBoolean(System.getProperty("apijson.debug"), false);
APIJSONApplication.init();
  • 处理请求
public class ApijsonHandler extends AbstractHandler {
	private static final APIJSONController apijson = new APIJSONController();
	//获取get 计数head 新增post 修改put 删除delete 登录login 登出logout
	public void get(HttpServerExchange exchange) throws Exception {
		String json = apijson.get(HandlerUtil.getBodyString(exchange), null);
		jsonResp(exchange, json);
	}
	public static void jsonResp(HttpServerExchange exchange, String json) {
		exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, HandlerUtil.MIMETYPE_JSON);
		exchange.setStatusCode(200);
		exchange.getResponseSender().send(json);
	}
}
light4j/apijson.txt · 最后更改: 2020/08/20 18:07 由 admin