控制器看到.html页面但不是.jsp

时间:2018-04-27 10:41:38

标签: spring-mvc spring-boot

我是春天的新手, 所以我在HelloWorld示例上工作,我编写了以下简单的控制器:

with valid_rows as (
  select *
  from temp
  where all_data::text not like '[%'
)
select *
from valid_rows
where all_data ->> 'Accountid' = '1364';

enter image description here

我收到以下错误:

Controller
@RequestMapping("/welcome")
public class HelloWorldController{

   @RequestMapping(method = RequestMethod.GET)
   public ModelAndView helloWorld(){

    ModelAndView model = new ModelAndView("MVC_First_Page");
    model.addObject("msg", "hello world");

    return model;
  }

解析模板“错误”时出错,模板可能不存在或任何已配置的模板解析器可能无法访问

为什么拦截器看不到MVC_First_Page.jsp页面?我已将其扩展名更改为.html,并且可以正常工作。

我应该将此属性添加到application.properties文件吗?

 Error resolving template "error", template might not exist or might not be accessible by any of the configured Template Resolvers
Caused by: org.thymeleaf.exceptions.TemplateInputException: 

1 个答案:

答案 0 :(得分:1)

如果您不需要Thymeleaf(因为您只是在试验),最简单的方法就是只使用jsp视图解析器。

你可以在这里找到一个很好的例子:https://hellokoding.com/spring-boot-hello-world-example-with-jsp/

基本上,在您的代码中,您需要从<?php require_once 'bin/PHPCaller.php'; $argv = array(basename(__FILE__, '.php')); $argv[] = "search"; $argv[] = $_GET['mobile'] ; //print_r($argv); $phpCaller = new PHPCaller('apache2handler', $argv); $phpCaller->newLineCharacter = "\n"; $phpCaller->tabCharacter = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; ob_start(); $phpCaller->run(false); $response = ob_get_clean(); $data = json_decode($response, TRUE); $name = $data['data'][0]['name']; $score = (floatval($data['data'][0]['score']) * 10); //echo $name . "<br /><br />" . $score; echo $score; ?> 中删除Thymeleaf并添加jasper依赖项:

pom.xml

然后您必须在 <!--<dependency>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter-thymeleaf</artifactId>--> <!--</dependency>--> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> 文件中指定视图后缀:

application.properties

最后,您需要将JSP文件移动到spring.mvc.view.suffix=.jsp 目录