SpringBoot微服务项目框架搭建

controller层

统一使用Map进行传参
@RequestMapping(value = “”, method = {RequestMethod.POST})
public ResultVO queryApiConfirmOrder(@RequestBody Map map);
远程调用的时候使用MapParam.put(map)put进去
定义一个流转map的工具类

public class MapParam {
   /**
    * @return java.util.Map
    * @Description: put 对象到mao ;不需要处理异常,有异常直接抛出打印
    * @Param [map]
    *
    **/
   public static Map<String, Object> put(Map<String, Object> map) {
       Map<String, Object> mapParam = new HashMap<>(GlobalCode.MAP_INIT_SIZE);
       mapParam.put(GlobalCode.MAP_PARAM, map);
       return mapParam;
   }

   /**
    * @return java.util.Map
    * @Description: get 对象到mao ;不需要处理异常,有异常直接抛出打印
    * @Param [map]
    **/
   public static <T> T get(Class<T> clazz, Map<String, Object> map) {
       return JSON.parseObject(JSON.toJSONString(map.get(GlobalCode.MAP_PARAM)), clazz);
   }
}

## Service层
  public ResultVO queryApiConfirmOrder(Map<String, Object> map) throws Exception {
       Map ApiMap = MapParam.get(Map.class, map);  get获取

## 返回的实体类
public class ResultVO extends HashMap<String, Object> {
   public ResultVO() {
       put("code",GlobalCode.SYS_SUCCESS);
       put("msg","执行成功");
   }
   public static ResultVO ok() {
       return new ResultVO();
   }
       public ResultVO put(String key, Object value) {
       super.put(key, value);
       return this;
   }
       public static ResultVO sysError(String code, String msg) {
       ResultVO r = new ResultVO();
       r.put("code", code);
       r.put("msg", msg);
       return r;
   }
}

你可能感兴趣的:(微服务,微服务架构,spring,boot)