还在为springboot项目使用方法而烦恼吗?保姆级教程来啦

springboot项目使用

  • 自定义类型和类型转换器代码和上一篇wb项目使用方法一样,可以移步到上一篇文章详细了解一下哦~
  • 项目使用了mybatis-plus插件。

配置自定义类型和类型转换器

在项目配置文件里application.yml里加上配置type-handlers-packagetype-aliases-package:分别指出你的类型转换器所在包名和自定义类所在包名。

mybatis-plus:
  global-config:
    db-config:
      logic-delete-field: deleted
      logic-not-delete-value: "0"
      logic-delete-value: "1"
  mapper-locations: "classpath*:/mapper/**/*.xml"
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  type-handlers-package: com.banxian.mybatis.typehandler
  type-aliases-package: com.banxian.mybatis.alias

mybatis-plus的使用

当然上面web项目的查询、新增和修改使用方法这里也是可以正常使用的

1)在实体类上使用注解 @TableName(autoResultMap = true)

2)在加密字段上指明类型@TableField(value = "sfz", typeHandler = SecretFieldTypeHandler.class)

@Data
@TableName(autoResultMap = true)
public class User implements Serializable {

    private static final long serialVersionUID = 4344848828462926573L;

    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Integer id;

    /**
     * 名称
     */
    private String userName;

    /**
     * 是否删除 1:是  0:否
     */
    @TableLogic
    private String deleted;

    /**
     * 是否有效 1:是  0:否
     */
    private String valid;

    /**
     * 创建时间
     */
    @TableField(value = "create_at", fill = FieldFill.INSERT)
    private LocalDateTime createAt;

    /**
     * 更新时间
     */
    @TableField(value = "update_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateAt;

    @TableField(value = "sfz", typeHandler = SecretFieldTypeHandler.class)
    private String sfz;
}
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章