728x90 반응형 Study364 Java에서 날짜 빼기 이 기사에서는 Java에서 두 날짜를 빼거나 두 날짜 간의 차이를 얻는 방법을 설명합니다. java.util.Date를 사용하여 Java에서 두 개의 날짜를 뺍니다 java.text.SimpleDateFormat 클래스는 지정된 패턴에 따라 날짜를 형식화하고 구문 분석하는 데 사용됩니다. 두 날짜 간의 시간 차이의 절대 값을 밀리 초 단위로 계산합니다. TimeUnit 클래스의convert()메서드는 시간 기간과 기간 단위 인 두 개의 매개 변수를받습니다. TimeUnit 객체time을 만들고convert()메서드를 사용하여 밀리 초를 일로 변환합니다. import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; im.. 2022. 3. 15. Spring Data JPA에서 Query를 사용하는 방법 Spring JPA Data Doc에서는? https://docs.spring.io/spring-data/jpa/docs/2.3.3.RELEASE/reference/html/#jpa.repositories Spring Data JPA - Reference Documentation Example 108. Using @Transactional at query methods @Transactional(readOnly = true) public interface UserRepository extends JpaRepository { List findByLastname(String lastname); @Modifying @Transactional @Query("delete from User u where u.act.. 2022. 3. 15. [java indexOf]배열에서 특정값의 인덱스 구하기 indexOf : 자료구조에서 특정 문자의 인덱스를 찾기 위해 사용된다. 자바에서는 배열에서는 indexOf()를 지원하지 않고 ArrayList자료구조에서만 지원하므로 asList()를 통해 변환시켜 인덱스를 구해야 한다. import java.util.Arrays; public class IndexOfTest { public static void main(String[] args) { String[] arr = {"a","b","c"}; System.out.println(Arrays.asList(arr).indexOf("b")); //1이 출력된다. } 출처 : https://technote-mezza.tistory.com/99 2022. 3. 14. [JPA] Executing an update/delete query Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query @Modifying @Query(value = "delete from tb_specimen where registry_id=:registryId", nativeQuery=true) void deleteBySpecimen(@Param("registryId")Long registryId); } 실행 시 문제가 발생한다. UPDATE, DELETE 경우 @Transactional 어 로테이션을 추가해주지 않으면 문제가 발생하기 때문에 아래와 같이 추가해주어야 한다. @.. 2022. 3. 13. 이전 1 ··· 44 45 46 47 48 49 50 ··· 91 다음 728x90 반응형