@songhanshi
2020-10-19T12:51:16.000000Z
字数 4369
阅读 556
Java小工具
List<Map<String,String>> B
= A.entrySet().stream().map(m->{
Map<String,String> u = new Map<String,String>();
u.setKey(m.getKey());
u.setTitle(m.getValue());
return u;
}).collect(Collectors.toList());
Map<String, List<String>> parameters;
Map<String, String[]> collect = parameters.entrySet().stream()
.collect(Collectors.toMap(entry-> entry.getKey(),entry -> entry.getValue().toArray()));
空
str.isEmpty()
不为空
StringUtils.isNotBlank(str)
if(list == null || list.size() ==0 ){
//为空的情况
}else{
//不为空的情况
}
if(list!=null && !list.isEmpty()){
//不为空的情况
}else{
//为空的情况
}
public static boolean isIntegerForDouble(double obj) {
double eps = 1e-10; // 精度范围
return obj-Math.floor(obj) < eps;
}
private static boolean doubleAccuracy(String str, int doubleSize) {
try {
double num = Double.valueOf(str);//把字符串强制转换为数字
if (str.trim().contains(".")) {
int currentPlace = str.trim().length() - str.trim().indexOf(".") - 1;
return currentPlace < doubleSize;
}
return true;
} catch (Exception e) {
return false;//如果抛出异常,返回False
}
}
// 获取前30分钟日期
Calendar calendar = Calendar.getInstance();
Date late = calendar.getTime();
calendar.add(Calendar.MINUTE, -30);
Date early = calendar.getTime();
query.setStartTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(early));
query.setEndTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(late));
String end = "2020-06-27";
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss " );
Date endTime = simpleDateFormat.parse(end);
注:例如MM是月份,mm是分;HH是24小时制,而hh是12小时制。
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str = format.format(date);
Date endDate = DateUtil.parseDate(endStr);
Date startDate = DateUtil.parseDate(startStr);
if (DateUtil.compare(endDate, startDate) < 0) {
return stringBuilder.append("结束时间不能早于开始时间").toString();
}
Date now = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(now);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
Date now2= calendar.getTime();
System.out.println(now2);
File file = new File("F:/hejing/InstrumentJsonData.txt");
if(file.isFile() && file.exists()) {
...
}
public static void main(String[] args) throws Exception {
// File file = new File("F:/hejing/InstrumentJsonData.txt");
String strUrl = "F:/hejing/InstrumentJsonData.txt";
File file = new File(strUrl);
InputStream inputStream = new FileInputStream(file);
MultipartFile multipartFile = new MockMultipartFile(file.getName(), inputStream);
log.info("file转multipartFile成功. {}",multipartFile);
}
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(inputStream);
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
int rowSize = xssfSheet.getLastRowNum();
CommonsMultipartFile cmf = (CommonsMultipartFile)file;
DiskFileItem dfi = (DiskFileItem)cmf.getFileItem();
File f = dfi.getStoreLocation();
CommonsMultipartFile commonsMultipartFile = (CommonsMultipartFile)file;
DiskFileItem fileItem = (DiskFileItem)commonsMultipartFile.getFileItem();
InputStream fileInputStream = fileItem.getInputStream();
配置路径 yml
dataplatform:
filePath: D:\file\
创建config类
@Configuration(value = "filePathConfig")
@ConfigurationProperties(prefix = "dataplatform")
@Data
public class FilePathConfig {
public static final String SEPARATOR;
static {
SEPARATOR = FileUtil.isWindows() ? "\\" : "/";
}
String filePath;
}
读
["1","2","3"]
public String save(@Param("switch")boolean switch1,String slider,String input,String redio,String checkbox){
JSONArray obj = JSON.parseArray(checkbox);
sout(JSON.parseArray(checkbox).size());
fori(){
obj.get(i);
}
}
curl -X POST 'http://localhost:8080/formPost' -d 'id=1&name=foo&mobile=13612345678'
curl -X POST -H "Content-Type: application/json" 'http://localhost:8080/jsonPost' -d '{"id":2,"name":"foo","mobile":"13656635451"}'
https://blog.csdn.net/weixin_34400525/article/details/86254617