zoukankan      html  css  js  c++  java
  • 基于反射实现自己主动化restful开发

    [Author]: kwu 

    基于反射实现自己主动化restful开发,通用的仅仅须要写查询数据库的sql。并增加相应的javabean实现的高速restful服务的开发。


    1、编写数据库的查询sql。相应sql.properties

    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类

    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

    <img src="http://img.blog.csdn.net/20150709152633218?

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />



    附反射DAO实现:

    <略....>


  • 相关阅读:
    C++中typename关键字的用法
    多项式系数的值
    记录几个经典的字符串hash算法
    linux timerfd系列函数总结
    linux 获取网络状态信息(Rtnetlink)
    linux netlink通信机制
    linux进程、线程与cpu的亲和性(affinity)
    C语言检查ip是否合法
    使用libpcap获取http报文
    使用libpcap过滤arp
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5346352.html
Copyright © 2011-2022 走看看