您的位置:首页 > 其它

基于反射实现自动化restful开发

2015-10-13 13:15 603 查看
[Author]: kwu

基于反射实现自动化restful开发,通用的只需要写查询数据库的sql,并加入对应的javabean实现的快速restful服务的开发。

1、编写数据库的查询sql,对应sql.properties

[sql] view
plaincopy

daily = DailyReport;select t.day,t.cnt,t.type from (select day,cnt,type From dailyreport where type=? order by day desc limit ? ) t order by t.day;String,Integer

SQL的属性文件,以";"分隔。说明:

1)pv为该SQL的标签。

2)第一个参数为,DailyReport为对应的JavaBean的类名

3)第二个参数为查询的SQL,参数以 "?" 占位符

4)第三个参数为 参数的类型,以"," 分隔

2、编写对应的pojo类

[java] view
plaincopy

import com.hexun.bean.base.ChartsData;



public class DailyReport implements ChartsData {

private String day, type;

private Integer cnt;



public String getDay() {

return day;

}



public void setDay(String day) {

this.day = day;

}



public String getType() {

return type;

}



public void setType(String type) {

this.type = type;

}



public Integer getCnt() {

return cnt;

}



public void setCnt(Integer cnt) {

this.cnt = cnt;

}

}

3、启动restful服务访问
http://localhost:9088/restful?tag=pv&args=3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: