Posts

Showing posts from June, 2023

Java,Spring,hibernate開發web application rest api 的功能

 本人用的是Dynamic Web Project, Class path 有jackson-core-2.15.2.jar,jackson-annotations-2.15.2.jar,jackson-databind-2.15.2.jar 根據請求的內容類型選擇適當的視圖解析器。我們將默認內容類型設置為jsp,prefix是"/WEB-INF/view/",suffix 是".jsp" ,之後如找不到適當的視圖解析器就改為application/json,並使用MappingJackson2JsonView作為JSON視圖解析器, 現在 http://localhost:8080/genbook/book/list 成功找到視圖文件 list-books.jsp, 另一個 http://localhost:8080/genbook/book/retrieve rest api 應該回應一個json bookController程式: package com.book.gen.controller; import java.io.IOException; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Base64; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.ut