| | 139 | == 2.4、接口开发说明 == |
| | 140 | * 每一个接口开头处需要使用如下方法对接口进行初始化设置 |
| | 141 | {{{ |
| | 142 | #!java |
| | 143 | WebUtils.initAppResponse( response, 0 ); |
| | 144 | }}} |
| | 145 | |
| | 146 | * 之后必须使用如下方法初始化结果模板: |
| | 147 | {{{ |
| | 148 | #!java |
| | 149 | ResultHandler<JSONObject> result = ResultHandler.extract(request, false); |
| | 150 | }}} |
| | 151 | |
| | 152 | * pageNo, pageSize, limit, commonSessionId这几个固定的参数需要直接从result中获取,无需在从request中拿去 |
| | 153 | {{{ |
| | 154 | #!java |
| | 155 | int pageNo = result.getPageNo(); |
| | 156 | int pageSize = result.getPageSize(); |
| | 157 | int limit = result.getLimit(); |
| | 158 | String commonSessionid = result.getCommonSessionId(); |
| | 159 | }}} |
| | 160 | |
| | 161 | * 对于需要登录的接口,直接放到 /intf/app/my/文件夹里面,在接口里面直接从request里面可以获取到用户登录信息: |
| | 162 | {{{ |
| | 163 | #!java |
| | 164 | Account account = (Account)request.getAttribute("account"); |
| | 165 | }}} |
| | 166 | |
| | 167 | * 每一个接口必须使用try catch 捕获异常,防止服务器抛出RunTimeException导致接口出错 |
| | 168 | |
| | 169 | * 在接口中存在集群并发访问同步问题,可以使用 cn.pconline.best.util.sync.McSyncUtils,参考如下接口: |
| | 170 | [http://trac.pc.com.cn/pc_best/wiki/app2.0/13_collect#收藏1 /app/my/collect/collectForApp.do // 收藏接口][[BR]] |
| | 171 | |
| | 172 | * 对于需要限制为post提交的,直接用下面语句判断即可,无需再额外编写代码: |
| | 173 | {{{ |
| | 174 | #!java |
| | 175 | if(!result.limitPost()){ |
| | 176 | out.print(result.toStringResult()); |
| | 177 | return; |
| | 178 | } |
| | 179 | }}} |