mybatis pit row diary 1 – @TableField(typeHandler = JacksonTypeHandler.class) does not take effect when querying and is null

Using @TableField(typeHandler = JacksonTypeHandler.class) often finds that data can be added, but the query result is null, record it

Empty query results
1. If you encounter empty query results when using JacksonTypeHandler, you may need to add the autoResultMap attribute to the @TableName annotation. For example:

@TableName(value = “my_table”, autoResultMap = true)

public class MyObject {
    
    
    // ...
}

This will automatically generate a result map that can help prevent empty query results.

2. Processing arrays
If you need to process arrays in MyBatis applications, you can use JacksonTypeHandler and @TableField annotations. For example:

@TableField(typeHandler = JacksonTypeHandler.class)
private String[] tags;

This will enable you to map arrays of JSON data to Java objects.

3. Custom result type
Usually, if you use mybatis-plus to automatically generate, there is no problem, but if you customize sql, you need to define the typeHandler attribute

If you are not using MyBatis' built-in basemapper and need to define your own result types, you can use the typeHandler attribute on the resultMap element. For example:

<resultMap id="myResultMap" type="com.example.MyObject">
    <result column="data" property="data" typeHandler="com.example.JacksonTypeHandler"/>
</resultMap>

This will enable you to specify custom type handlers for specific columns in the result map.

Generally speaking, it is the above three problems that lead to

Guess you like

Origin blog.csdn.net/weixin_43866043/article/details/130826492