일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- IntelliJ
- iBatis
- 티스토리챌린지
- 자바
- mysql
- MariaDB
- PostgreSQL
- java
- Javascript
- SQL
- 네트워크
- zset
- DBMS
- Linux
- network
- 명령어
- github
- mssql
- pandas
- Python
- error
- 쉘스크립트
- oracle
- 리눅스
- codeium
- 오블완
- git
- Kibana
- spring
- docker
- Today
- Total
목록JAVA (54)
hanker
Java 에서 Json 문자열로 데이터를 받을 때 다시 Json 형태로 Parsing 해서 사용 하는 코드 Gson 라이브러리 사용하여 파싱 pom.xml com.google.code.gson gson 2.8.1 받은 Json 문자열을 Parsing Gson gson = new Gson(); List listMap = gson.fromJson((String) params.get("listMap"), new TypeToken(){}.getType()); // Map 형식의 params 파라미터를 받음 // params 안에 key name이 listMap 이라는 Json 문자열을 List 형식으로 Parsing // List 형식이 아닌 List -- 등 위 코드 수정하여 사용 가능
Date date = new Date(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); String nowDate = simpleDateFormat.format(date); LocalDate localDate = LocalDate.parse(nowDate); LocalDate firstDate = localDate.withDayOfMonth(1); // 해당월의 마지막 날짜 LocalDate lastDate = localDate.withDayOfMonth(localDate.lengthOfMonth());
Client 아이피 가져오기 import java.net.Inet4Address; ... String ip = Inet4Address.getLocalHost().getHostAddress();
LocalDate Class 안에 plusMonths() 메서드 * 날짜범위를 벗어난 경우 DateTimeException 발생 LocalDate date = LocalDate.of(2023, 1, 1); LocalDate mon = date.plusMonths(1); 결과 : mon = 2023-02-01 LocalDate mon = date.plusMonths(2); 결과 : mon = 2023-03-01 LocalDate mon = date.plusMonths(3); 결과 : mon = 2023-04-01 LocalDate mon = date.plusMonths(4); 결과 : mon = 2023-05-01

beforeDate - 이전 날짜 nowDate - 현재 날짜 public void monthValue(LocalDateTime beforeDate, LocalDateTime nowDate) { int monthA = beforeDate.getYear() * 12 + beforeDate.getMonthValue(); int monthB = nowDate.getYear() * 12 + nowDate.getMonthValue(); return monthB - monthA; }
메소드 또는 변수를 구현(implements)하는가 그대로 사용(extends)하는가에 따라서 형태가 갈린다. extends(상속) 상속의 대표적인 형태 부모의 메소드를 그대로 사용 오버라이딩(재정의)할 필요 없이 부모에 구현되있는 것을 직접 사용 가능 JAVA는 다중상속을 지원하지 않는다. 그래서 implements를 사용(상속이라고 말한 순 없지만..) implements (상속) 부모의 메소드를 반드시 오버라이딩(재정의)해야 함 다중상속을 대신해준다.

toString Object 클래스가 가진 메소드 객체가 가지고 있는 정보나 값들을 문자열로 만들어 리턴하는 메소드 Spring boot VO(DTO)클래스에서 사용하는 toString 메소드는 Object클래스에 있는 toString() 메소드를 오버라이딩하여 사용(재정의) toString 사용 및 재정의 한번 실행해보자 뭔가 출력되긴 했지만 무슨 값인지 확인이 안된다. 이때 재정의를 해서 사용한다. Favorite.java에서 toString() 메서드 추가 결과
import org.json.JSONException; import org.json.JSONObject; import java.io.*; import java.net.URL; import java.nio.charset.Charset; public class JsonParseTest { public static void main(String ar[]) throws Exception{ String url = "Json Data를 가져올 URL"; JSONObject json = readJsonFromUrl(url); System.out.println(json.toString()); } private static String jsonReadAll(Reader reader) throws IOException{ ..
String to Date (String → Date) String에서 Date로 형변환 SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date to = transFormat.parse("Date로 변환할 String Data"); Date to String (Date → String) Date에서 String으로 형변환 SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String to = transFormat.format("String으로 변환할 Date data");
pom.xml에 org.json 을 추가한다. org.json json 20180130 json 추가가 완료되면 테스트 코드를 작성한다. import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import org.apache.commons.io.IOUtils; import org.json.JSONObject; import org.json.XML; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; public class xmltoJson { public static vo..