简体   繁体   English

您可以将 jsp 用于您的前端,而您的后端路由在 Spring 引导中是安静的吗?

[英]Can you use jsp for your front end while your backend routes are restful in Spring Boot?

@RestController

public class IndexController {公共 class 索引控制器 {

@RequestMapping("/")
public String indexRoute() {
    return JSON HERE;
}

Suppose the above is my backend route, is there any way with jsp in which i can display that?假设以上是我的后端路线,jsp 有什么方法可以显示吗? I really dont want to use React to embed it.我真的不想使用 React 来嵌入它。

Yes you can annotate your class with @RestController to tell Spring that it's methods will return a HTTP response body (in JSON format for example) Yes you can annotate your class with @RestController to tell Spring that it's methods will return a HTTP response body (in JSON format for example)

And you can annotate an other class with @Controller to tell Spring that it's methods will return a view name (like a JSP file name for example)您可以使用@Controller注释另一个 class 以告诉 Spring 它的方法将返回视图名称(例如 JSP 文件名)

Controller: Controller:

@Controller
public class MyController {

    @GetMapping("/json")
    @ResponseBody
    public MyResource idexJson() {
        ...
        return res;
    }

    @GetMapping("/jsp")
    public String input(final Model model) {
        ...
        model.addAttribute(res);
        return "index";
    }

}

Additionally, you may possibly need additional configuration.此外,您可能需要额外的配置。 For example:例如:

properties:特性:

spring.mvc.view.prefix= /WEB-INF/view/
spring.mvc.view.suffix= .jsp

dependencies:依赖项:

    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>

Example code 示例代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 弹簧启动应用程序,前端和休息 - spring boot application with both front end and restful 如何使用三角形作为弹簧靴的前端? - how to use triangular as front end for spring boot? 你如何在 Spring-boot 中自动装配/注入你的数据源? - How do you autowire/inject your datasource in Spring-boot? Spring RESTful后端和Angularjs前端:如何从客户端添加参数? - Spring RESTful backend and Angularjs front end : How to add parameters from the client side? 如何使用查询方法在 JPA 中使用自定义查询(spring boot) - How to use Customize your Queries in JPA with Query Methods (spring boot) 如何使用React前端和Spring Boot安全后端进行客户端身份验证? - How do I do client side authentication check with React front end and Spring Boot security backend? Node.js / AngularJS前端调用Spring Boot API后端 - Node.js/AngularJS front end calling Spring Boot API backend 如何使用jsp在spring boot web应用中实现分页前端 - how to implement pagination front-end in spring boot web application using jsp 使用Spring作为grails前端的后端 - Using Spring as a backend for grails front end 如果在后端使用它,可以从spring(Boot)进行rest api调用吗? (使用调度程序)如果是,我应该使用rest模板吗? - Can you make a rest api call from spring (Boot) if you are using it on the backend? (Using a scheduler) If so, should I use rest template?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM