본문 바로가기

개발&프로그래밍104

[Kotlin] 코틀린 클래스와 프로퍼티 코틀린에서의 클래스와 프로퍼티에 대해 알아봅니다. 코틀린 클래스(Class) 자바에서 아래와 같은 Person 클래스를 public class Person { private final String name; public Person(String name) { this.name = name; } public String getName() { return name; } } 코틀린 코드로 바꿔보면? 단! 한줄로 가능합니다. class Person(val name: String) 코틀린에서는 명시하지 않아도 기본적으로 public 접근제한자여서 생략이 가능합니다. 코틀린 프로퍼티(Property) 요즘 나온 언어들과 같이 프로퍼티에 읽기 전용과 변경 가능한 프로퍼티가 있습니다. val : 읽기 전용 프로퍼티 v.. 2022. 3. 15.
[Spring] @SpringBootApplication 어노테이션 @SpringBootApplication은 아래 어노테이션을 추가한 편의성 어노테이션입니다. @Configuration 애플리케이션 컨텍스트에 대한 빈 정의 소스로 클래스에 태그를 지정합니다. @EnableAutoConfiguration Spring Boot에 클래스 경로 설정, 기타 Bean들과 다양한 property 설정을 기반으로 bean을 추가하도록 한다. 예를 들어 spring-webmvc가 클래스 경로에 있는 경우 이 어노테이션은 애플리케이션에 웹 애플리케이션으로 플래그를 지정하고 DispatcherServlet 설정과 같은 주요 동작을 활성화합니다. @ComponentScan Spring이 예를들어 com/example/demo 패키지에서 선언된 components, configuration.. 2022. 3. 15.
[Spring] 스프링 웹 어노테이션 (Spring Web Annotation) Spring에서의 Spring Web 어노테이션을 이용하여 RESTful 웹 서비스를 만들어보자. http://localhost:8080/greeting API GET 요청으로 아래의 JSON 응답을 받는 API를 작성해보자. {"id":1,"content":"Hello, World!"} 먼저 greeting 모델 클래스를 만들자. package com.example.demo; public class Greeting { private final long id; private final String content; public Greeting(long id, String content) { this.id = id; this.content = content; } public long getId() { ret.. 2022. 3. 15.
[Spring] @Controller 과 @RestController 어노테이션 Spring MVC에서 @Controller와 @RestController 어노테이션의 차이점에 대해 알아봅니다. @RestController 어노테이션은 Spring 4.0 에서 새롭게 추가가 되었습니다. 기존의 @Controller와 @ResponseBody를 결합한 어노테이션으로 모든 요청 처리에 대해 @ResponseBody를 추가할 필요가 없습니다. @Controller을 사용 package com.example.demo; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; @Controller @RequestMapping("users") public class User.. 2022. 3. 14.