1.springboot.factories
没有启动类的时候可以使用:
Spring Boot 之 spring.factories的用法_我俗人的博客-CSDN博客_spring.factories
2.mp的增删改查
注意这个增加
MP的增删改查基本操作_Lkun_99的博客-CSDN博客_mp update
3.
报错,直接把这个文件删了,正常启动,真迷。重新下载。居然又好
4.阿里的fastJson转化
List
5.Arrays的使用&一个小细节
arrayList.addAll(Arrays.asList(split));
......
Map hashMap = new HashMap<>();
hashMap.put("content", stringBuilder.toString());
//这里有一个小细节,如果直接上stringBuider打印的是地址,所以要toString
//arrayList底层String
hashMap.put("images", arrayList);
6.手写异常:
ResponseResult responseResult=saveArticle(wmNews);
if (!responseResult.getCode().equals(200)){
throw new RuntimeException("失败了")
}
7.报错
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
siteController (field private com.weareint.mcs_test.service.ISiteService com.weareint.mcs_test.controller.SiteController.iSiteService)
┌─────┐
| siteServiceImpl (field private com.weareint.mcs_test.service.ITranshipPlatformService com.weareint.mcs_test.service.impl.SiteServiceImpl.iTranshipPlatformServicepl)
↑ ↓
| transhipPlatformServiceImpl (field private com.weareint.mcs_test.service.ISiteService com.weareint.mcs_test.service.impl.TranshipPlatformServiceImpl.iSiteService)
└─────┘
Action:
Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.
service层就调用mapper,解决问题。
//这么写就是循环依赖
WmNews wmNews = wmNewsService.getById(id);
//更改之后
WmNews wmNews = wmNewsMapper.selectById(id);
8.@Async异步调用注解
1.zset数据结构:
2.如果有两个校验我们要做,我们可以一起抛出一个异常。
3.调用 BaseMapper 的 insert方法后 ,默认将自增主键封装在 插入对象中
4.懒加载
Task task=null;//这个地方先不用null因为不一定用的上
try {
//从数据表删除
taskinfoMapper.deleteById(taskId);
//更改日志表的状态
TaskinfoLogs taskinfoLogs = taskinfoLogsMapper.selectById(taskId);
taskinfoLogs.setStatus(status);
taskinfoLogsMapper.updateById(taskinfoLogs);
task=new Task();//这个地方在new,这就是懒加载。
5.redis的用法
6.Json的方法
json中的json.parseObject()方法和json.tojsonString()方法_wodetian1225的博客-CSDN博客_json.tojsonstringJSON.parseObject,是将Json字符串转化为相应的对象;JSON.toJSONString则是将对象转化为Json字符串。在前后台的传输过程中,Json字符串是相当常用的,这里就不多介绍其功能了,直接举一下应用的小例子,帮助理解这两个方法的用法。首先用maven引入fastjson<?xml version="1.0" encoding="UTF-8"?><pro...https://blog.csdn.net/wodetian1225/article/details/80975719 toString和toJSONString的区别_in the way的博客-CSDN博客_tojsonstring和tostringMap
map = new HashMap<>(); map.put( "staff9", 1 ); map.put( "staff1", 3 ); System.out.println(map.toString()); System.out.println(JSONObject.toJSONString(map));... https://blog.csdn.net/sinat_36454672/article/details/105969975?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164994196416780255289040%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164994196416780255289040&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-2-105969975.142%5Ev8%5Epc_search_result_control_group,157%5Ev4%5Econtrol&utm_term=JSON.toJSONString%E5%92%8CArrays.toString&spm=1018.2226.3001.4187
7.@Schedule定时任务,Calendar获取时间的方法
定时器@Scheduled(cron = "0 0/1 * * * ?")问题_潇~~樊的博客-CSDN博客定时器配置步骤参考:http://blog.csdn.NET/sd4000784/article/details/7745947下面给出cron参数中各个参数的含义:CRON表达式 含义"0 0 12 * * ?" 每天中午十二点触发"0 15 10 ? * *" 每天早上10:15触发"0 15 10 * * ?" 每天早上10:15触发"0 15...https://blog.csdn.net/weixin_43548284/article/details/105368358?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165011067616780269892479%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=165011067616780269892479&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-105368358.142%5Ev9%5Econtrol,157%5Ev4%5Econtrol&utm_term=%40Scheduled%28cron+%3D+0+*%2F1+*+*+*+%29&spm=1018.2226.3001.4187
8.启动两个端口的时候设置端口的默认值:
server:
port: ${server.port:51701}
9.为了让数据库在每次程序启动的时候刷新,所以要加上@PostConstruct注解。
@PostConstruct详解_一个喜欢健身的程序员的博客-CSDN博客_postconstruct定义: @PostContruct是spring框架的注解,在方法上加该注解会在项目启动的时候执行该方法,也可以理解为在spring容器初始化的时候执行该方法。 从Java EE5规范开始,Servlet中增加了两个影响Servlet生命周期的注解,@PostConstruct和@PreDestroy,这两个注解被用来修饰一个非静态的void()方法。用法:@Post...https://blog.csdn.net/sunayn/article/details/92840439?ops_request_misc=&request_id=&biz_id=102&utm_term=@postconstruct&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-92840439.nonecase&spm=1018.2226.3001.4187 以上是详解
10.关于feign的调用方法:
11.Mysql的blog类型
blob类型简介类型简介
BLOB (binary large object)即二进制大对象,是一种可以存储二进制文件的容器。在计算机中,BLOB常常是数据库中用来存
储二进制文件的字段类型。常见的BLOB文件有图片、声音和自定义对象等
12.要求一个集合可是我只有一个字符串怎么办?
使用:Collection.singleList
1.es条件查询:
boolQueryBuilder:
searchSourceBuilder 他装下了boolQueryBuilder
最后是searchRequest,他又把searchSourceBuilder装了。
2.获取当前线程
0.注意一定要先从token中找到用户信息不然塞不进去
网关进行token解析后,把解析后的用户信息存储到header中
//获得token解析后中的用户信息
Object userId = claimsBody.get("id");
//在header中添加新的信息
ServerHttpRequest serverHttpRequest = request.mutate().headers(httpHeaders -> {
httpHeaders.add("userId", userId + "");
}).build();
//重置header
exchange.mutate().request(serverHttpRequest).build();
1.在mvc中获取拦截器:
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new AppTokenInterceptor()).addPathPatterns("/**");
}
}
2.在拦截器中获取线程,把用户信息放入线程当中
public class AppTokenInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String userId = request.getHeader("userId");
if(userId != null){
//存入到当前线程中
ApUser apUser = new ApUser();
apUser.setId(Integer.valueOf(userId));
AppThreadLocalUtil.setUser(apUser);
}
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
AppThreadLocalUtil.clear();
}
}
3.编写线程:
public class AppThreadLocalUtil {
private final static ThreadLocal WM_USER_THREAD_LOCAL = new ThreadLocal<>();
//添加用户
public static void setUser(ApUser apUser){
WM_USER_THREAD_LOCAL.set(apUser);
}
//获取用户
public static ApUser getUser(){
return WM_USER_THREAD_LOCAL.get();
}
//清理用户
public static void clear(){
WM_USER_THREAD_LOCAL.remove();
}
}