Springboot + Mybatis 后端
项目目录
controller:负责处理REST API请求
bl:业务逻辑层接口
blImpl:业务逻辑层实现
data:数据层接口
po:持久化对象,用于数据层和逻辑层之间数据传递
vo:值对象,用于逻辑层和展示层(前端)数据传递
dataImpl:数据层实现,Mybatis是XML文件
后端调用流程:
controller->bl->blImpl->data->dataImpl
controller
controller.coupon.CouponController
@RestController REST风格API的控制器 @RequestMapping("/api/coupon") 请求的URL
@PostMapping("/hotelTargetMoney") Post请求子路径
@RequestParam 请求参数
couponVO 传给前端的数据
package com.example.hotel.controller.coupon;
import com.example.hotel.bl.coupon.CouponService;
import com.example.hotel.vo.CouponVO;
import com.example.hotel.vo.HotelTargetMoneyCouponVO;
import com.example.hotel.vo.OrderVO;
import com.example.hotel.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/coupon")
public class CouponController {
@Autowired
private CouponService couponService;
@PostMapping("/hotelTargetMoney")
public ResponseVO addHotelTargetMoneyCoupon(@RequestBody HotelTargetMoneyCouponVO hotelTargetMoneyCouponVO) {
CouponVO couponVO = couponService.addHotelTargetMoneyCoupon(hotelTargetMoneyCouponVO);
return ResponseVO.buildSuccess(couponVO);
}
@GetMapping("/hotelAllCoupons")
public ResponseVO getHotelAllCoupons(@RequestParam Integer hotelId) {
return ResponseVO.buildSuccess(couponService.getHotelAllCoupon(hotelId));
}
@GetMapping("/orderMatchCoupons")
public ResponseVO getOrderMatchCoupons(@RequestParam Integer userId,
@RequestParam Integer hotelId,
@RequestParam Double orderPrice,
@RequestParam Integer roomNum,
@RequestParam String checkIn,
@RequestParam String checkOut) {
OrderVO requestOrderVO = new OrderVO();
requestOrderVO.setUserId(userId);
requestOrderVO.setHotelId(hotelId);
requestOrderVO.setPrice(orderPrice);
requestOrderVO.setRoomNum(roomNum);
requestOrderVO.setCheckInDate(checkIn);
requestOrderVO.setCheckOutDate(checkOut);
return ResponseVO.buildSuccess(couponService.getMatchOrderCoupon(requestOrderVO));
}
}
bl
Bl.coupon.CouponService
前端输入的参数&#