프로젝트를 시작하면서 application.xml 설정을 해주는데

 

<beans xmlns="http://www.springframework.org/schema/beans"

 

xmlns:aop="http://www.springframework.org/schema/aop"

 

xmlns:context="http://www.springframework.org/schema/context"

 

xmlns:security="http://www.springframework.org/schema/security"

 

xmlns:tx="http://www.springframework.org/schema/tx"

 

xsi:schemaLocation="

 

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

 

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

 

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

 

http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd

 

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"

 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

 

xsi:schemaLocation 에서 Downloading external resources is disabled. 오류가 발생했다

 

 

첫번째로 검색했던 블로그에서는  <beans xmlns:beans:   <beans xmlns: 로 고치면 된다고 했는데

난 이미 <beans xmlns: 로 작성했었다.

 

그래서 난 반대로 <beans xmlns: 뒤에 <beans xmlns:beans: 으로 수정해 줬더니 해당 오류는 사라졌지만

아래와 같은 새로운 오류가 발생했다.

 

cvc-elt.1.a: cannot find the declaration of element 'beans'.

 

처음에는 버전을 안적어줘서 그런가 해서 버전을 적어줘도 오류는 똑같았다

 

그래서 두번째로 수정했던 부분을 지웠다. 잘못 수정했다는 생각이 들어 다른 해결방안을 찾았다

 

다시 첫번째 오류에 집중하였는데 소스 다운에 문제 있다고 하니

 

Preferences -> Maven -> Download Artifact JavaDoc 체크를 해주었다.

 

체크해주니 정상 작동하였다.

 

 

아래 링크를 참고하였다

https://stackoverflow.com/questions/77252112/downloading-from-external-resources-is-disabled-in-hibernate-dtd

 

Downloading from external resources is disabled in hibernate dtd

While I am trying to do hibernate configuration I put hibernate dtd in hibernate.cfg.xml file and it is showing an error that downloading from external resources is disabled. Can you please help me...

stackoverflow.com

 

 

 

 

[오류]

이클립스에서 프로젝트를 maven Update project 하니깐 pom.xml에서 아래와 같은 오류가 발생하였다

cvc-elt.1.a:Cannot find the declaration of element 'project'

 

[오류해결]

xsi:schemaLocation 부분에서 https를 http로 수정하니 에러 사라짐

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>spring4</groupId>
  <artifactId>testProject01</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  
</project>

수정 전

 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>spring4</groupId>
  <artifactId>testProject01</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  
</project>

수정 후

@RequestParam란?

  • 스프링에서 제공하는 HTTP 요청 파라미터 값을 편리하게 사용하게 해주는 어노테이션
  • 파라미터 이름으로 바인딩하는 방법
  • HttpServletRequest의 request.getparameter의 기능과 동일

 

@RequestParam 속성

name

파라미터 이름을 지정하는 것으로 다른 속성이 없을 경우 "name = " 생략 가능

@RequestParam("itemId") Long itemId
@RequestParam(name = "itemId") Long itemId

 

 

required

파라미터의 필수 여부 결정

기본값으로 필수(true)

required가 true 일 경우 해당 파리미터가 없으면 HTTP 상태코드 400반환,

false일 경우 해당 파라미터가 없어도 예외 발생 X

@RequestParam(name = "itemId", required = true) Long itemId
@RequestParam(name = "itemId", required = false) Long itemId

 

주의할점

파라미터의 이름만 있고 값이 없는 경우 (null과 다름) 빈문자로 취급하여 예외 발생 X

 

 

defalutValue

파라미터에 값이 없을 경우 defalutValue 속성을 사용하여 기본값 적용

이경우 기본 값이 설정되기 때문에 required와 함께 사용하면 required 의미가 없음

 

 

@RequestParam 사용법

@PostMapping("/order")
public String order(@RequestParam("memberId") Long memberId,
                    @RequestParam("itemId") Long itemId,
                    @RequestParam("count") int count){

    orderService.order(memberId, itemId, count);
    return "redirect:/orders";
}

 - Http 요청 파라미터의 이름으로 바인딩하여 그 값을 변수에 저장

 

<form role="form" action="/order" method="post">
    <div class="form-group">
        <label for="member">주문회원</label>
        <select name="memberId" id="member" class="form-control">
            <option value="">회원선택</option>
            <option th:each="member : ${members}"
                    th:value="${member.id}"
                    th:text="${member.name}" />
        </select>
    </div>
</form>
  • html에서 name으로 받아온다

 

@PostMapping("/order")
public String order(@RequestParam Long memberId,
                    @RequestParam Long itemId,
                    @RequestParam int count){

    orderService.order(memberId, itemId, count);
    return "redirect:/orders";
}

 * HTTP파라미터 이름이 변수랑 동일할 경우 4 @RequestParam의 value 값 생략 가능

 

@PostMapping("/order")
public String order(Long memberId,
                    Long itemId,
                    int count){

    orderService.order(memberId, itemId, count);
    return "redirect:/orders";
}

 * String, int, Integer 등 단순 타입일 경우 @RequestParam 생략 가능

+ Recent posts