springboot各种集成
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的错误改了警告编译就能通过了