当前位置: 首页 > wzjs >正文

it企业网站模板下载b站推广有用吗

it企业网站模板下载,b站推广有用吗,南昌购物网站制作,网站重新设计在Mybaties Plus 里面的逻辑删除功能简介 逻辑删除是一种数据管理策略,它允许应用程序通过标记数据记录为“已删除”而不是从数据库中物理删除记录来维护数据的完整性。 在 MyBatis Plus 中实现逻辑删除的简介如下: • 字段约定:在数据表中定…

在Mybaties Plus 里面的逻辑删除功能简介

逻辑删除是一种数据管理策略,它允许应用程序通过标记数据记录为“已删除”而不是从数据库中物理删除记录来维护数据的完整性。

在 MyBatis Plus 中实现逻辑删除的简介如下:

• 字段约定:在数据表中定义一个逻辑删除标志字段,常用的字段名为is_deleteddeleted,字段类型通常为tinyintboolean

• 默认值:该字段的默认值应设置为表示未删除的状态,例如0(未删除)和1(已删除)。

• 查询过滤:在执行查询操作时,自动添加过滤条件以排除逻辑删除的数据。MyBatis Plus 提供了自动过滤逻辑删除记录的功能,无需手动编写 SQL 语句来排除这些记录。

• 操作接口:MyBatis Plus 提供了SoftDelete接口,实体类实现该接口后,可以自动应用逻辑删除策略。

• 删除操作:更新操作不再直接删除数据库记录,而是更新逻辑删除标志字段的值为已删除状态。

• 配置:在 MyBatis Plus 的配置中,可以指定逻辑删除的字段名和删除值,以便框架自动识别和处理逻辑删除。

逻辑删除的优点包括:

• 数据恢复:逻辑删除的数据可以被恢复,因为它们仍然存在于数据库中。

• 数据审计:可以追踪数据的删除历史,有助于数据审计和分析。

• 性能:避免了物理删除操作可能引起的性能问题,如索引重组等。

逻辑删除是一种在业务逻辑层面上处理删除操作的方法,它通过改变数据的状态来模拟删除效果,而不是真正从数据库中移除数据。这种方法在需要保留历史数据记录的场景中非常有用。

使用案例

controller层

package com.nie.lease.web.admin.controller.apartment;import com.nie.lease.common.result.Result;
import com.nie.lease.model.entity.PaymentType;
import com.nie.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;@Tag(name = "支付方式管理")
@RequestMapping("/admin/payment")
@RestController
public class PaymentTypeController {@Autowiredprivate PaymentTypeService paymentTypeService;@Operation(summary = "查询全部支付方式列表")@GetMapping("list")public Result<List<PaymentType>> listPaymentType() {List<PaymentType> list = paymentTypeService.list();return Result.ok(list);}@Operation(summary = "保存或更新支付方式")@PostMapping("saveOrUpdate")public Result saveOrUpdatePaymentType(@RequestBody PaymentType paymentType) {return Result.ok();}@Operation(summary = "根据ID删除支付方式")@DeleteMapping("deleteById")public Result deletePaymentById(@RequestParam Long id) {return Result.ok();}}

service层

package com.nie.lease.web.admin.service;import com.nie.lease.model.entity.PaymentType;
import com.baomidou.mybatisplus.extension.service.IService;/**
* @author liubo
* @description 针对表【payment_type(支付方式表)】的数据库操作Service
* @createDate 2023-07-24 15:48:00
*/
public interface PaymentTypeService extends IService<PaymentType> {}

当我们这样写之后 我们可以看出 他逻辑删除的数据依旧被查询出来了
在这里插入图片描述

解决办法:

解决方案一:

直接添加一个过滤条件 只查询isDeleted为0的数据

