inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 MVC 1편 - 백엔드 웹 개발 핵심 기술

http://localhost:8080/request-param-v1

411

사탕

작성한 질문수 13

0

ok는 뜨는대요 

서버에서는 username=김,age=123이 안나와요

spring MVC

답변 5

0

사탕

log.info("username={},age={}",username,age );
답변감사드립니다
setting에서 idea 든 gradle 이든 jdk 11로 바꿔줫는데도 왜 15로 뜨는걸까요?

0

김영한

다음 링크를 참고해주세요^^

https://www.inflearn.com/questions/116973

0

사탕

@Slf4j
@Controller
public class RequestParamController {

@RequestMapping("/request-param-v1")
public void requestParamV1(HttpServletRequest request, HttpServletResponse response) throws IOException {
String username = request.getParameter("username");
int age = Integer.parseInt(request.getParameter("age"));


response.getWriter().write(
"ok");
}

@ResponseBody
@RequestMapping("/request-param-v2")
public String requestParamV2(
@RequestParam("username") String memberName,
@RequestParam("age") int memberAge) {

log.info("username={}, age={}", memberName, memberAge);
return "ok";//@RestController 같은효과
}

}
#전체 로그 레벨 설정(기본 info)
logging.level.root=info
#hello.springmvc 패키지와 그 하위 로그 레벨 설정
logging.level.hello.springmvc=debug

2021-04-24 21:05:34.313 INFO 15380 --- [ main] hello.springmvc.SpringmvcApplication : Starting SpringmvcApplication using Java 15.0.2 on DESKTOP-C6Q38EP with PID 15380 (C:\study\springmvc\springmvc\out\production\classes started by 82109 in C:\study\springmvc\springmvc) 2021-04-24 21:05:34.317 DEBUG 15380 --- [ main] hello.springmvc.SpringmvcApplication : Running with Spring Boot v2.4.5, Spring v5.3.6 2021-04-24 21:05:34.318 INFO 15380 --- [ main] hello.springmvc.SpringmvcApplication : No active profile set, falling back to default profiles: default 2021-04-24 21:05:35.409 INFO 15380 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2021-04-24 21:05:35.421 INFO 15380 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2021-04-24 21:05:35.421 INFO 15380 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.45] 2021-04-24 21:05:35.515 INFO 15380 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2021-04-24 21:05:35.515 INFO 15380 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1132 ms 2021-04-24 21:05:35.915 INFO 15380 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2021-04-24 21:05:36.292 INFO 15380 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html] 2021-04-24 21:05:36.465 WARN 15380 --- [ main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration) 2021-04-24 21:05:36.551 INFO 15380 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2021-04-24 21:05:36.563 INFO 15380 --- [ main] hello.springmvc.SpringmvcApplication : Started SpringmvcApplication in 2.734 seconds (JVM running for 3.135)
2021-04-24 21:06:19.710 INFO 15380 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2021-04-24 21:06:19.710 INFO 15380 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2021-04-24 21:06:19.712 INFO 15380 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms

0

김영한

requestParamV1에 로그 출력 부분이 누락되어 있습니다.

다음 부분을 requestParamV1에도 포함해주세요.

log.info("username={}, age={}", memberName, memberAge);

0

김영한

사탕님 작성하신 컨트롤러의 전체 코드를 보여주세요.

추가로 application.properties도 보여주세요.

서버에 남겨진 전체 로그도 남겨주세요.

0

사탕

네 똑같이 ok만 뜹니다

0

김영한

안녕하세요. 사탕님

다음과 같이 호출해보시겠어요?

http://localhost:8080/request-param-v1?username=hello&age=20

servlet과 container에 대한 질문입니다

0

12

1

api를 어느 컨트롤러에 작성해야하는지는 어떤 기준으로 해야하나요?

0

59

1

jsp 의존성 수정 요청

0

72

2

요즘 웹 서버가 주로 사용되는 이유는 SPA 구조 때문일까요 ?

0

141

1

save() 메서드 문의

0

62

1

절대 경로로 templates/basic 하위 파일 열면 css 적용 안되는 현상

0

98

1

request-body-json

0

83

2

MVC 패턴의 적용 단위

0

92

1

RequestMapping을 이용한 핸들러, 어댑터

0

118

2

save 후 결과화면

0

86

2

jsp를 이용한 view

0

95

1

application.properties에 debug 추가해도 결과가 똑같습니다.

0

170

1

수업 코드 제공 관련 문의

0

95

2

RequestMappingHandlerAdapter의 Controller 호출 과정

0

96

3

파일 오픈 시

0

66

1

스프링 배치 관련

0

74

1

@RequestParam의 defaultValue가 blank 값도 처리하는 지 여부

0

110

1

postman으로 /request-body-json-v1 호출시 500 error

0

93

1

프론트엔드와 백엔드의 mvc, rest api에 대한 질문

0

74

1

모델의 역할과 계층 분리에 대한 이해 차이 + 추가질문

0

110

1

console log 출력 관련 질문입니다.

0

73

1

애플리케이션이 실행 되지 않습니다 ㅠㅠㅠ

0

135

1

html 변경하는 부분 적용 문제

0

98

1

한글 깨짐

0

72

2