Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/main/java/com/example/bcsd/HelloController.java

This file was deleted.

52 changes: 52 additions & 0 deletions src/main/java/com/example/demo/ArticleController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.example.demo;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.DeleteMapping;

import org.springframework.web.bind.annotation.GetMapping;

@RestController
public class ArticleController {
@PostMapping("/article")
public ResponseEntity<Void> createArticle(@RequestBody ArticleDto dto) {
System.out.println("클라이언트가 보낸 description: " + dto.getDescription());
return ResponseEntity.status(HttpStatus.CREATED).build();
}
@PutMapping("/article/{id}")
public ResponseEntity<Void> updateArticle(
@PathVariable("id") Long id, // URL의 {id} 값을 id 변수에 저장
@RequestBody ArticleDto dto) // Body의 JSON을 dto 변수에 저장
{
System.out.println("--- PUT /article/" + id + " ---");
System.out.println("수정할 대상 ID: " + id);
System.out.println("새로 받은 description: " + dto.getDescription());

return ResponseEntity.ok().build();
}
@DeleteMapping("/article/{id}")
public ResponseEntity<Void> deleteArticle(@PathVariable("id") Long id) {

System.out.println("--- DELETE /article/" + id + " ---");
System.out.println("삭제할 대상 ID: " + id);

// (실제로는 id를 사용해 DB에서 데이터를 찾아 삭제합니다)

// 204 No Content 응답 반환
return ResponseEntity.noContent().build();
}
@GetMapping("/article/{id}")
public ResponseEntity<ArticleDto> getArticle(@PathVariable("id") Long id) {
System.out.println("--- GET /article/" + id + " ---");

return ResponseEntity.notFound().build();

}
}
13 changes: 13 additions & 0 deletions src/main/java/com/example/demo/ArticleDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.demo;

public class ArticleDto {
private String description;
public ArticleDto() {
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.example.bcsd;
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class BcsdApplication {
public class DemoApplication {

public static void main(String[] args) {
SpringApplication.run(BcsdApplication.class, args);
SpringApplication.run(DemoApplication.class, args);
}

}
45 changes: 45 additions & 0 deletions src/main/java/com/example/demo/HelloController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;

@Controller
public class HelloController {

@GetMapping("/hello")
public String hello() {
return "안녕하세요 박준서입니다.";
}

@GetMapping("/introduce")
public String hello2(@RequestParam("name") String name, Model model) {
model.addAttribute("name", name);
return "introduce";
}

@GetMapping("/json")
@ResponseBody
public jsonc getJsonDate(){
return new jsonc(26, "허준기");
}

public static class jsonc{
private int age;
private String name;

public jsonc(int age, String name){
this.age=age;
this.name=name;
}
public int getAge(){
return age;
}
public String getName(){
return name;
}
}

}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.application.name=demo
9 changes: 0 additions & 9 deletions src/main/resources/templates/hello.html

This file was deleted.

10 changes: 10 additions & 0 deletions src/main/resources/templates/introduce.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p th:text="|안녕하세요 제 이름은 ${name}입니다!|"></p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.example.bcsd;
package com.example.demo;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class BcsdApplicationTests {
class DemoApplicationTests {

@Test
void contextLoads() {
Expand Down