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