전체 글 172

스프링에서 form submit 으로 가변(멀티) 데이터 받기

form submit으로 정해지지 않은 수의 데이터를 받아야 할 경우가 있다. 간단하게 말하면 화면에서는 같은 name으로 값들을 전달하고 서버에서는 배열로 받는다. 아래와 같은 경우. item1 item2 item3 ...... ...... 화면 체크리스트 항목 체크리스트 항목 체크리스트 항목 서버 @RequestMapping(value = "/checkListRegister", method = RequestMethod.POST) public String checkListRegister(Locale locale, Model mode, CheckList checkList) { log.debug(checkList.toString()); return "/checklist/checkList"; } public..

spring-project 2020.01.10

lombok (롬복) 설치하기.

롬복을 설치해보자. https://projectlombok.org/ 에서 lombok.jar 다운로드 예전에는 java가 path에 잡혀있어서 더블클릭하면 바로 실행. 안잡혀 있다면 CMD 를 실행 한 뒤, java -jar lombok.jar 명령어 입력. (당연히 lombok.jar 다운받은 디렉토리 이동 후 입력) Specify location 선택 후 eclipse or STS 실행 파일 선택 (eclipse.exe or sts.exe) Install / Update 로 설치 eclipse or STS 재시작

spring-project 2020.01.05

spring security 로그인 username 가져오기

첫번째 방법은 SecurityContextHolder를 사용하는 방법 Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String username = authentication.getName(); logger.debug("current username : {}", username); 두번째 방법은 Method 선언에서 Principal 이나 Authentication 에 자동으로 할당 되는 값을 사용하는 방법 @RequestMapping(value = "/list") public String list(Principal principal, ...) { ... } @RequestMapping(valu..

spring-project 2020.01.03

Spring MVC Request 객체는 매번 새로 생성 됨.

스프링 MVC Request 요청이 오면 매번 새로운 객체가 생성 됨. Request 를 2번 요청하여 각각의 객체의 hash값을 보면 다른 걸 확인 할 수 있다. toString() 으로 객체의 hash 값을 보면 다르다. @RequestMapping(value = "/register", method = RequestMethod.POST) public String register(Locale locale, Model model, @ModelAttribute TestRegisterRequest testRegisterRequest) { logger.debug(informationRegisterRequest.toString()); return "redirect:/test/list"; DEBUG 18048 -..

spring-project 2020.01.02

Redis 처음 사용하기

[Homepage] https://redis.io/ [Redis란] open source (BSD licensed) in-memory data structure store (데이터베이스, cache, message broker 처럼 사용), NoSQL 데이터베이스, key-value 저장소라도 함 strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams 데이터 구조 지원 replication, Lua scripting, LRU eviction, transactions and different levels of on-dis..

redis 2019.10.13

Spring Boot 에서 JSP 사용하기 위한 라이브러리 추가

maven (pom.xml) org.apache.tomcat.embed tomcat-embed-jasper javax.servlet jstl gradle (build.gradle) #jsp spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp application.properties 에 다음과 같은 설정 추가 implementation 'org.apache.tomcat.embed:tomcat-embed-jasper' implementation 'javax.servlet:jstl:1.2' /main/webapp/WEB-INF/jsp/ 와 같이 디렉토리 만들고 jsp 파일 생성

spring-project 2019.09.13

Spring Boot 최초 실행 시 'Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. '

Spring Boot 초기 프로젝트를 Initializr를 통해서 생성 한 뒤 최초 실행 할 경우 다음과 같은 오류가 발생하면서 정상적으로 실행이 되지 않을 경우. *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class Action: Consider the following: If you wan..

spring-project 2019.09.10

Spring Security를 이용한 Basic Authentication

Spring Security를 이용한 REST API Basic Authentication Basic Authentication이란? REST API 인증을 할 때, username, password로 인증을 하는 방법을 말한다.username, password를 입력하면 Client에서 username + password를 base64 인코딩을 이용하여 매 request 마다 서버에 전달하면서버에서는 이를 가지고 사용자인지 아닌지 판단 한다. base64 인코딩을 사용하기 때문에 인코딩 된 문자열이 노출이 되면 쉽게 username, password를알수 있다. SpringSecurity를 이용한 구현package com.quickguide.backend.config; import com.quickgu..

spring-project 2019.03.01