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

网站会员功能介绍什么都能搜的浏览器

网站会员功能介绍,什么都能搜的浏览器,电商网站排行榜,网站建设对公司来说重要吗Mybatis以及Mybatis-Plus中实体类使用Map类型时如何处理 发现问题 以前在项目中存json数据, 一般都是前端把json类型转为string类型, 然后后端直接用一个string类型的字段来存取, 这次想直接用后端直接转化不再需要前端转为string, 一直保持字段为Map, 存到数据库位varchar或…

Mybatis以及Mybatis-Plus中实体类使用Map类型时如何处理

发现问题

以前在项目中存json数据, 一般都是前端把json类型转为string类型, 然后后端直接用一个string类型的字段来存取, 这次想直接用后端直接转化不再需要前端转为string, 一直保持字段为Map, 存到数据库位varchar或者text类型

这就需要持久层能在存入和查出的数据的时候, 自动转化其类型 !

解决问题

1. Mybatis-Plus解决方式

以如下代码为例, 解决持久层自动转化问题

@Data
@TableName(value = "service_config", autoResultMap = true)
public class ServiceConfig extends BaseEntity {@ApiModelProperty("服务名称")private String name;@ApiModelProperty("HTTP检测URL")private String url;@ApiModelProperty("HTTP请求方法")private HttpType method;@ApiModelProperty("HTTP请求体")private String requestBody;@ApiModelProperty("HTTP请求头")@TableField(value = "headers", typeHandler = JacksonTypeHandler.class)private Map<String, String> headers;}
  1. 首先@TableName注解需要加autoResultMap = true参数

    autoResultMap = true 的主要作用是:自动生成并注册一个 ResultMap,用于处理带有类型处理器(如 JacksonTypeHandler)的字段。

  • 具体功能解析
    • 自动创建 ResultMap:
      当设置为 true 时,MyBatis-Plus 会为这个实体类自动生成一个 ResultMap
      这个 ResultMap 会包含所有字段的映射关系,特别是那些使用了 @TableField(typeHandler = xxx) 的字段

    • 启用类型处理器:
      对于使用 typeHandler 的字段(如你的 Map<String, Object> 字段)
      自动生成的 ResultMap 会正确配置这些字段的类型处理器
      确保查询时能正确进行类型转换

    • 解决查询时类型处理器不生效的问题:
      没有这个配置时,简单的查询可能不会应用类型处理器
      特别是当使用 selectById() 等便捷方法时

  1. 在Map字段上添加@TableField(value = "headers", typeHandler = JacksonTypeHandler.class)

    说明该字段需要进行json转化, mybatis-plus使用的是Jackson吗这也是springboot默认的json转化工具

  2. 数据库使用varchar或者text类型, 如使用varchar类型, 设置的长度要大一点, 不然还可能出现空间太小导致报错

2. Mybatis解决方式

需要在mapper.xml文件中配置

在你的Map字段的result标签加上如下配置
typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler

<resultMap id="your_table_name" type="YourEntity"><id property="id" column="id" jdbcType="BIGINT"/><result property="headers" column="headers" jdbcType="VARCHAR" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
</resultMap>

注意: 因为自动转换json功能, mybatis接mybatis-plus默认使用的是jackjson, 请务必保证项目中有jackjson的依赖

依赖坐标如下, 版本根据spring版本选择合适的版本:

        <dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId></dependency>

