学习汇总:

数据表中直接存放json格式的一些思考_Cym02的博客-CSDN博客_数据库应不应该存json

JSON数组存入数据库,取出后变成了字符串的问题_渝小白的博客-CSDN博客_jsonarray存到数据库后格式不对

mybatis plus保存JSON数组到mysql数据库_静水楼台x的博客-CSDN博客_mybatisplus 存数组

mybatis-plus 实体json互相转化; typeHandler的使用_mybatisplus中的json转换_维维悄悄写代码的博客-CSDN博客

Site Unreachable

Mybatis优雅存取json字段的解决方案 - TypeHandler (一) - 简书

Mybatis优雅存取json字段的解决方案 - TypeHandler (二) - 简书

使用 hutool 工具类解析 json 对象_create17的博客-CSDN博客_hutool jsonobject

前端传递JSON数组

后端接收

实体类改造

使用List<\T> 存取:

假如我timeperiod不使用String,而使用Date类型呢?

前端修改传入时间组件;

更新成功

注意,修改数据库存储类型,否则不够;

MySQL中tinytext、text、mediumtext和longtext等各个类型详解_youcijibi的博客-CSDN博客_mediumtext

修改xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hl.emsystem.model.dao.ResumeMapper">
  <resultMap id="BaseResultMap" type="com.hl.emsystem.model.pojo.Resume">
    <id column="StuNo" jdbcType="CHAR" property="stuno" />
    <result column="StuName" jdbcType="VARCHAR" property="stuname" />
    <result column="ResID" jdbcType="BIGINT" property="resid" />
    <result column="GraDate" jdbcType="TIMESTAMP" property="gradate" />
    <result column="Job" jdbcType="VARCHAR" property="job" />
    <result column="Language" jdbcType="CHAR" property="language" />
    <result column="Level" jdbcType="CHAR" property="level" />
    <result column="Computer" jdbcType="CHAR" property="computer" />
    <result column="Office" jdbcType="VARCHAR" property="office" />
    <result column="Phone" jdbcType="BIGINT" property="phone" />
    <result column="Mail" jdbcType="VARCHAR" property="mail" />
    <result column="Address" jdbcType="VARCHAR" property="address" />
    <result column="Experience" jdbcType="VARCHAR" property="experience" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
  </resultMap>
  <sql id="Base_Column_List">
    StuNo, StuName, ResID, GraDate, Job, `Language`, `Level`, Computer, Office, Phone,    Mail, Address, Experience
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select<include refid="Base_Column_List" />
    from resume    where StuNo = #{stuno,jdbcType=CHAR}  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from resume    where StuNo = #{stuno,jdbcType=CHAR}  </delete>
  <insert id="insert" parameterType="com.hl.emsystem.model.pojo.Resume">
    insert into resume (StuNo, StuName, ResID,      GraDate, Job, `Language`,
      `Level`, Computer, Office,
      Phone, Mail, Address,
      Experience)
    values (#{stuno,jdbcType=CHAR}, #{stuname,jdbcType=VARCHAR}, #{resid,jdbcType=BIGINT},      #{gradate,jdbcType=TIMESTAMP}, #{job,jdbcType=VARCHAR}, #{language,jdbcType=CHAR},
      #{level,jdbcType=CHAR}, #{computer,jdbcType=CHAR}, #{office,jdbcType=VARCHAR},
      #{phone,jdbcType=BIGINT}, #{mail,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
      #{experience,jdbcType=VARCHAR,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler})
  </insert>
  <insert id="insertSelective" parameterType="com.hl.emsystem.model.pojo.Resume">
    insert into resume    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="stuno != null">
        StuNo,      </if>
      <if test="stuname != null">
        StuName,      </if>
      <if test="resid != null">
        ResID,      </if>
      <if test="gradate != null">
        GraDate,      </if>
      <if test="job != null">
        Job,      </if>
      <if test="language != null">
        `Language`,      </if>
      <if test="level != null">
        `Level`,      </if>
      <if test="computer != null">
        Computer,      </if>
      <if test="office != null">
        Office,      </if>
      <if test="phone != null">
        Phone,      </if>
      <if test="mail != null">
        Mail,      </if>
      <if test="address != null">
        Address,      </if>
      <if test="experience != null">
        Experience,      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="stuno != null">
        #{stuno,jdbcType=CHAR},      </if>
      <if test="stuname != null">
        #{stuname,jdbcType=VARCHAR},      </if>
      <if test="resid != null">
        #{resid,jdbcType=BIGINT},      </if>
      <if test="gradate != null">
        #{gradate,jdbcType=TIMESTAMP},      </if>
      <if test="job != null">
        #{job,jdbcType=VARCHAR},      </if>
      <if test="language != null">
        #{language,jdbcType=CHAR},      </if>
      <if test="level != null">
        #{level,jdbcType=CHAR},      </if>
      <if test="computer != null">
        #{computer,jdbcType=CHAR},      </if>
      <if test="office != null">
        #{office,jdbcType=VARCHAR},      </if>
      <if test="phone != null">
        #{phone,jdbcType=BIGINT},      </if>
      <if test="mail != null">
        #{mail,jdbcType=VARCHAR},      </if>
      <if test="address != null">
        #{address,jdbcType=VARCHAR},      </if>
      <if test="experience != null">
        #{experience,jdbcType=VARCHAR,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler},      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.hl.emsystem.model.pojo.Resume">
    update resume    <set>
      <if test="stuname != null">
        StuName = #{stuname,jdbcType=VARCHAR},      </if>
      <if test="resid != null">
        ResID = #{resid,jdbcType=BIGINT},      </if>
      <if test="gradate != null">
        GraDate = #{gradate,jdbcType=TIMESTAMP},      </if>
      <if test="job != null">
        Job = #{job,jdbcType=VARCHAR},      </if>
      <if test="language != null">
        `Language` = #{language,jdbcType=CHAR},      </if>
      <if test="level != null">
        `Level` = #{level,jdbcType=CHAR},      </if>
      <if test="computer != null">
        Computer = #{computer,jdbcType=CHAR},      </if>
      <if test="office != null">
        Office = #{office,jdbcType=VARCHAR},      </if>
      <if test="phone != null">
        Phone = #{phone,jdbcType=BIGINT},      </if>
      <if test="mail != null">
        Mail = #{mail,jdbcType=VARCHAR},      </if>
      <if test="address != null">
        Address = #{address,jdbcType=VARCHAR},      </if>
      <if test="experience != null">
        Experience = #{experience,jdbcType=VARCHAR,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler},      </if>
    </set>
    where StuNo = #{stuno,jdbcType=CHAR}  </update>
  <update id="updateByPrimaryKey" parameterType="com.hl.emsystem.model.pojo.Resume">
    update resume    set StuName = #{stuname,jdbcType=VARCHAR},      ResID = #{resid,jdbcType=BIGINT},      GraDate = #{gradate,jdbcType=TIMESTAMP},      Job = #{job,jdbcType=VARCHAR},      `Language` = #{language,jdbcType=CHAR},      `Level` = #{level,jdbcType=CHAR},      Computer = #{computer,jdbcType=CHAR},      Office = #{office,jdbcType=VARCHAR},      Phone = #{phone,jdbcType=BIGINT},      Mail = #{mail,jdbcType=VARCHAR},      Address = #{address,jdbcType=VARCHAR},      Experience = #{experience,jdbcType=VARCHAR,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler}    where StuNo = #{stuno,jdbcType=CHAR}  </update>
</mapper>

结果