后端传给前端 无限极分类_Web开发基础-10-Springboot + Mybatis 后端

本文介绍了如何使用Springboot + Mybatis在后端实现无限极分类,详细讲解了项目目录结构,包括controller、bl、blImpl、data、dataImpl等层的作用。并阐述了后端调用流程,依赖注入(DI)的概念,以及ORM和Mybatis的区别,强调MyBatis作为数据映射框架,更注重SQL的灵活性。
摘要由CSDN通过智能技术生成

Springboot + Mybatis 后端

项目目录

abf62ab2b4b88ff13f61af3153358cb5.png

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

前端输入的参数&#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值