中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

網(wǎng)站編輯工具軟文廣告投放平臺

網(wǎng)站編輯工具,軟文廣告投放平臺,政府網(wǎng)站建設(shè)需要進行采購,網(wǎng)站加速優(yōu)化前言:公共字段自動填充實現(xiàn),刪除業(yè)務邏輯實現(xiàn) 一、公共字段自動填充 1.1 問題分析 1.2 代碼實現(xiàn) 1.2.1 修改實體類Employee package com.runa.reggie.entity;import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.…

前言:公共字段自動填充實現(xiàn),刪除業(yè)務邏輯實現(xiàn)

一、公共字段自動填充

1.1 問題分析

1.2 代碼實現(xiàn)

?1.2.1 修改實體類Employee

package com.runa.reggie.entity;import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;@Data
public class Employee implements Serializable {private static final long serialVersionUID = 1L;private Long id;private String username;private String name;private String password;private String phone;private String sex;private String idNumber;private Integer status;@TableField(fill = FieldFill.INSERT)  //插入時更新字段private LocalDateTime createTime;@TableField(fill = FieldFill.INSERT_UPDATE)  //插入和更新時更新字段private LocalDateTime updateTime;@TableField(fill = FieldFill.INSERT)private Long createUser;@TableField(fill = FieldFill.INSERT_UPDATE)private Long updateUser;}

?1.2.2?MyMetaObjectHandler

package com.runa.reggie.common;import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;import java.time.LocalDateTime;@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {/*** 插入操作,自動填充* @param metaObject*/@Overridepublic void insertFill(MetaObject metaObject) {log.info("公共字段自動填充[insert]...");log.info(metaObject.toString());metaObject.setValue("createTime", LocalDateTime.now());metaObject.setValue("updateTime", LocalDateTime.now());metaObject.setValue("createUser", new Long(1) );metaObject.setValue("updateUser", new Long(1));}/*** 更新操作,自動填充* @param metaObject*/@Overridepublic void updateFill(MetaObject metaObject) {log.info("公共字段自動填充[update]...");log.info(metaObject.toString());metaObject.setValue("updateTime", LocalDateTime.now());metaObject.setValue("updateUser", new Long(1));}
}

?1.2.3?EmployeeController將新增、修改方法當中的公共字段賦值注釋掉?

package com.runa.reggie.controller;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.runa.reggie.common.R;
import com.runa.reggie.entity.Employee;
import com.runa.reggie.service.impl.EmployeeServcie;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {@Autowiredprivate EmployeeServcie employeeServcie;/*** 員工登錄* @param request* @param employee* @return*///HttpServletRequest request  是為了將登錄對象塞入session@PostMapping("/login")public R<Employee> login(HttpServletRequest request, @RequestBody Employee employee){//1、將頁面提交的密碼password進行md5加密處理String password = employee.getPassword();password = DigestUtils.md5DigestAsHex(password.getBytes());//2、根據(jù)頁面提交的用戶名username查詢數(shù)據(jù)庫LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<>();queryWrapper.eq(Employee::getUsername,employee.getUsername());Employee emp = employeeServcie.getOne(queryWrapper);//3、如果沒有查詢到則返回登錄失敗結(jié)果if(emp == null){return R.error("登錄失敗");}//4、密碼比對,如果不一致則返回登錄失敗結(jié)果if(!emp.getPassword().equals(password)){return R.error("登錄失敗");}//5、查看員工狀態(tài),如果為已禁用狀態(tài),則返回員工已禁用結(jié)果if(emp.getStatus() == 0){return R.error("賬號已禁用");}//6、登錄成功,將員工id存入Session并返回登錄成功結(jié)果request.getSession().setAttribute("employee",emp.getId());return R.success(emp);}@PostMapping("/logout")public R<String> logout(HttpServletRequest request){// 清理Session 中保存的當前員工的idrequest.getSession().removeAttribute("emplyee");return R.success("退出成功!");}@PostMappingpublic R<String> save(HttpServletRequest request, @RequestBody Employee employee){log.info("新增員工,員工信息為:{}",employee.toString());// 設(shè)置初始密碼123456,需要進行md5加密處理employee.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));//        employee.setCreateTime(LocalDateTime.now());
//        employee.setUpdateTime(LocalDateTime.now());
//        //獲得當前用戶的id
//        Long empId = (Long) request.getSession().getAttribute("employee");
//        employee.setCreateUser(empId);
//        employee.setUpdateUser(empId);employeeServcie.save(employee);return R.success("新增員工成功");}/*** 員工信息分頁查詢* @param page* @param pageSize* @param name* @return*/@GetMapping("/page")public R<Page> page(int page, int pageSize,String name){log.info("page= {}, pageSize= {}, name = {}",page, pageSize, name);// 構(gòu)造分頁構(gòu)造器Page pageInfo = new Page(page, pageSize);//構(gòu)造條件構(gòu)造器LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper();// 添加過濾條件//當傳入的name不為空的時候才會添加條件queryWrapper.like(StringUtils.isNotEmpty(name),Employee::getName,name);// 添加排序條件queryWrapper.orderByDesc(Employee::getUpdateTime);//執(zhí)行查詢employeeServcie.page(pageInfo, queryWrapper);return R.success(pageInfo);}/*** 根據(jù)ID修改員工信息* @param employee* @return*/@PutMappingpublic R<String> update(HttpServletRequest request, @RequestBody Employee employee){log.info(employee.toString());//        Long empId = (Long) request.getSession().getAttribute("employee");
//        employee.setUpdateUser(empId);
//        employee.setUpdateTime(LocalDateTime.now());employeeServcie.updateById(employee);return R.success("員工信息修改成功");}@GetMapping("/{id}")public R<Employee> GetById(@PathVariable Long id){log.info("根據(jù)id查詢員工:{}",id);Employee employee = employeeServcie.getById(id);if(employee != null){return R.success(employee);}return R.error("沒有查詢到對應員工信息");}}

1.3 功能測試

1.4 功能完善

?

?

?1.4.1?BaseContext?

package com.runa.reggie.common;public class BaseContext {private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();public static void setCurrentId(Long id){threadLocal.set(id);}public static Long getCurrent(){return threadLocal.get();}
}

1.4.2?LoginCheckFilter優(yōu)化將用戶id塞進線程

package com.runa.reggie.filter;import com.alibaba.fastjson.JSON;
import com.runa.reggie.common.BaseContext;
import com.runa.reggie.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.AntPathMatcher;import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;@Slf4j
@WebFilter(filterName = "loginCheckFilter", urlPatterns = "/*")
public class LoginCheckFilter implements Filter {// 路徑匹配器public static final AntPathMatcher PATH_MATCHER = new AntPathMatcher();@Overridepublic void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {HttpServletRequest request = (HttpServletRequest) servletRequest;HttpServletResponse response = (HttpServletResponse) servletResponse;// 1  獲取本次請求的URI//        request.getRequestURL()返回的是全路徑。//        request.getRequestURI()返回的是除去協(xié)議,域名(IP+端口號)之后的路由部分。String requestURI = request.getRequestURI();log.info("攔截到請求:【{}】",requestURI);// 定義一些不需要處理的路徑String[] urls = new String[]{"/employee/login",    // 登錄不需要"/employee/logout","/backend/**","/front/**"};// 2  判斷本次請求是否需要處理boolean check = check(urls, requestURI);// 3 如果不需要處理,則直接放行if(check){log.info("本次請求【 {} 】 不需要處理",requestURI);filterChain.doFilter(request,response);return;}// 4 判斷登錄狀態(tài),如果已登錄,則直接放行if(request.getSession().getAttribute("employee") != null){log.info("用戶已登錄,請求url為:【{}】, 用戶id為:【 {} 】 ",requestURI,request.getSession().getAttribute("employee"));// 獲取ID 塞進線程Long empId = (Long) request.getSession().getAttribute("employee");BaseContext.setCurrentId(empId);filterChain.doFilter(request,response);return;}log.info("用戶未登錄");// 5 如果未登錄則返回未登錄結(jié)果,通過輸出流方式向客戶端頁面響應數(shù)據(jù)response.getWriter().write(JSON.toJSONString(R.error("NOTLOGIN")));return;}/*** 路徑匹配,檢查本次請求是否需要放行* @param urls* @param requestURI* @return*/public boolean check(String[] urls, String requestURI){for (String url : urls) {boolean match = PATH_MATCHER.match(url, requestURI);if(match){return true;}}// 循環(huán)都匹配不上就返回falsereturn false;}
}

1.4.3?MyMetaObjectHandler?

package com.runa.reggie.common;import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;import java.time.LocalDateTime;@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {/*** 插入操作,自動填充* @param metaObject*/@Overridepublic void insertFill(MetaObject metaObject) {log.info("公共字段自動填充[insert]...");log.info(metaObject.toString());metaObject.setValue("createTime", LocalDateTime.now());metaObject.setValue("updateTime", LocalDateTime.now());metaObject.setValue("createUser", BaseContext.getCurrent());metaObject.setValue("updateUser",  BaseContext.getCurrent());}/*** 更新操作,自動填充* @param metaObject*/@Overridepublic void updateFill(MetaObject metaObject) {log.info("公共字段自動填充[update]...");log.info(metaObject.toString());metaObject.setValue("updateTime", LocalDateTime.now());metaObject.setValue("updateUser",  BaseContext.getCurrent());}
}

二、新增分類

2.1 需求分析

2.2 數(shù)據(jù)模型

2.3 代碼實現(xiàn)

?

?

?2.3.1 實體類Category

package com.runa.reggie.entity;import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.time.LocalDateTime;/*** 分類*/
@Data
public class Category implements Serializable {private static final long serialVersionUID = 1L;private Long id;//類型 1 菜品分類 2 套餐分類private Integer type;//分類名稱private String name;//順序private Integer sort;//創(chuàng)建時間@TableField(fill = FieldFill.INSERT)private LocalDateTime createTime;//更新時間@TableField(fill = FieldFill.INSERT_UPDATE)private LocalDateTime updateTime;//創(chuàng)建人@TableField(fill = FieldFill.INSERT)private Long createUser;//修改人@TableField(fill = FieldFill.INSERT_UPDATE)private Long updateUser;//是否刪除private Integer isDeleted;}

2.3.2?CategoryMapper

package com.runa.reggie.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.runa.reggie.entity.Category;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface CategoryMapper  extends BaseMapper<Category> {
}

2.3.3?CategoryService

package com.runa.reggie.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.runa.reggie.entity.Category;public interface CategoryService extends IService<Category> {
}

2.3.4?CategoryServiceImpl

package com.runa.reggie.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.runa.reggie.entity.Category;
import com.runa.reggie.mapper.CategoryMapper;
import com.runa.reggie.service.CategoryService;
import org.springframework.stereotype.Service;@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
}

2.3.5?CategoryController

package com.runa.reggie.controller;import com.runa.reggie.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** 分類管理*/
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {@Autowiredprivate CategoryService categoryService;
}

?

?2.3.6 CategoryController新增save方法

?
package com.runa.reggie.controller;import com.runa.reggie.common.R;
import com.runa.reggie.entity.Category;
import com.runa.reggie.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** 分類管理*/
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {@Autowiredprivate CategoryService categoryService;/*** 新增分類* @param category* @return*/@PostMappingpublic R<String> save(@RequestBody Category category){log.info("新增分類:{}", category);categoryService.save(category);return R.success("新增分類成功");}
}?

2.4 功能測試

?

三、分類信息分頁查詢

3.1 需求分析

?

3.2 代碼實現(xiàn)

?3.2.1 CategoryController

package com.runa.reggie.controller;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.runa.reggie.common.R;
import com.runa.reggie.entity.Category;
import com.runa.reggie.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;/*** 分類管理*/
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {@Autowiredprivate CategoryService categoryService;/*** 新增分類* @param category* @return*/@PostMappingpublic R<String> save(@RequestBody Category category){log.info("新增分類:{}", category);categoryService.save(category);return R.success("新增分類成功");}/*** 分頁查詢* @param page* @param pageSize* @return*/@GetMapping("/page")public R<Page> page(int page, int pageSize){log.info("page= {}, pageSize= {}, name = {}",page, pageSize);//分頁構(gòu)造器Page pageInfo = new Page(page, pageSize);// 條件構(gòu)造器LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();//添加排序條件,根據(jù)sort排序queryWrapper.orderByAsc(Category::getSort);//進行分頁查詢categoryService.page(pageInfo, queryWrapper);return R.success(pageInfo);}
}

3.2.1?Category注釋是否刪除字段

package com.runa.reggie.entity;import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.time.LocalDateTime;/*** 分類*/
@Data
public class Category implements Serializable {private static final long serialVersionUID = 1L;private Long id;//類型 1 菜品分類 2 套餐分類private Integer type;//分類名稱private String name;//順序private Integer sort;//創(chuàng)建時間@TableField(fill = FieldFill.INSERT)private LocalDateTime createTime;//更新時間@TableField(fill = FieldFill.INSERT_UPDATE)private LocalDateTime updateTime;//創(chuàng)建人@TableField(fill = FieldFill.INSERT)private Long createUser;//修改人@TableField(fill = FieldFill.INSERT_UPDATE)private Long updateUser;//是否刪除
//    private Integer isDeleted;}

?

3.3 功能測試

?

四、刪除分類

4.1 需求分析

?

4.2 代碼實現(xiàn)

?4.2.1? CategoryController

注意傳參是ids

package com.runa.reggie.controller;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.runa.reggie.common.R;
import com.runa.reggie.entity.Category;
import com.runa.reggie.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;/*** 分類管理*/
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {@Autowiredprivate CategoryService categoryService;/*** 新增分類* @param category* @return*/@PostMappingpublic R<String> save(@RequestBody Category category){log.info("新增分類:{}", category);categoryService.save(category);return R.success("新增分類成功");}/*** 分頁查詢* @param page* @param pageSize* @return*/@GetMapping("/page")public R<Page> page(int page, int pageSize){log.info("page= {}, pageSize= {}, name = {}",page, pageSize);//分頁構(gòu)造器Page pageInfo = new Page(page, pageSize);// 條件構(gòu)造器LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();//添加排序條件,根據(jù)sort排序queryWrapper.orderByAsc(Category::getSort);//進行分頁查詢categoryService.page(pageInfo, queryWrapper);return R.success(pageInfo);}/*** 根據(jù)id刪除分類* @param ids* @return*/@DeleteMappingpublic R<String> delete(Long ids){log.info("根據(jù)ID刪除分類:{}",ids);categoryService.removeById(ids);return R.success("分類信息刪除成功");}
}

4.3 功能測試

?

4.4 功能完善

?4.4.1 菜品實體類Dish?

package com.runa.reggie.entity;import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;/**菜品*/
@Data
public class Dish implements Serializable {private static final long serialVersionUID = 1L;private Long id;//菜品名稱private String name;//菜品分類idprivate Long categoryId;//菜品價格private BigDecimal price;//商品碼private String code;//圖片private String image;//描述信息private String description;//0 停售 1 起售private Integer status;//順序private Integer sort;@TableField(fill = FieldFill.INSERT)private LocalDateTime createTime;@TableField(fill = FieldFill.INSERT_UPDATE)private LocalDateTime updateTime;@TableField(fill = FieldFill.INSERT)private Long createUser;@TableField(fill = FieldFill.INSERT_UPDATE)private Long updateUser;//是否刪除private Integer isDeleted;}

4.4.2 套餐實體類Setmeal?

package com.runa.reggie.entity;import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;/*** 套餐*/
@Data
public class Setmeal implements Serializable {private static final long serialVersionUID = 1L;private Long id;//分類idprivate Long categoryId;//套餐名稱private String name;//套餐價格private BigDecimal price;//狀態(tài) 0:停用 1:啟用private Integer status;//編碼private String code;//描述信息private String description;//圖片private String image;@TableField(fill = FieldFill.INSERT)private LocalDateTime createTime;@TableField(fill = FieldFill.INSERT_UPDATE)private LocalDateTime updateTime;@TableField(fill = FieldFill.INSERT)private Long createUser;@TableField(fill = FieldFill.INSERT_UPDATE)private Long updateUser;//是否刪除private Integer isDeleted;
}

?4.4.3?DishMapper?

package com.runa.reggie.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.runa.reggie.entity.Dish;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface DishMapper extends BaseMapper<Dish> {
}

4.4.4?SetmealMapper?

package com.runa.reggie.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.runa.reggie.entity.Setmeal;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface SetmealMapper extends BaseMapper<Setmeal> {
}

4.4.5?DishService?

package com.runa.reggie.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.runa.reggie.entity.Dish;public interface DishService extends IService<Dish> {
}

?4.4.6?SetmealService?

package com.runa.reggie.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.runa.reggie.entity.Setmeal;public interface SetmealService extends IService<Setmeal> {
}

4.4.7?DishServiceImpl?

package com.runa.reggie.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.runa.reggie.entity.Dish;
import com.runa.reggie.mapper.DishMapper;
import com.runa.reggie.service.DishService;
import org.springframework.stereotype.Service;@Service
public class DishServiceImpl extends ServiceImpl<DishMapper, Dish> implements DishService {
}

?4.4.8?SetmealServiceImpl?

package com.runa.reggie.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.runa.reggie.entity.Setmeal;
import com.runa.reggie.mapper.SetmealMapper;
import com.runa.reggie.service.SetmealService;
import org.springframework.stereotype.Service;@Service
public class SetmealServiceImpl extends ServiceImpl<SetmealMapper, Setmeal> implements SetmealService {
}

?4.4.9 修改CategoryService

package com.runa.reggie.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.runa.reggie.entity.Category;public interface CategoryService extends IService<Category> {public void remove(Long ids);
}

4.4.10? 自定義業(yè)務異常類CustomException?

?

package com.runa.reggie.common;/*** 自定義業(yè)務異常類*/
public class CustomException extends RuntimeException {public CustomException(String message){super(message);}
}

4.4.11?CategoryServiceImpl?

package com.runa.reggie.service.impl;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.runa.reggie.common.CustomException;
import com.runa.reggie.entity.Category;
import com.runa.reggie.entity.Dish;
import com.runa.reggie.entity.Setmeal;
import com.runa.reggie.mapper.CategoryMapper;
import com.runa.reggie.service.CategoryService;
import com.runa.reggie.service.DishService;
import com.runa.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {@Autowiredprivate DishService dishService;@Autowiredprivate SetmealService setmealService;@Overridepublic void remove(Long ids) {LambdaQueryWrapper<Dish> dishLambdaQueryWrapper = new LambdaQueryWrapper<>();//添加查詢條件,根據(jù)分類id查詢dishLambdaQueryWrapper.eq(Dish::getCategoryId,ids);int count1 = dishService.count(dishLambdaQueryWrapper);// 查詢分類是否關(guān)聯(lián)了菜品,如果關(guān)聯(lián)了,拋出一個業(yè)務異常if(count1 > 0){// 關(guān)聯(lián)了 拋出異常throw new CustomException("當前分類下關(guān)聯(lián)了菜品,不能刪除");}LambdaQueryWrapper<Setmeal> setmealLambdaQueryWrapper = new LambdaQueryWrapper<>();//添加查詢條件,根據(jù)分類id查詢setmealLambdaQueryWrapper.eq(Setmeal::getCategoryId,ids);int count2 = setmealService.count(setmealLambdaQueryWrapper);// 查詢分類是否關(guān)聯(lián)了套餐,如果關(guān)聯(lián)了,拋出一個業(yè)務異常if(count2 > 0){// 關(guān)聯(lián)了 拋出異常throw new CustomException("當前分類下關(guān)聯(lián)了套餐,不能刪除");}//執(zhí)行刪除super.removeById(ids);}
}

?4.4.12?GlobaExceptionHandler?

package com.runa.reggie.common;import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;import java.sql.SQLIntegrityConstraintViolationException;/*** 全局異常處理*/
@ControllerAdvice(annotations = {RestController.class, Controller.class})   // 加了RestController Controller 注解的
@ResponseBody
@Slf4j
public class GlobaExceptionHandler {/*** 異常處理方法* @return*/@ExceptionHandler(SQLIntegrityConstraintViolationException.class)public R<String> exceptionHandler(SQLIntegrityConstraintViolationException ex){String msg = ex.getMessage();log.error(msg);if(msg.contains("Duplicate entry")){String[] split = msg.split(" "); //空分割String resultMsg = split[2] + " 已存在 ";return R.error(resultMsg);}return R.error("未知錯誤!");}/*** 異常處理方法(處理自定義的)* @return*/@ExceptionHandler(CustomException.class)public R<String> exceptionHandler(CustomException ex){String msg = ex.getMessage();log.error(msg);return R.error(msg);}}

4.4.13?CategoryController?

package com.runa.reggie.controller;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.runa.reggie.common.R;
import com.runa.reggie.entity.Category;
import com.runa.reggie.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;/*** 分類管理*/
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {@Autowiredprivate CategoryService categoryService;/*** 新增分類* @param category* @return*/@PostMappingpublic R<String> save(@RequestBody Category category){log.info("新增分類:{}", category);categoryService.save(category);return R.success("新增分類成功");}/*** 分頁查詢* @param page* @param pageSize* @return*/@GetMapping("/page")public R<Page> page(int page, int pageSize){log.info("page= {}, pageSize= {}, name = {}",page, pageSize);//分頁構(gòu)造器Page pageInfo = new Page(page, pageSize);// 條件構(gòu)造器LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();//添加排序條件,根據(jù)sort排序queryWrapper.orderByAsc(Category::getSort);//進行分頁查詢categoryService.page(pageInfo, queryWrapper);return R.success(pageInfo);}/*** 根據(jù)id刪除分類* @param ids* @return*/@DeleteMappingpublic R<String> delete(Long ids){log.info("根據(jù)ID刪除分類:{}",ids);
//        categoryService.removeById(ids);categoryService.remove(ids);return R.success("分類信息刪除成功");}
}

?

?

五、修改分類

5.1 需求分析

?

5.2 代碼實現(xiàn)

5.2.1?CategoryController

package com.runa.reggie.controller;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.runa.reggie.common.R;
import com.runa.reggie.entity.Category;
import com.runa.reggie.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;/*** 分類管理*/
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {@Autowiredprivate CategoryService categoryService;/*** 新增分類* @param category* @return*/@PostMappingpublic R<String> save(@RequestBody Category category){log.info("新增分類:{}", category);categoryService.save(category);return R.success("新增分類成功");}/*** 分頁查詢* @param page* @param pageSize* @return*/@GetMapping("/page")public R<Page> page(int page, int pageSize){log.info("page= {}, pageSize= {}, name = {}",page, pageSize);//分頁構(gòu)造器Page pageInfo = new Page(page, pageSize);// 條件構(gòu)造器LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();//添加排序條件,根據(jù)sort排序queryWrapper.orderByAsc(Category::getSort);//進行分頁查詢categoryService.page(pageInfo, queryWrapper);return R.success(pageInfo);}/*** 根據(jù)id刪除分類* @param ids* @return*/@DeleteMappingpublic R<String> delete(Long ids){log.info("根據(jù)ID刪除分類:{}",ids);
//        categoryService.removeById(ids);categoryService.remove(ids);return R.success("分類信息刪除成功");}@PutMappingpublic R<String> update(@RequestBody Category category){log.info("根據(jù)id更新分類信息:{}",category);categoryService.updateById(category);return R.success("修改分類信息成功");}
}

5.3 功能測試

?

http://m.risenshineclean.com/news/65675.html

相關(guān)文章:

  • 怎么做視頻解析的網(wǎng)站如何設(shè)置友情鏈接
  • 抄襲網(wǎng)站案例seo查詢友情鏈接
  • 深圳有名的做公司網(wǎng)站廣州私人做網(wǎng)站
  • 紅杭州網(wǎng)站建設(shè)推銷廣告
  • 開發(fā)網(wǎng)站開發(fā)工程師附近的教育培訓機構(gòu)有哪些
  • 浦東新區(qū)建設(shè)交通委網(wǎng)站鄭州seo線下培訓
  • 青島網(wǎng)絡(luò)優(yōu)化seo 頁面
  • 多種語言獨立網(wǎng)站wordpress抖音廣告怎么投放
  • 無人高清影視在線觀看seo運營招聘
  • 佛山網(wǎng)站建設(shè)是哪個好東莞谷歌推廣
  • html5網(wǎng)站導航品牌策略怎么寫
  • 做家教網(wǎng)站要多少錢google安卓手機下載
  • 河南省城鄉(xiāng)建設(shè)廳官網(wǎng)seo優(yōu)化中商品權(quán)重主要由什么決定
  • 網(wǎng)站設(shè)計流程包括百度指數(shù)app官方下載
  • 商標 做網(wǎng)站 是幾類谷歌seo優(yōu)化
  • 做網(wǎng)站應該怎么做行業(yè)數(shù)據(jù)統(tǒng)計網(wǎng)站
  • 石家莊哪有個人建站的網(wǎng)頁設(shè)計素材網(wǎng)站
  • 做童裝在哪個網(wǎng)站找客戶搜索引擎優(yōu)化seo方案
  • 推銷別人做網(wǎng)站有什么作用專業(yè)搜索引擎優(yōu)化電話
  • 南京整站優(yōu)化推廣和競價代運營
  • 做衣服接訂單的網(wǎng)站專業(yè)搜索引擎seo技術(shù)公司
  • 做網(wǎng)站有必要要源碼嗎營銷型網(wǎng)站有哪些功能
  • 給你一個網(wǎng)站你怎么做的嗎怎么查詢最新網(wǎng)站
  • 阿里云可以建網(wǎng)站嗎網(wǎng)絡(luò)宣傳方式有哪些
  • 網(wǎng)站和網(wǎng)頁的概念免費的網(wǎng)站域名查詢565wcc
  • 福田網(wǎng)站開發(fā)老王搜索引擎入口
  • 如何購買建設(shè)網(wǎng)站系統(tǒng)it培訓班真的有用嗎
  • 怎樣做約票的網(wǎng)站意思電商營銷推廣方案
  • 建網(wǎng)站報價 優(yōu)幫云企業(yè)培訓考試
  • 網(wǎng)站建設(shè)有哪些方法google seo 優(yōu)化招聘