1. @RequestBody(required = false)
@RequestBody(required = false)表示可以不传对象,默认时true表示必须传对象过来
2. 进入docker某一镜像命令
docker exec -it storage /bin/bash
//storge是镜像名字
exit
//退出该容器命令
3. tobao/fastdfs_client测试记录
-
springboot启动类
/** * @author jss * @version 1.0 * @date 2021/9/13 11:13 * @description 标题 * @packge com.changgou */ //排除数据源的自动配置,不然会报错配置了数据库的url @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) @EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING) public class FileApplication { public static void main(String[] args) { SpringApplication.run(FileApplication.class, args); } }
-
yml配置
#fastdfs 配置 fdfs: # 读取时间 so-timeout: 1500 # 连接超时时间 connect-timeout: 600 # 缩略图 thumb-image: width: 150 height: 150 # Tracker服务,确保tracker storage nginx已经启动 tracker-list: - 192.168.0.166:22122 pool: #从池中借出的对象的最大数目 max-total: 153 max-wait-millis: 102 jmx-name-base: 1 jmx-name-prefix: 1
-
测试类
@SpringBootTest @RunWith(SpringRunner.class) public class FastdfsTest { @Autowired private FastFileStorageClient storageClient; @Autowired private ThumbImageConfig thumbImageConfig; @Test public void testTobaoUpload() throws FileNotFoundException { File file = new File("F:\\test\\timg53OREYQX.jpg"); //上传并且生成缩略图 StorePath jpg = storageClient.uploadFile(new FileInputStream(file), file.length(), "jpg", null); System.out.println(jpg.getFullPath()); System.out.println(jpg.getPath()); } }
4. 上传文件的解析
@PostMapping("/upload")
//MultipartFile参数 是commons-fileupload.jar解析的, springboot已经配置了该jar包,所以这可以直接用
public String upload(MultipartFile file) throws Exception {
}
5. javax.persistence.Transient注解
该属性不需要映射映射数据库表的字段
6. @Autowired加载时间
在所在类的构造函数运行完才会运行@Autowired
7. 开启mybatis驼峰命名和下划线命名的互转
自动匹配pojo和表的字段
ybatis:
configuration:
map-underscore-to-camel-case: true #开启mybatis驼峰命名和下划线命名的互转
8. feign
feign就是跟浏览器一样,发送url请求的,这个feign就是从eureka中找到content的服务名
* 然后去访问ip/content/list/category/{id}的
* 当然content服务中要实现/content/list/category/{id}这个请求的回应
*
在这就是个接口,更content服务没关系,是想访问content服务的另一个服务调用的,谁想调用这个接口
*
谁就需要开启Enablefeignclient,就可以通过向浏览器发请求似的请求服务,并得到数据
/**
* @author ljh
* @version 1.0
* @date 2020/12/26 16:37
* @description
* FeignClient参数
* name 是微服务的名字
* path = "/content"相当于@requestMapping
* RequestMapping("/content")
* @package com.changgou.content.feign
*/
@FeignClient(name="content",path = "/content")
public interface ContentFeign {
/**
* 根据广告分类的ID 获取广告分类下的所有的广告列表数据
* feign就是跟浏览器一样,发送url请求的,这个feign就是从eureka中找到content的服务名
* 然后去访问ip/content/list/category/{id}的
* 当然content服务中要实现/content/list/category/{id}这个请求的回应
* 在这就是个接口,更content服务没关系,是想访问content服务的另一个服务调用的,谁想调用这个接口
* 谁就需要开启Enablefeignclient,就可以通过向浏览器发请求似的请求服务,并得到数据
* @param id
* @return
*/
@GetMapping("/list/category/{id}")
public Result<List<Content>> findByCategory(@PathVariable(name="id") Long id);
}
9 docker进入redis 客户端
-
进入redis的docker
-
进入文件夹
cd /usr/local/bin
-
进入redis客户端
./redis-cli
10 jackson转换日期问题
jackson转换日期为json时, 需要给定日期格式,和时区, 要不时区默认是GMT
spring加如下配置
# 设置日期格式转为json的格式以及时区, json默认是GMT
spring:
jackson:
date-format: java.text.SimpleDateFormat
time-zone: GMT+8
11. 一致性hash算法
为了解决集群中一个节点坏掉, 影响hash算法的准确性, 并且提升均匀分布,
不会出现某个节点压力大
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-j96FAFVy-1641369291061)(C:%E5%9D%9A%E6%9E%9C%E4%BA%91%E5%90%8C%E6%AD%A5%E5%9D%9A%E6%9E%9C%E4%BA%91%E5%90%8C%E6%AD%A5%E7%AC%94%E8%AE%B0%E7%95%85%E8%B4%AD\img%E2%91%A0%E5%A4%87%E5%BF%98\image-20211021110155325.png)]
有1个hash环
要访问存储的对象object, 通过hash算法得出一个值, 一定落在hash环上
object如果正好落在的节点上, 节点就处理这个object
如果没有, 就顺时针移动该object, 碰到的第一个节点, 就再该节点执行
为了能均匀分布object, 每一个节点都会有160个虚拟机节点, 就是说,
hash环上一个真实的节点, 会在环上均匀虚拟160个节点,
如果object走到虚拟节点, 就会在真实节点执行