Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

16.2. 获取IP地址何机器名

改变java.io.tmpdir的默认值

		
    @GetMapping("/host")
    public ResponseEntity<String> host() {
        try {
            InetAddress addr = InetAddress.getLocalHost();
            String hostAddress = addr.getHostAddress().toString();
            String hostName = addr.getHostName().toString();
            String tmp = String.format("%s: %s", hostAddress, hostName);
            return ResponseEntity.ok(tmp);
        } catch (Exception e) {
            return ResponseEntity.ok(e.toString());
        }
    }