一个Spring boot的完整请求流程

1,由前端发起请求

uni.request({
				url: this.domainUrl+"/zyymall/queryorderlist/"+this.cmsSiteId+"/"+this.VolId+"/"+this.orderStatus,
				method: 'GET',
				data:{
					"VolId":this.VolId,
					"orderStatus":this.orderStatus,
				},
				header: {
					"Content-Type": this.contenttype,
					"volauth":this.volauth
				},
				success: (res) => {
					console.log(res);
					if (res.statusCode == 200) {
						this.orderList=res.data.orders;
						console.log(this.orderList);
						uni.hideLoading();
					}
					
				}
			});	

2,根据路径,Springboot会加载相应的Controller进行拦截

	@GetMapping("/queryorderlist/{cmsSiteId}/{volId}/{orderStatus}")
	public ResponseEntity queryOrderList(@PathVariable Integer cmsSiteId,@PathVariable Integer volId,@PathVariable Integer orderStatus,
			@RequestParam Map params){
		MapcmsSite = CmsSiteCheckUtil.querySiteInfo(cmsSiteId);
		if (cmsSite.get("status") != null) {
			return ResponseEntity.ok(cmsSite);
		}
		params.put("volId", volId);
		params.put("orderStatus", orderStatus);
		return ResponseEntity.ok(mallOrderService.queryOrderList(params));
	}

3,拦截处理后,跳转到相应的Service处理层

public interface MallOrderService {
/**
	 * 查询订单列表
	 * @param volId 志愿者ID,orderStatus 订单状态
	 * @return 返回成功或失败
	 */
	Map queryOrderList(Map params);
}

4,跳转到ServiceImplement(service实现类)

@Service
public class MallOrderServiceImpl implements MallOrderService {
@Autowired
	private MallOrderDao mallOrderDao;`
	@Override
	public Map queryOrderList(Map params) {
		Map resultMap = Maps.newConcurrentMap();
		//根据用户ID查询用户订单
		List orderList = mallOrderDao.queryOrderListByUid(params);
		if (orderList==null || orderList.isEmpty()) {
			resultMap.put("status", ResponseConstants.HTTP_RESPONSE_MALL_ORDER_NULL_FAIL);
			resultMap.put("msg", ResponseConstants.HTTP_RESPONSE_MALL_ORDER_NULL_FAIL_DESC);
			return resultMap;
		}else {
			try {
				for (MallOrder mallOrder : orderList) {
					List goodsList = mallOrderDao.queryGoodsListByOrderId(mallOrder.getOrderId());
					mallOrder.setMallOrderGoods(goodsList);
				}
				resultMap.put("orders",orderList);
			} catch (Exception e) {
				e.printStackTrace();
				resultMap.put("status", ResponseConstants.HTTP_RESPONSE_FAIL_REGEDIT);
				resultMap.put("msg", ResponseConstants.HTTP_RESPONSE_FAIL_REGEDIT_DESC);
				return resultMap;
			}
			resultMap.put("status", ResponseConstants.HTTP_RESPONSE_SUCCESS);
			resultMap.put("msg",ResponseConstants.HTTP_RESPONSE_SUCCESS_DESC);
			return resultMap;
		}
	}
}

5,在执行serviceimplement时会加载Dao层,操作数据库

public interface MallOrderDao {
	//根据志愿者ID查询订单
	List queryOrderListByUid(Map params);
}

6,再跳到Dao层实现类

@Repository
public class MallOrderDaoImpl implements MallOrderDao {
@Override
	public List queryOrderListByUid(Map params) {
		return mallOrderMapper.queryOrderListByUid(params);
	}
}

7,执行会跳转到mapper层

public interface MallOrderMapper {
	List queryOrderListByUid(Map params);
}

8,然后MallMapper会继续找对应的mapper.xml配置文件




  
  	
    
    
    
  
    

之后便会跳转到第4步继续执行,执行完毕后会将结果返回到第1步,然后

ResponseEntity.ok(mallOrderService.queryOrderList(params));

便会将数据以JSON的形式返回到页面,同时返回状态码,正常则会返回200,便会回到步骤1中查询判断。

success: (res) => {
					console.log(res);
					if (res.statusCode == 200) {
						this.orderList=res.data.orders;
						console.log(this.orderList);
						uni.hideLoading();
					}
					
				}

如果判断正常。前端根据数据遍历显示

	
		
			
				
					订单详情
					已拒收
					待付款
					待发货
					配送中
					已收货
				
				
					
						{{goodsItem.orgName}}
						
					
					
					
						¥{{goodsItem.goodsPrice}}
						×{{goodsItem.goodsNum}}
					
					{{goodsItem.goodsTitle}}
				
				合计
					¥{{item.goodsMoney}}
				
			
		

这就是我理解的一个请求的完整流程

你可能感兴趣的:(SpringBoot)