基于反射实现自动化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
基于反射实现自动化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
相关文章推荐
- WWDC 2015 - 揭开AutoLayout的神秘面纱(Mysteries Of Auto Layout) Part1
- 黑马程序员--java基础日记--网络编程
- html或者jsp页面引用jar包中的js文件
- C语言:编写程序求解:有1,2,3,4,个数字,将组成互不相同且无重复数字出现的三位数打印出来
- iOS 判断详细的网络类型
- 详解C#编程中.NET的弱事件模式
- 总结
- 创建C3P0数据源
- mysql 视图
- Lisp老程序编译时有时会出现编译出错,但程序没有任何错误,解决办法
- FMX 模态窗体
- 二级指针删除单向链表
- Provide Regular Time to Focus
- css3 calc()自适应布局属性 ---浏览器版本兼容性的问题
- Don’t Skip Vacations for the Project
- Windows下的内存是如何管理
- c#注册表操作类
- 自定义有序广播并接受信息
- android手机两种方式获取IP地址
- C语言:编这样一个程序,用户输入10个整数,程序找出其中的最大值和最小值