- 浏览: 185752 次
- 性别:
- 来自: 北京
最新评论
文章列表
private static int failureCount = 0;
private static final int MAX_FAILURES = 3;
private static final int DELAY_BETWEEN_FAILURES = 5000; // 3 seconds
@ApiOperation(value="TestRunnable")
@GetMapping(value = "/TestRunnable")
public Result TestRunnable () {
...
1,定义接口
public SseEmitter get(@RequestBody DTO dto){
return SseEmitter Service.getSseEmitter(dto);
}
2,实现ObjectMapper mapper = new ObjectMapper();
String params = mapper.writeValueAsString(Object参数);
EventSourceListener listener = new EventSourceListener() {
@Override
public void on ...
1,准备工作需要小程序appid和secret
2,在controller定义一个方法
@ApiOperation(value = "通过code登录")
@GetMapping("/getTokenByCode")
public R getTokenByCode(@RequestParam(value = "code") String code) {
return loginService.getTokenByCode(code);
}
3,接口 R getTokenByCode(String code);
4,接口实现类 ...
1,date转 LocalDateTime
Date date = new Date();
// 将 Date 对象转化为 LocalDateTime 对象
LocalDateTime localDateTime = DateUtil.toLocalDateTime(date);
2,LocalDateTime转date
Date date = DateUtil.date(localDateTime);
3,string 转date
String dateStr = "2017-03-01";
Date d ...
1,date转 LocalDateTime
Date date = new Date();
// 将 Date 对象转化为 LocalDateTime 对象
LocalDateTime localDateTime = DateUtil.toLocalDateTime(date);
2,LocalDateTime转date
Date date = DateUtil.date(localDateTime);
3,string 转date
String dateStr = "2017-03-01";
Date d ...
需要引入hutool----工具类
public static String dayOfWeek(Date date) {
int day = DateUtil.dayOfWeek(date);
switch (day) {
case 1:
return "星期天";
case 2:
return "星期一";
case 3:
return " ...
package com.xxx;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import java.text.DecimalFormat;
import ...
package com.utils;
import java.math.BigDecimal;
import java.util.Random;
public class RandomUtil {
private static final String SYMBOLS = "0123456789"; // 数字
private static final String SYMBOLS_STR = "0123456789abcdefghijklmnopqrstuvwxyz";
/*
* @Description: 获取 ...
SELECT
*
FROM
demo
WHERE
DATEDIFF(
CAST(
CONCAT(
YEAR ('2023-12-27'),
DATE_FORMAT(birthday, '-%m-%d')
) AS DATE
),
CAST(
DATE_FORMAT('2023-12-27', '%y-%m-%d') AS DATE
)
) BETWEEN 0
AND 10
OR
DATEDIFF(
CAST(
CONCAT(
YEAR ('2023-12-27') + 1,
DATE_FORMAT(birthday, ...
boot数据校验,全局异常
- 博客分类:
- 数据校验,全局异常
package com.exception;
import com.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.validation.BindException;
import org.springframework.validati ...
SELECT
*,
DAYOFYEAR(now())+7,
DAYOFYEAR(birthday)
FROM
demo
WHERE
birthday >= DATE_FORMAT('2023-08-10', '%Y-%m-%d')
and
birthday <= DATE_FORMAT(
date_add('2023-08-10', INTERVAL 7 DAY),
'%Y-%m-%d'
)
or DAYOFYEAR(birthday) + 7 >= ...
public static void main(String[] args) {
List<Test >testList = new ArrayList<>();
Test test= new Test ();
test.setId(1);
test.setCode("aasdf");
testList.add(test);
Test test2= new Test ();
test2.setId(2);
test2.setCode("aasd ...
package com.common;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author zys
* @date 2023/08/2 14:12
*/
@Data
public class Demo {
private String name;
private int age;
public static List<Demo> getDemo1() {
...
package com.test.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHand ...
使用 ClassLoader.getResourceAsStream() 方法
可以使用类加载器来获取资源文件的输入流。该方法接受一个资源文件路径参数,返回一个 InputStream 对象。
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("file.txt");
注意,该方法返回的资源文件路径是相对于类加载器的根路径。因此,对于 resources 目录下的文件,需要在文件名前加上 "classpath:" 前缀。例如: "classpath ...