关于mybatis plus中手写sql查询enum

首先,我系统里之前是mybatis,现在用mp,就得解决冲突问题。mp本身有个mybatis,要把之前的pageHelper中的mybatis exclude出去:

<dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
             <exclusions>
                <exclusion>
                    <groupId>org.mybatis</groupId>
                    <artifactId>mybatis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

然后看mp官网配置,其他都一样,只不过这里有个细节:这个必须加上才能在xml手写的时候查询enum的类型,比如状态

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer customizer(){
        return builder -> builder.featuresToEnable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
    }

例如:

<select id="selectAll" resultType="xxxx2" parameterType="xxxx">
    select * from xxx b
         where 1=1 
        <if test="status != null">
            AND b.status = #{status}
        </if>  
        
        
 </select>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容