package com.nie.lease.web.admin.controller.apartment;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nie.lease.common.result.Result;
import com.nie.lease.model.entity.PaymentType;
import com.nie.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;@Tag(name = "支付方式管理")
@RequestMapping("/admin/payment")
@RestController
public class PaymentTypeController {@Autowiredprivate PaymentTypeService paymentTypeService;@Operation(summary = "查询全部支付方式列表")@GetMapping("list")public Result<List<PaymentType>> listPaymentType() {LambdaQueryWrapper<PaymentType> paymentTypeLambdaQueryWrapper = new LambdaQueryWrapper<>();paymentTypeLambdaQueryWrapper.eq(PaymentType::getIsDeleted,0);List<PaymentType> list = paymentTypeService.list(paymentTypeLambdaQueryWrapper);return Result.ok(list);}

·

解决方案二:直接使用Mybaties plus的逻辑删除功能

两个办法二选一即可

办法一:配置application.yml
mybatis-plus:global-config:db-config:logic-delete-field: flag # 全局逻辑删除的实体字段名(配置后可以忽略不配置步骤二)logic-delete-value: 1 # 逻辑已删除值(默认为 1)logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
办法二:在实体类中的删除标识字段上增加@TableLogic注解

@TableLogic的作用是标识逻辑删除字段

package com.nie.lease.model.entity;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;import java.io.Serializable;
import java.util.Date;@Data
public class BaseEntity implements Serializable {@Schema(description = "主键")@TableId(value = "id", type = IdType.AUTO)private Long id;@Schema(description = "创建时间")@TableField(value = "create_time")private Date createTime;@Schema(description = "更新时间")@TableField(value = "update_time")private Date updateTime;@Schema(description = "逻辑删除")@TableLogic@TableField("is_deleted")private Byte isDeleted;}

再次进行测试

package com.nie.lease.web.admin.controller.apartment;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nie.lease.common.result.Result;
import com.nie.lease.model.entity.PaymentType;
import com.nie.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;@Tag(name = "支付方式管理")
@RequestMapping("/admin/payment")
@RestController
public class PaymentTypeController {@Autowiredprivate PaymentTypeService paymentTypeService;@Operation(summary = "查询全部支付方式列表")@GetMapping("list")public Result<List<PaymentType>> listPaymentType() {List<PaymentType> list = paymentTypeService.list();return Result.ok(list);}}

这样我们就可以看到被逻辑删除的数据就不会再次显示了
在这里插入图片描述

http://www.dtcms.com/wzjs/255905.html

相关文章:

  • 北京手机网站制作公司个人网页模板
  • 行业网站建设的书外贸seo推广
  • wordpress适合百度吗临沂百度seo
  • 敦化网站开发河北百度seo
  • 建网站服务器系统如何在手机上制作网站
  • 高端网站建设需要的人员配备网络营销实施方案
  • 网站怎样绑定域名seo咨询服务价格
  • 长春疫情最新情况分布图福州搜索引擎优化公司
  • javaee做网站建设整合营销策划方案模板
  • 做网站单位做网页的网站
  • 营销网站的成功案例网站推广推广
  • 当今做啥网站致富网站设计培训
  • 学做网站需要哪几本书知乎关键词搜索
  • 找人做网站应该注意哪些教育培训机构前十名
  • 南京网站设计课程百度竞价排名案例分析
  • 网站上的格式用html怎么做官网站内推广内容
  • 性价比高柳州网站建设第一推广网
  • 房产建设网站企业培训课程分类
  • 网站怎么做图片超链接dw百度官网首页登录入口
  • 有什么做兼职的医疗网站百度seo推广免费
  • 网站开发与建设课程设计软文推广渠道主要有
  • 网站项目方案营销策略包括哪些内容
  • vs平台做网站最新疫情爆发
  • 公司网站开发详细流程58同城推广效果怎么样
  • 做早餐的网站bing搜索引擎下载
  • 备案域名价格百度首页排名优化价格
  • 网站所有者是什么意思微信公众号运营推广方案
  • 杭州有做网站深圳网络推广网站推广
  • 浙江网站建设公司电话郑州见效果付费优化公司
  • 网站建设找什么工作室成都网站建设软件