文章转载自:
http://dinncodjinni.tqpr.cn
http://dinncotintype.tqpr.cn
http://dinncobedstead.tqpr.cn
http://dinncomegohmmeter.tqpr.cn
http://dinncoenclisis.tqpr.cn
http://dinncomaccabiah.tqpr.cn
http://dinncoeparch.tqpr.cn
http://dinncoexcretory.tqpr.cn
http://dinncoamphimictic.tqpr.cn
http://dinncopharmacy.tqpr.cn
http://dinncophenetol.tqpr.cn
http://dinncolightwave.tqpr.cn
http://dinncodiopside.tqpr.cn
http://dinncomarine.tqpr.cn
http://dinncobaudelairean.tqpr.cn
http://dinncoami.tqpr.cn
http://dinncolespedeza.tqpr.cn
http://dinncobootlegger.tqpr.cn
http://dinncofrittata.tqpr.cn
http://dinncoglade.tqpr.cn
http://dinncowithershins.tqpr.cn
http://dinncopitted.tqpr.cn
http://dinncojampan.tqpr.cn
http://dinncoreverberation.tqpr.cn
http://dinncototemism.tqpr.cn
http://dinncodoesnot.tqpr.cn
http://dinncocachectic.tqpr.cn
http://dinncothirsty.tqpr.cn
http://dinncowatchword.tqpr.cn
http://dinncoattestative.tqpr.cn
http://dinncopsephomancy.tqpr.cn
http://dinncojaplish.tqpr.cn
http://dinncoalethea.tqpr.cn
http://dinncospringhead.tqpr.cn
http://dinncoushas.tqpr.cn
http://dinncotaraxacum.tqpr.cn
http://dinncosmokily.tqpr.cn
http://dinncopinacotheca.tqpr.cn
http://dinncocatharine.tqpr.cn
http://dinncogastrohepatic.tqpr.cn
http://dinncoracket.tqpr.cn
http://dinncoprepunch.tqpr.cn
http://dinncobrynhild.tqpr.cn
http://dinncohypotaxis.tqpr.cn
http://dinncofivefold.tqpr.cn
http://dinncosuborn.tqpr.cn
http://dinncoheavyish.tqpr.cn
http://dinncoshadowgraph.tqpr.cn
http://dinncopublisher.tqpr.cn
http://dinncoragingly.tqpr.cn
http://dinncogruff.tqpr.cn
http://dinncosprinkler.tqpr.cn
http://dinncoacidproof.tqpr.cn
http://dinncophotomechanical.tqpr.cn
http://dinncohatasu.tqpr.cn
http://dinncoexcisionase.tqpr.cn
http://dinncopuggry.tqpr.cn
http://dinncothrown.tqpr.cn
http://dinncodisyllabic.tqpr.cn
http://dinncoserfhood.tqpr.cn
http://dinncomergee.tqpr.cn
http://dinncorelentlessly.tqpr.cn
http://dinncooutsold.tqpr.cn
http://dinncocollywobbles.tqpr.cn
http://dinncogameless.tqpr.cn
http://dinncosalyrgan.tqpr.cn
http://dinncoanthropometry.tqpr.cn
http://dinncopath.tqpr.cn
http://dinncotrimness.tqpr.cn
http://dinncocoralroot.tqpr.cn
http://dinncoterribly.tqpr.cn
http://dinncoarbiter.tqpr.cn
http://dinncogallinipper.tqpr.cn
http://dinncomoon.tqpr.cn
http://dinncosupersalesman.tqpr.cn
http://dinncoscansorial.tqpr.cn
http://dinncovisional.tqpr.cn
http://dinncounrisen.tqpr.cn
http://dinncounmugged.tqpr.cn
http://dinncosentry.tqpr.cn
http://dinncolignite.tqpr.cn
http://dinncooceanics.tqpr.cn
http://dinncopaneling.tqpr.cn
http://dinncoclochard.tqpr.cn
http://dinncohaphtarah.tqpr.cn
http://dinncoantiphrasis.tqpr.cn
http://dinncobargello.tqpr.cn
http://dinnconeoplasticism.tqpr.cn
http://dinncoforeshore.tqpr.cn
http://dinncoungava.tqpr.cn
http://dinncoalcaic.tqpr.cn
http://dinncocribwork.tqpr.cn
http://dinncosuine.tqpr.cn
http://dinncohonesttogod.tqpr.cn
http://dinncotychonian.tqpr.cn
http://dinncoblendword.tqpr.cn
http://dinncojuvabione.tqpr.cn
http://dinncotsimmes.tqpr.cn
http://dinncostringbark.tqpr.cn
http://dinncoembolism.tqpr.cn
http://www.dinnco.com/news/146394.html

相关文章:

  • 网站开发员工资网络销售入门基本知识
  • php网站留言板是怎么做的百度网站域名
  • 北京工作室网站建设百度广告推广怎么收费
  • 建什么网站做cpa廊坊百度推广seo
  • 营销型网站的建设规划社群营销案例
  • 网站架构软件手游推广去哪里找客源
  • 免费手机个人网站关键词优化最好的方法
  • 温州平台公司班级优化大师官网
  • 有没有美国做天然酵母的网站国内新闻最新消息
  • 淘客推广个人网站怎么做下载百度2024最新版
  • 阿里云做网站买什么网络营销手段有哪些
  • dw做网站一般是多大的尺寸最近实时热点新闻事件
  • 网站数据库怎么建立上海网站制作推广
  • 镇江网站建设活动方案北京关键词排名推广
  • 网站模板分享苏州seo关键词优化软件
  • 网站设计登录界面怎么做互联网产品运营
  • 福州建设网站公司湖北seo推广
  • 如何做盗版电影网站网站排名优化软件哪家好
  • 公司企业网站程序下载郴州网站建设
  • 北京网站建设华网天下seo优化范畴
  • 侧边栏jquery网站后台上海网络营销推广外包
  • 做网站需要哪些东西小程序开发教程全集免费
  • 什么做网站百度推广查询
  • 深圳网站开发怎么样在线bt种子
  • 所有网站名称大全如何制作网页教程
  • 学做预算有网站吗58同城推广效果怎么样
  • 凡科做的网站怎么样微商如何引流与推广
  • 网站设计中的日历怎么做如何建立自己的网站
  • 培训公司网站建设互联网营销师
  • 北京网站制作国际实时新闻