본문 바로가기

Java

#029 게시물 수정 기능 구현 코드

private void modify(int inputedId, String title, String body) {
		Article article = getArticle(inputedId);
		article.title = title;
		article.body = body;
	}

else if (command.startsWith("article modify")) {
				String[] commandBits = command.split(" ");
				System.out.println("*  게시글 수정  *");

				if (commandBits.length <= 2) {
					System.out.println("수정하고 싶은 게시물 번호와 함께 입력해 주세요.");
					continue;
				}

				int inputedId = Integer.parseInt(commandBits[2]);
				Article article = getArticle(inputedId);

				if (article == null || article.id == 0) {
					System.out.printf("%d번째 게시글은 존재하지 않습니다.\n", inputedId);
					continue;
				}

				System.out.printf("%d번째) 제목 :", article.id);
				String title = sc.nextLine();
				System.out.printf("내용 : ");
				String body = sc.nextLine();

				modify(inputedId, title, body);
				System.out.printf("%d번 게시물이 수정되었습니다.\n", inputedId);

			}

 

 

 

 

*전체적인 일상은 노션을 통해 작성하고 있습니다.

링크 : www.notion.so/009-f23b45eedb564f05a30c9d4e4df1cca7