只为自己备忘,没上下文,你肯定看不懂啦! AdapterBase: import net.kentop.bscore.resource.ICallRes; /** * * @author Administrator */ public class AdapterBase implements ICallRes { private String info; public AdapterBase(String info) { this.info = info; } public String info() { return this.info; } public Object call(Object params) { throw new UnsupportedOperationException("Not supported yet."); } } Adapter: import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import kentop.net.lib.gtums.beans.SysOperateType; import kentop.net.lib.gtums.dao.OperateTypeDAO; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONException; /** * * @author Administrator */ public class OperateTypeAdapter extends AdapterBase { private OperateTypeDAO dao = new OperateTypeDAO(); public OperateTypeAdapter() { super("OperateType表操作的外部接口!"); } @Override public Object call(Object params) { Object object = null; try { JSONParamData jsonData = new JSONParamData(params); String taskCode = jsonData.getTaskCode(); String actionType = jsonData.getActionType(); JSONObject uilogicParamObj = jsonData.getUilogicParamObj(); try { object = handle(actionType, uilogicParamObj); } catch (SQLException ex) { ex.printStackTrace(); } } catch (JSONException ex) { ex.printStackTrace(); } return object; } /** * 根据动作代码和参数列表,执行相应请求操作 * @param actionType 动作代码 * @param jsonObject UILogic_Param参数列表 * @return Object 操作成功影响的条数,数据集则返回数据列表 * @throws JSONException 执行SQL语句可能出现的异常 * @throws SQLException JSON数据操作异常 */ private Object handle(String actionType, JSONObject jsonObject) throws JSONException, SQLException { Object rtnObject = null; String operateCode = jsonObject.getString("OperateCode"); String name = jsonObject.getString("Name"); String remark = jsonObject.getString("Remark"); SysOperateType type = new SysOperateType(); type.setOperateCode(operateCode); type.setName(name); type.setRemark(remark); if (actionType.equals("btAdd")) { rtnObject = addHandle(type); } if (actionType.equals("btDelete")) { rtnObject = deleteHandle(operateCode); } if (actionType.equals("btEdit")) { rtnObject = editHandle(type); } if (actionType.equals("btGetOne")) { rtnObject = queryHandle(operateCode); } if (actionType.equals("btGetList")) { rtnObject = queryAll(); } return rtnObject; } /** * 添加一条动作代码记录 * @param type 一条动作代码记录 * @return int 操作成功影响的条数 * @throws JSONException 执行SQL语句可能出现的异常 */ private int addHandle(SysOperateType type) throws SQLException { try { dao.AddOperateType(type); return 1; } catch (SQLException e) { return 0; } } /** * 删除一条动作代码记录 * @param type 一条动作代码记录 * @return int 操作成功影响的条数 * @throws JSONException 执行SQL语句可能出现的异常 */ private int deleteHandle(String operateCode) throws SQLException { try { dao.DeleteOperateType(operateCode); return 1; } catch (SQLException e) { return 0; } } /** * 修改一条动作代码记录 * @param type 一条动作代码记录 * @return int 操作成功影响的条数 * @throws JSONException 执行SQL语句可能出现的异常 */ private int editHandle(SysOperateType type) throws SQLException { try { dao.UpdateOperateType(type); return 1; } catch (SQLException e) { return 0; } } /** * 获得一条动作代码记录 * @param operateCode 动作代码 * @return String JSON数据形式返回此条记录 * @throws JSONException 执行SQL语句可能出现的异常 * @throws SQLException JSON数据操作异常 */ private String queryHandle(String operateCode) throws SQLException, JSONException { SysOperateType type = dao.GetOperateTypeByCode(operateCode); JSONObject jsonObject = new JSONObject(); jsonObject.put("OperateCode", type.getOperateCode()); jsonObject.put("Name", type.getName()); jsonObject.put("Remark", type.getRemark()); return jsonObject.toString(); } /** * 获得全部动作代码记录 * @return String JSON数据形式返回所有记录 * @throws JSONException 执行SQL语句可能出现的异常 * @throws SQLException JSON数据操作异常 */ private String queryAll() throws SQLException, JSONException { JSONObject jsonObject = new JSONObject(); JSONArray array = new JSONArray(); try { List list = new ArrayList(); list = dao.GetOperateType(); for (int i = 0; i < list.size(); i++) { SysOperateType type = (SysOperateType) list.get(i); Map<String, String> mapType = new HashMap<String, String>(); mapType.put("OperateType", type.getOperateCode()); mapType.put("Name", type.getName()); mapType.put("Remark", type.getRemark()); array.put(mapType); } jsonObject.put("list", array); return jsonObject.toString(); } catch (SQLException sql) { return ""; } catch (JSONException json) { return ""; } } } 测试代码: import net.kentop.bscore.resource.ICallRes; import net.kentop.bscore.resource.IResource; import net.kentop.bscore.resource.impl.ResourceException; import net.kentop.bscore.resource.impl.ResourceImpl; /** * * @author Administrator */ public class Test { public static void main(String args[]) throws ResourceException{ IResource resource = new ResourceImpl(); ICallRes adapter = new OperateTypeAdapter(); resource.reg("adapter", adapter); ICallRes res = resource.get("adapter"); String json = "{/"Task_Data/":{/"task_code/":/"sys_operate_type/",/"action_type/":/"btGetList/"},/"UILogic_Param/":{/"OperateCode/":/"test1/",/"Name/":/"test1/",/"Remark/":/"addRemark1/"}}"; Object object = res.call(json); System.out.println(object.toString()); } }