목록Web/SpringBoot (15)
blog
local은 Windows고, 실제 웹 프로젝트가 구동 될 서버는 linux이다. 경로의 경우에는 application.properties에 작성하여 간단하게 바꿔서 사용중이지만, ex) resource.filepath=C:\\workspaces\\ application.properties @Value("${resource.filepath}") private String myFilepath; java 코드 내부에서 파일 경로를 생성 할 때 바꿔주기 귀찮다. File.separator를 사용하면 OS에 따른 경로 구분자를 자동으로 바꿔준다. 윈도우 환경에서 구동한다면 \로 구분자를 리턴하고, 리눅스나 macOS환경에서는 /로 구분자를 리턴한다.
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 32 33 34 35 36 37 String cmd[] = new String[] {"나의", "커맨드", "명령어"}; ProcessBuilder builder = new ProcessBuilder(cmd); try { Process process = builder.start(); int exitVal = process.waitFor(); // wait for end of child process System.out.println("\nExited with error code : " + exitVal); if (exitVal != 0) { System.o..
@Query(value = "SELECT name FROM myDB where id in (:id)", nativeQuery = true) public List selectNameWithID(@Param(value = "id") List id); Interface List NameList = MytRepo.selectNameWithPno(IdList); 이렇게 상용하면 된다.
JSONArray[JSONObject{id, value}, JSONObject{id, value} .. ] StringBuilder으로 JSONObject의 value를 만들어 넣고, JSONArray로 묶어 보내는 API를 만들었더니 AJAX 통신에 실패했다. jsonviewer로 확인했더니 해당 결과값이 JSON vaule가 아니라는 문구가 나왔다. 보내준 값을 확인하니 { "id": 128, "value": Jamse (male) } 이런 형식 자세히 보면 value값이 "String"이 아니다. JSONArray resultArray = new JSONArray(); JSONObject resultObj = new JSONObject(); StringBuilder value = new String..
기본 select를 제외하고 실제 쿼리문으로 쿼리를 하려고한다. 1 2 3 @Query(value = "SELECT * FROM MEMBER mem WHERE mem.age = (:age) AND mem.office = (:office)", nativeQuery = true) public List selectByAgeOffice(@Param(value = "age")int age, @Param(value = "office")String office); Colored by Color Scripter cs memberRepository.java에 추가 1 2 3 4 5 @GetMapping("select") public List selectByAgeOffice() { return memberrepo.sele..
Table명을 대문자로 지정하였는데, @Table에서 대문자로 지정해줬음에도 불구하고 해당 테이블을 찾지 못하고 새로 테이블을 만든다. (create table은 spring.jpa.hibernate.ddl-auto=update 설정을 해주었기 때문) 찾아보니 Hibernate의 네이밍전략때문에 그렇다. https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.data-access.configure-hibernate-naming-strategy 기본적 Spring Boot 물리적 명명 전략은 CamelCaseToUnderscoresNamingStrategy 이다. 1. 점(.) -> 언더바 2. 카멜케이스 -> 언더바 ..