Skip to content

YuanKQ/SpringBootTutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SpringBoot 2.0 学习计划

在查找配置文件相关文档时,务必要保证SpringBoot的版本号要匹配

Spring Boot 2.0.3
fastJson 1.2.17
redis 4.0   

Spring Core

理解Bean的作用域,生命周期,体会Bean的注入

详见《Spring实战》第三版:第1章~第3章

常见注解

@ppt,@Bean

@Controller,@RestController

@RequestMapping

Spring Web

配置模板引擎

ViewResolverConfig

配置路由(URL映射)

UrlMappingController.java

fastJson配置

使用 Fastjson 提供的FastJsonHttpMessageConverter 来替换 Spring 默认的 HttpMessageConverter以提高@RestController, @ResponseBody, @RequestBody 注解的 JSON序列化速度

官方doc: http://static.javadoc.io/com.alibaba/fastjson/1.2.33/index.html @JsonField解析: https://github.com/alibaba/fastjson/wiki/JSONField sample: http://www.baeldung.com/fastjson 配置: https://www.jianshu.com/p/aabd308ac963

序列化 JSON.toJSONString():Object --> String

  • private/protected字段没有加getter方法的话,该字段不会被序列化(该字段不会输出到String中)

反序列化 JSON.parseObject():String --> Object

  • private/protected字段没有setter方法的话,该字段不会被反序列化(该字段的值保留为系统默认值)
  • define a no-args or default constructor

验证:

  • 本地 JSON.toJSONString()JSON.parseObject()
  • client与server端:JSON序列化与反序列化

Spring Data

Redis

install redis

倘若是Manjaro,直接在Terminal命令输入yaourt -S redis 其他OS参见官网:http://www.baeldung.com/spring-data-redis-tutorial

Introduction to Spring Data Redis

first run Reids by the command redis-server /etc/redis.conf --port 7001

以上配置只能二选一,虽然方法2减少配置工作量,但是作用有限,当你需要使用RedisTemplate,只能使用方法1.

使用RedisTemplate实现CRUD操作

先看这个tutorial: https://www.cnblogs.com/EasonJim/p/7803067.html,对RedisTemplate常用操作有个基本了解

在 Spring Data Redis 中集成 Fastjson: https://github.com/alibaba/fastjson/wiki/%E5%9C%A8-Spring-%E4%B8%AD%E9%9B%86%E6%88%90-Fastjson

所有步骤:http://javasampleapproach.com/spring-framework/spring-data/spring-data-redis-example-spring-boot-redis-example#2Configure_Spring_Data_Redis

不要忘了在相应的repo的类中添加@Repository

Redis缓存配置

RedisCacheManager在SpringBoot2.0中有较大改动。

最简单的配置,可用于测试配置是否正确:https://blog.csdn.net/fanpeizhong/article/details/79998164 注解失效时间+主动刷新缓存:https://www.cnblogs.com/ASPNET2008/p/6511500.html, https://www.cnblogs.com/ASPNET2008/p/8733087.html

@Cacheable,@CachePut, @CacheEvict, @CacheConfig介绍:https://blog.csdn.net/poorCoder_/article/details/55258253

cacheNames可以一样,但是key不能一样 ==> 待证实

@Cacheable,@CachePut, @CacheEvict, @CacheConfig实战:https://my.oschina.net/silenceyawen/blog/1555996

About

SpringBoot 从入门到弃坑

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages