springboot各种集成

本文介绍如何在Spring Boot项目中配置FastJSON以提高JSON处理效率并解决NULL值显示问题,同时分享PageHelper与Druid数据库连接池的依赖引入方式,以及MyBatis的配置细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

fastjson

两个方法

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        // 定义一个convert转换消息对象
        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
        // 添加fastjosn配置信息, 比如是否格式化返回的json数据
//        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        // convert中添加配置
//        fastConverter.setFastJsonConfig(fastJsonConfig);
        // 添加到convert中
        converters.add(fastConverter);
    }
}

方法2(这个可以避免null,加快速度

@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
FastJsonHttpMessageConverter oFastConverter = new FastJsonHttpMessageConverter();
FastJsonConfig oFastJsonConfig = new FastJsonConfig();
oFastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
oFastConverter.setFastJsonConfig(oFastJsonConfig);
//处理中文乱码问题
List<MediaType> oFastMediaTypeList = new ArrayList<>();
oFastMediaTypeList.add(MediaType.APPLICATION_JSON_UTF8);
oFastConverter.setSupportedMediaTypes(oFastMediaTypeList);

HttpMessageConverter<?> oConverter = oFastConverter;
return new HttpMessageConverters(oConverter);
}

  pagehelper

<dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.4</version>
        </dependency>

druid

<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.9</version>
  </dependency>

 mybatis(在实体类改了DO后缀的,记得在xml改

mybatis:
typeAliasesPackage: com.biao.entity
mapper-locations: classpath:mapper/*/*.xml
configuration:
#配置项:开启下划线到驼峰的自动转换. 作用:将数据库字段根据驼峰规则自动注入到对象属性。
map-underscore-to-camel-case: true

#打印SQL信息
logging:
level:
com:
biao:
dao: DEBUG
@MapperScan("com.biao.dao")

 

ps:由于在mybaits使用了@Mapper的注解代替原来的@repository,因此idea会监测到错误,因为idea只能检查java标准的注解和spring的,除非加了mybatis的插件(要收费),所以把Autowired的错误改了警告编译就能通过了

 

转载于:https://www.cnblogs.com/vhyc/p/8762004.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值