mysql查询一列逗号分隔
select id from bg_cust_info where for_short="金马衡器";
select GROUP_CONCAT(id) as ids from bg_cust_info where for_short="金马衡器";
map根据value进行排序
Stream<Map.Entry<String, Long>> sorted = nameToNum.entrySet().stream().sorted((a, b) -> (int) (a.getValue() - b.getValue()))
接着map转为list
假设map有5个属性,转为list,包含5个map,每个map包含一个属性
//在上面sorted的基础上:
List<Map.Entry<String, Long>> collect= sorted.collect(Collectors.toList())
Java百分比计算
public static String percentCalculate(long num1, long num2) {
//创建一个数值格式化对象
java.text.NumberFormat numberformat = java.text.NumberFormat.getInstance();
//设置精确到小数点后2位
numberformat.setMaximumFractionDigits(2);
java.text.DecimalFormat df = new java.text.DecimalFormat("##.##%");//传入格式模板
return df.format((float) num1 / (float) num2);
}
private String percentDivide(BigDecimal divisor, BigDecimal sum) {
//求比例 相除
BigDecimal divide = divisor.divide(sum, 4, RoundingMode.HALF_UP);
//将结果装换未百分比
NumberFormat percent = NumberFormat.getPercentInstance();
percent.setMaximumFractionDigits(2);
return percent.format(divide.doubleValue());
}
rest请求接收参数
方式1
@PostMapping("/a")
JsonResponse<Object> suppliesReservesByArea(String areaCode,String name);
POST http://localhost:8066/phe-api/v2/event/materials/suppliesReservesByArea?areaCode=62100000000&name=123
方式2
@PostMapping("/a/{areaCode}")
JsonResponse<Map<String,Object>> materialTypeByArea(@PathVariable("areaCode") @NotBlank String areaCode);
POST http://localhost:8066/phe-api/v2/event/materials/MaterialTypeByArea/62100000000
方式3
@PostMapping("/a")
JsonResponse<Map<String, Object>> getMaterialsByTag(@RequestBody @Validated MaterialQuantityStatisticsVo vo);
POST http://localhost/phe-api/v2/event/materials/countMaterialsByTags
{
"a":"b"
}