|
| 1 | +package apijson.demo.server; |
| 2 | + |
| 3 | +import static zuo.biao.apijson.RequestMethod.GET; |
| 4 | + |
| 5 | +import com.jfinal.kit.HttpKit; |
| 6 | + |
| 7 | +import apijson.demo.server.model.Privacy; |
| 8 | +import apijson.demo.server.model.User; |
| 9 | +import apijson.demo.server.model.Verify; |
| 10 | +import zuo.biao.apijson.JSONResponse; |
| 11 | +import zuo.biao.apijson.RequestMethod; |
| 12 | +import zuo.biao.apijson.server.JSONRequest; |
| 13 | + |
| 14 | +public class Controller extends com.jfinal.core.Controller { |
| 15 | + |
| 16 | + //通用接口,非事务型操作 和 简单事务型操作 都可通过这些接口自动化实现<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 17 | + |
| 18 | + |
| 19 | + /**获取 |
| 20 | + * @param request 只用String,避免encode后未decode |
| 21 | + * @param session |
| 22 | + * @return |
| 23 | + * @see {@link RequestMethod#GET} |
| 24 | + */ |
| 25 | + public void get() { |
| 26 | + renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest()))); |
| 27 | + } |
| 28 | + |
| 29 | + /**计数 |
| 30 | + * @param request 只用String,避免encode后未decode |
| 31 | + * @param session |
| 32 | + * @return |
| 33 | + * @see {@link RequestMethod#HEAD} |
| 34 | + */ |
| 35 | + public void head() { |
| 36 | + renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest()))); |
| 37 | + } |
| 38 | + |
| 39 | + /**限制性GET,request和response都非明文,浏览器看不到,用于对安全性要求高的GET请求 |
| 40 | + * @param request 只用String,避免encode后未decode |
| 41 | + * @param session |
| 42 | + * @return |
| 43 | + * @see {@link RequestMethod#GETS} |
| 44 | + */ |
| 45 | + public void gets() { |
| 46 | + renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest()))); |
| 47 | + } |
| 48 | + |
| 49 | + /**限制性HEAD,request和response都非明文,浏览器看不到,用于对安全性要求高的HEAD请求 |
| 50 | + * @param request 只用String,避免encode后未decode |
| 51 | + * @param session |
| 52 | + * @return |
| 53 | + * @see {@link RequestMethod#HEADS} |
| 54 | + */ |
| 55 | + public void heads() { |
| 56 | + renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest()))); |
| 57 | + } |
| 58 | + |
| 59 | + /**新增 |
| 60 | + * @param request 只用String,避免encode后未decode |
| 61 | + * @param session |
| 62 | + * @return |
| 63 | + * @see {@link RequestMethod#POST} |
| 64 | + */ |
| 65 | + public void post() { |
| 66 | + renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest()))); |
| 67 | + } |
| 68 | + |
| 69 | + /**修改 |
| 70 | + * @param request 只用String,避免encode后未decode |
| 71 | + * @param session |
| 72 | + * @return |
| 73 | + * @see {@link RequestMethod#PUT} |
| 74 | + */ |
| 75 | + public void put() { |
| 76 | + renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest()))); |
| 77 | + } |
| 78 | + |
| 79 | + /**删除 |
| 80 | + * @param request 只用String,避免encode后未decode |
| 81 | + * @param session |
| 82 | + * @return |
| 83 | + * @see {@link RequestMethod#DELETE} |
| 84 | + */ |
| 85 | + public void delete() { |
| 86 | + renderJson(new DemoParser(GET).setSession(getSession()).parse(HttpKit.readData(getRequest()))); |
| 87 | + } |
| 88 | + |
| 89 | + |
| 90 | + //通用接口,非事务型操作 和 简单事务型操作 都可通过这些接口自动化实现>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + public static final String USER_; |
| 95 | + public static final String PRIVACY_; |
| 96 | + public static final String VERIFY_; //加下划线后缀是为了避免 Verify 和 verify 都叫VERIFY,分不清 |
| 97 | + static { |
| 98 | + USER_ = User.class.getSimpleName(); |
| 99 | + PRIVACY_ = Privacy.class.getSimpleName(); |
| 100 | + VERIFY_ = Verify.class.getSimpleName(); |
| 101 | + } |
| 102 | + |
| 103 | + public static final String VERSION = JSONRequest.KEY_VERSION; |
| 104 | + public static final String FORMAT = JSONRequest.KEY_FORMAT; |
| 105 | + public static final String COUNT = JSONResponse.KEY_COUNT; |
| 106 | + public static final String TOTAL = JSONResponse.KEY_TOTAL; |
| 107 | + |
| 108 | + public static final String ID = "id"; |
| 109 | + public static final String USER_ID = "userId"; |
| 110 | + public static final String CURRENT_USER_ID = "currentUserId"; |
| 111 | + |
| 112 | + public static final String NAME = "name"; |
| 113 | + public static final String PHONE = "phone"; |
| 114 | + public static final String PASSWORD = "password"; |
| 115 | + public static final String _PASSWORD = "_password"; |
| 116 | + public static final String _PAY_PASSWORD = "_payPassword"; |
| 117 | + public static final String OLD_PASSWORD = "oldPassword"; |
| 118 | + public static final String VERIFY = "verify"; |
| 119 | + |
| 120 | + public static final String TYPE = "type"; |
| 121 | + |
| 122 | +} |
0 commit comments