1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | package com.beans.erp.controller; import com.beans.erp.model.Document; import com.beans.erp.service.DocumentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; @Controller @RequestMapping("/documents") public class BeansDocumentController { @Autowired private DocumentService documentService; @GetMapping public String listDocuments(Model model) { model.addAttribute("documents", documentService.getAllDocuments()); return "documentList"; } @GetMapping("/{id}") public String viewDocument(@PathVariable Long id, Model model) { model.addAttribute("document", documentService.getDocumentById(id)); return "documentView"; } @PostMapping public String createDocument(Document document) { documentService.saveDocument(document); return "redirect:/documents"; } @DeleteMapping("/{id}") public String deleteDocument(@PathVariable Long id) { documentService.deleteDocument(id); return "redirect:/documents"; } } package com.beans.erp.model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import java.util.Date; @Entity public class Document { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String title; private String content; private Date createdDate; private Date modifiedDate; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public Date getCreatedDate() { return createdDate; } public void setCreatedDate(Date createdDate) { this.createdDate = createdDate; } public Date getModifiedDate() { return modifiedDate; } public void setModifiedDate(Date modifiedDate) { this.modifiedDate = modifiedDate; } } package com.beans.erp.repository; import com.beans.erp.model.Document; import org.springframework.data.jpa.repository.JpaRepository; public interface DocumentRepository extends JpaRepository<Document, Long> { } package com.beans.erp.service; import com.beans.erp.model.Document; import com.beans.erp.repository.DocumentRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class DocumentService { @Autowired private DocumentRepository documentRepository; public List<Document> getAllDocuments() { return documentRepository.findAll(); } public Document getDocumentById(Long id) { return documentRepository.findById(id).orElse(null); } public Document saveDocument(Document document) { return documentRepository.save(document); } public void deleteDocument(Long id) { documentRepository.deleteById(id); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | <!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>ERP 프로그램</title> <link rel="stylesheet" href="beans_erp.css"> <style> body { font-family: Arial, sans-serif; background-color: #f0f0f0; margin: 0; padding: 0; } #app { background-color: #fff; margin: 20px; padding: 20px; border-radius: 5px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 10px; border-bottom: 1px solid #ccc; margin-bottom: 20px; } h1 { font-size: 24px; margin: 0; } nav ul { list-style: none; margin: 0; padding: 0; display: flex; } nav ul li { margin-right: 20px; } nav ul li a { text-decoration: none; color: #333; font-weight: bold; } main table { width: 100%; border-collapse: collapse; margin-bottom: 20px; } th, td { border: 1px solid #ccc; padding: 8px; text-align: center; } th { background-color: #f0f0f0; } h3 { font-size: 20px; margin: 20px 0 10px; } form div { margin-bottom: 10px; } label { display: block; margin-bottom: 5px; } input[type="text"], input[type="number"] { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 5px; } button[type="submit"] { background-color: #007BFF; color: #fff; border: none; border-radius: 5px; padding: 8px 15px; cursor: pointer; } button[type="submit"]:hover { background-color: #0056b3; } footer { margin-top: 20px; text-align: center; font-size: 14px; color: #777; } </style> </head> <body> <div id="app"> <header> <h1>ERP 프로그램</h1> <nav> <ul id="menuList"> <li><a href="/home">홈</a></li> <li><a href="/BeansOrderManagement">주문 관리</a></li> <li><a href="/BeansInventoryLogistics">재고 및 물류</a></li> <li><a href="/BeansHumanResources">인력 및 인사</a></li> <li><a href="/BeansAccountingFinance">회계 및 재무</a></li> <li><a href="/BeansProjectManagement">프로젝트 관리</a></li> <li><a href="/BeansProjectCreate">프로젝트 생성</a></li> <li><a href="/BeansDocumentManagement">문서 관리</a></li> <li><a href="/BeansNotifications">알림</a></li> <li><a href="/BeansMemberInformation">회원정보</a></li> </ul> </nav> </header> <main> <table border="1"> <thead> <tr> <th>ID</th> <th>제목</th> <th>작성일</th> <th>수정일</th> <th>동작</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>문서 제목 1</td> <td>2023-08-27</td> <td>2023-08-28</td> <td><a href="#">보기</a> | <a href="#">편집</a> | <a href="#">삭제</a> </td> </tr> <!-- 나머지 문서 데이터 추가 --> </tbody> </table> <h3>새 문서 추가</h3> <form action="#" method="post"> <div> <label for="title">제목:</label> <input type="text" id="title" name="title" required> </div> <div> <label for="content">내용:</label> <textarea id="content" name="content"></textarea> </div> <div> <button type="submit">문서 추가</button> </div> </form> <!-- 이미지 첨부 --> <div> <label for="image">이미지 첨부</label> <img src="/spring.jfif" alt="이미지" width="200"> </div> </main> <footer> <p>© 2023 beans_ERP 프로그램에 오신 것을 환영합니다.</p> </footer> </div> <script> const menuList = document.getElementById('menuList'); const content = document.getElementById('content'); menuList.addEventListener('click', (event) => { const clickedItem = event.target.dataset.page; if (clickedItem) { const pageURL = '/beans_erp' + getPagePath(clickedItem); loadPage(pageURL); } }); function getPagePath(pageName) { const pagePaths = { '주문 관리': '/BeansOrderManagement', '재고 및 물류': '/BeansInventoryLogistics', '인력 및 인사': '/BeansHumanResources', '회계 및 재무': '/BeansAccountingFinance', '프로젝트 관리': '/BeansProjectManagement', '프로젝트 생성': '/BeansProjectCreate', '문서 관리': '/BeansDocumentManagement', '알림': '/BeansNotifications', '회원정보': '/BeansMemberInformation' }; return pagePaths[pageName] || ''; } function loadPage(pageURL) { fetch(pageURL) .then(response => response.text()) .then(data => { content.innerHTML = data; }) .catch(error => { console.error('페이지 로딩 에러:', error); }); } </script> </body> </html> | cs |
각 컨트롤러의 전문적인? 기술을 최소화한채로
제작하였습니다.
스프링 부트는 내장 웹 서버를 제공하여 별도의 웹 서버 설정 없이 웹 애플리케이션을 실행할 수 있는 점을 크게 느꼈던 하루였습니다.