【问题标题】:How to return data within / with page without jsp / templates?如何在没有 jsp / 模板的情况下在 / 页面内返回数据?
【发布时间】:2020-01-23 01:09:16
【问题描述】:

[初学者] 嗨,我正在尝试学习 spring,但没有 Jsp。有没有办法使用例如 ModelAndView 在页面内/与页面返回数据,例如在 Jsp 中?我找到了一些建议模板(百里香)的答案,但现在,我不想弄乱模板。提前谢谢你:)

【问题讨论】:

    标签: javascript spring spring-boot jsp thymeleaf


    【解决方案1】:

    您可以在 Controller 类中通过 @RestController 注释返回 json 数据。

    @RequestMapping("/api/demo")
    @RestController
    public class DemoController {
        @GetMapping("/getData")
        public String getData(HttpServletRequest request) {
            return "{}";
        }
    
    }
    

    【讨论】:

      【解决方案2】:

      据我了解,您正在寻找开发 REST API。 您可能有也可能没有显示数据的前端页面 - 然后您尝试实现其 REST API 开发以查看/更新数据。

      您可以关注 - https://spring.io/guides/gs/rest-service/ 进行开发。详细示例可以阅读https://dzone.com/articles/how-to-create-rest-api-with-spring-boot

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-04-06
        • 2018-11-03
        • 1970-01-01
        • 2012-07-21
        • 2016-11-06
        • 1970-01-01
        • 2016-07-03
        相关资源
        最近更新 更多