본문 바로가기
728x90
반응형

Spring31

[Spring] JSONArray를 사용하지 않고 Ajax로 배열 list 넘기기 ajax로 배열 데이터를 넘기는 방법을 알아보겠습니다. 구글링을 해보면 대부분의 포스트가 배열을 파싱 하는 방법으로 JSONArray와 JSONObject를 이용하고 있는데, 다른 방법을 알려드리겠습니다. 아래와 같은 데이터를 Controller로 넘기려고 합니다. const data = { "id": 10, "typeList": [ {"type":"A", "typeNm":"에이"}, {"type":"B", "typeNm":"비"} ] }; 해당 데이터를 json dataType로 보내면, 아래와 같은 오류가 발생합니다. Property referenced in indexed property path 'typeList[0][type]' is neither an array nor a List nor a M.. 2021. 1. 6.
[Spring] java/jsp에서 properties value 불러오기 아래와 같은 common.properties 파일이 존재할 때 java와 jsp에서 값을 불러오는 방법을 알아보겠습니다. system.domain=http://localhost:8080 hello.world=hello world!! 1. java Application.java에 properties 파일을 설정하면, @PropertySource({ "classpath:properties/common.properties" }) public class Application { ... } @Value 어노테이션을 사용하여 properties값을 불러올 수 있습니다. import org.springframework.beans.factory.annotation.Value; @Cotroller public class.. 2021. 1. 5.
[Spring] local cache key, value 조회 및 삭제 @Cacheable 어노테이션을 사용하여 생성한 로컬 캐시 (ehCache)를 조회하고 삭제하는 방법을 알아보겠습니다. import org.springframework.cache.CacheManager; @Resource private CacheManager cacheManager; 1. Key, Value 정보 조회 1. ehcache public ResponseEntity ehCacheValues() { List result = new ArrayList(); for (String cacheName : cacheManager.getCacheNames()) { EhCacheCache cache = (EhCacheCache) cacheManager.getCache(cacheName); Ehcache ehc.. 2020. 12. 4.
[SpringBoot2] java config로 hikari datasource, transaction aop 설정 pom.xml org.springframework.boot spring-boot-starter-jdbc org.mybatis.spring.boot mybatis-spring-boot-starter 2.1.3 org.apache.commons commons-dbcp2 mysql mysql-connector-java runtime  application.ymlspring: datasource: h.. 2020. 11. 1.
[Spring] Chrome 양식 다시 제출 확인 ERR_CACHE_MISS 해결방법 Chrome에서 POST 요청으로 페이지 이동후 뒤로 가기를 하면 아래와 같은 확인 페이지를 제공하도록 되어있습니다. ​ ​ ​Spring security를 사용하면 headers cacheControl를 disabled 처리함으로써 해결합니다. @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) { http // ... .headers(headers -> headers .cacheControl(cache -> cache.disable()) ); } } Cache Control.. 2020. 10. 31.
[Spring] Mockmvc에 ExceptionHandler 등록 Controller Test 를 위해 MockMvc 기반으로 Test를 할 때, @ControllerAdvice 로 지정한 Global Exception Handler가 Test에서 동작하지 않을 때가 있습니다. ​ Mockmvc를 생성할때 아래와 같이 setControllerAdvice()로 사용할 class를 지정해주어야 합니다. ​ Normally @ControllerAdvice are auto-detected as long as they're declared as Spring beans. However since the standalone setup does not load any Spring config, they need to be registered explicitly here instead.. 2020. 10. 31.
[Spring Security5] Multiple HttpSecurity, Multiple Login, accessDenied 설정 한 프로젝트에 여러 개 서비스가 있을 경우, 로그인 화면이 두 개 이상인 경우 다음과 같이 구성합니다.​MultipleSecurityConfiguration.java (<a href="https://docs.spring.io/spring-security/site/docs/4.1.5... 2020. 10. 31.
[SpringBoot] Jackson JsonAlias 설정 및 x-www-form-urlencoded 문제 해결 JsonAlias를 사용하기위해 pom.xml에 Jackson lib를 추가합니다. org.springframework.boot spring-boot-starter-web com.fasterxml.jackson.core jackson-databind com.fasterxml.jackson.core jackson-annotations 2.9.9 com.fasterxml.jackson.core jackson-databind 2.9.9 com.fasterxml.jackson.core jackson-core 2.9.9 @JsonAlias 사용법 @Data public class UserVO { @JsonAlias(value = {"name", "userNm", "userName"} private String n.. 2020. 10. 31.
[spring] @ResponseBody Annotation vs ResponseEntity @ResponseBody annotation을 사용하면 스프링이 반환 객체를 http response body로 변환합니다. ResponseEntity는 @ResponseBody annotation과 유사하게 작동합니다. 그러나 ResponseEntity 객체를 생성할 때 response header를 http response에 추가할 수도 있습니다. responseEntity를 반환 객체로 사용하는 경우 @ResponseBody annotation을 사용할 필요가 없습니다. 예제) @ResponseBody annotation 사용 @ResponseBody @RequestMapping("/getData") public ResJsonVO getData(DataVO param) { try { return t.. 2020. 10. 31.
[spring security5] URL 더블슬래시 허용 - The request was rejected because the URL was not normalized. Spring security의 기본정책은 URL에 더블 슬래시가 들어가는 것을 허용하지 않습니다. 예를 들어 https://moonsiri.tistory.com/category와 같은 URL을 사용할 때, URL 더블 슬래시 처리가 안되어있는 상태에서 https://moonsiri.tistory.com//category로 요청이 들어오면 에러가 발생합니다.org.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the URL was not normalized. at org.springframework.security.web.firewall.StrictHttpFirewall.getFi.. 2020. 10. 14.
728x90
반응형