我是春天的初学者。我正在尝试为应用程序构建登录页面。问题是我无法从控制器加载登录页面。下面是控制器的代码。
@RestController
public class RootViewController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView login() {
Map map = Collections.singletonMap("title", "Welcome! Login the website");
return new ModelAndView("sites/test", map);
}
}
该方法返回状态 404 错误。测试页是玉石的。配置文件代码如下。
@Configuration
class JadeConfig {
@Bean
public SpringTemplateLoader templateLoader() {
SpringTemplateLoader templateLoader = new SpringTemplateLoader();
templateLoader.setBasePath("classpath:template/");
templateLoader.setEncoding("UTF-8");
templateLoader.setSuffix(".jade");
return templateLoader;
}
@Bean
public JadeConfiguration jadeConfiguration() {
JadeConfiguration configuration
= new JadeConfiguration();
configuration.setCaching(false);
configuration.setTemplateLoader(templateLoader());
return configuration;
}
}
测试文件存在于 resources/template/sites
下面是gradle依赖
//Spring
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
compile group: 'de.neuland-bfi', name: 'spring-jade4j', version: '1.2.5'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
客户端页面测试应在通过配置文件设置的端口 8081 上运行。
server:
port: 8081