Java的一些问题和解决方式

Java专栏
上一篇主目录 下一篇

文章结构

【前言】
本文章系列记录第一次实习中 - - 学习笔记 - - Java的一些问题和解决方式


如何判断Map<String, Object> map中Object是否为""?

    public static void main(String[] args) {
        Map<String,Object> map=new HashMap<>();
        map.put("k","");
        System.out.println("k:"+map.get("k").toString());
        System.out.println(StringUtils.isNotBlank(map.get("k").toString()));
    }
    结果:
    k:
	false

如何读取csv文件,以json格式发送POST请求

public class TestPmml {
    public static void testIntelliProductPoints() {
        System.out.println("-------------指数模型-------------");
        try {
            RestTemplate restTemplate =new RestTemplate();
            BufferedReader reader = new BufferedReader(new FileReader("XXX.csv"));
            reader.readLine();
            String line = "3";
            while((line=reader.readLine())!=null){String[] strArray = line.split(",");
                Map<String, Object> map = new HashMap<String, Object>();

                map.put("key1", strArray[7]);
                map.put("key2", strArray[8]);

                String result = JSONObject.toJSONString(map);
                HttpHeaders headers = new HttpHeaders();
                MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
                headers.setContentType(type);
                headers.add("Accept", MediaType.APPLICATION_JSON_UTF8_VALUE);
                HttpEntity<String> httpEntity = new HttpEntity<>(result, headers);
                ResponseEntity<String> response = restTemplate.postForEntity("服务器地址\请求", httpEntity, String.class);
                if(!response.getStatusCode().equals(HttpStatus.OK)){
                    //throw new Exception();
                }
                System.out.println(strArray[0]+"\tscore:"+strArray[28]+"\tprob:"+response.getBody());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {

        TestPmml.testIntelliProductPoints();
    }

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值