Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在控制器中为 html-view 和 RESTful API 重用相同的逻辑。在 Grails 中执行此操作的最佳方法是什么?
我相信您正在withFormat寻找方法:
withFormat
(此处的代码取自该链接并添加了 JSON)
import grails.converters.XML import grails.converters.JSON class BookController { def list() { def books = Book.list() withFormat { html bookList:books js { render books as JSON } xml { render books as XML } } } }