课程名称:多端全栈项目实战:商业级代驾全流程落地
课程章节: 华夏代驾全栈小程序实战
课程讲师: 神思者
课程内容:
预览订单
乘客选择代价车型和车牌
课程收获:
1.添加车辆
2.查询用户车辆
3.删除车辆记录
首先需要编写sql 在 tb_customer_car 进行instart
需要插入得内容有 自增得id 司机id 车牌号 车辆类型
INSERT INTO tb_customer_car SET customer_id = #{customerId}, car_plate = #{carPlate}, car_type = #{carType}
查询车辆列表
通过司机id对车辆表进行查询 这个司机有几辆车
SELECT CAST(id AS CHAR) AS id, car_plate AS carPlate, car_type AS carType FROM tb_customer_car WHERE customer_id = #{customerId}
再就是删除车辆信息
通过 id 对车辆信息 进行删除
DELETE FROM tb_customer_car WHERE id = #{id}
接下来是编写form类
需要对传入得数据做验证
Data@Schema(description = "添加客户车辆的表单")public class InsertCustomerCarForm { @NotNull(message = "customerId不能为空") @Min(value = 1, message = "customerId不能小于1") @Schema(description = "客户ID") private Long customerId; @NotBlank(message = "carPlate不能为空") @Pattern(regexp = "^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1})$", message = "carPlate内容不正确") @Schema(description = "车牌号") private String carPlate; @NotBlank(message = "carType不能为空") @Pattern(regexp = "^[\\u4e00-\\u9fa5A-Za-z0-9\\-\\_\\s]{2,20}$", message = "carType内容不正确") @Schema(description = "车型") private String carType;}
@Data@Schema(description = "查询客户车辆的表单")public class SearchCustomerCarListForm { @NotNull(message = "customerId不能为空") @Min(value = 1, message = "customerId不能小于1") @Schema(description = "客户ID") private Long customerId;}
@Data@Schema(description = "删除客户车辆的表单")public class DeleteCustomerCarByIdForm { @NotNull(message = "id不能为空") @Min(value = 1, message = "id不能小于1") @Schema(description = "车辆ID") private Long id;}
之后就是编写controller了
不难 就是接收数据后 调用分别得service
代码如下
@PostMapping("/insertCustomerCar") @Operation(summary = "添加客户车辆") public R insertCustomerCar(@RequestBody @Valid InsertCustomerCarForm form) { CustomerCarEntity entity = BeanUtil.toBean(form, CustomerCarEntity.class); customerCarService.insertCustomerCar(entity); return R.ok(); } @PostMapping("/searchCustomerCarList") @Operation(summary = "查询客户车辆列表") public R searchCustomerCarList(@RequestBody @Valid SearchCustomerCarListForm form) { ArrayList<HashMap> list = customerCarService.searchCustomerCarList(form.getCustomerId()); return R.ok().put("result", list); } @PostMapping("/deleteCustomerCarById") @Operation(summary = "删除客户车辆") public R deleteCustomerCarById(@RequestBody @Valid DeleteCustomerCarByIdForm form) { int rows = customerCarService.deleteCustomerCarById(form.getId()); return R.ok().put("rows", rows); }
之后需要开始编写fegin
同样的 要在项目中把刚才上面得form 再次编写一遍
之后就是对刚才编写得controller的调用
@PostMapping("/customer/car/insertCustomerCar") public R insertCustomerCar(InsertCustomerCarForm form); @PostMapping("/customer/car/searchCustomerCarList") public R searchCustomerCarList(SearchCustomerCarListForm form); @PostMapping("/customer/car/deleteCustomerCarById") public R deleteCustomerCarById(DeleteCustomerCarByIdForm form);
在controller中进行编写
@Resource private CustomerCarService customerCarService; @PostMapping("/insertCustomerCar") @Operation(summary = "添加客户车辆") public R insertCustomerCar(@RequestBody @Valid InsertCustomerCarForm form) { long customerId = StpUtil.getLoginIdAsLong(); form.setCustomerId(customerId); customerCarService.insertCustomerCar(form); return R.ok(); } @PostMapping("/searchCustomerCarList") @Operation(summary = "查询客户车辆列表") public R searchCustomerCarList(@RequestBody @Valid SearchCustomerCarListForm form) { long customerId = StpUtil.getLoginIdAsLong(); form.setCustomerId(customerId); ArrayList<HashMap> list = customerCarService.searchCustomerCarList(form); return R.ok().put("result", list); } @PostMapping("/deleteCustomerCarById") @Operation(summary = "删除客户车辆") public R deleteCustomerCarById(@RequestBody @Valid DeleteCustomerCarByIdForm form) { int rows = customerCarService.deleteCustomerCarById(form); return R.ok().put("rows", rows); }
对数据进行处理 然后返回
这样就完成了 添加车辆 查询车辆列表 删除客户车辆得 后端代码
明天接着分享 前端代码