Spring Boot应用程序ca';我看不到我的html文件
您好,我创建了一个带有default设置的Springboot应用程序。 我创建了控制器,并且工作得很好Spring Boot应用程序ca';我看不到我的html文件,spring,spring-boot,Spring,Spring Boot,您好,我创建了一个带有default设置的Springboot应用程序。 我创建了控制器,并且工作得很好 @RestController @RequestMapping("/users") public class UserController { private UserRepository userRepository; @Autowired public UserController(UserRepository u
@RestController
@RequestMapping("/users")
public class UserController {
private UserRepository userRepository;
@Autowired
public UserController(UserRepository userRepository) {
this.userRepository = userRepository;
}
@RequestMapping(method = RequestMethod.GET)
public List<Userus> findAllUsers(){
return userRepository.findAll();
}
@RestController
@请求映射(“/users”)
公共类用户控制器{
私有用户存储库用户存储库;
@自动连线
公共用户控制器(用户存储库用户存储库){
this.userRepository=userRepository;
}
@RequestMapping(method=RequestMethod.GET)
公共列表findAllUsers(){
返回userRepository.findAll();
}
该控制器返回数据库中的所有用户,但我正在尝试将请求重定向到html页面
@Controller
@RequestMapping("/home")
public class ActorsController {
@RequestMapping(method = RequestMethod.GET)
public String index(Map<String, Object> model){
System.out.print("Looking for index controller ");
return "home";
}
}
@控制器
@请求映射(“/home”)
公共类ActorsController{
@RequestMapping(method=RequestMethod.GET)
公共字符串索引(映射模型){
系统输出打印(“寻找索引控制器”);
返回“家”;
}
}
我把home.html放在参考资料文件中,但我收到一条消息“寻找索引控制器”当我进入/主页时,我在浏览器中只会收到错误消息。如果不看到您的错误消息,很难确定哪些内容不起作用,但是,我的最佳猜测是您没有连接模板引擎。您通常可以通过将其添加到pom文件来修复此问题:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
org.springframework.boot
弹簧启动装置
我面临的另一个常见问题是,当我自动生成HTML文件时,
标记没有关闭。通过将此
更改为:很难在不看到错误消息的情况下确定什么不起作用,但是,我的最佳猜测是您没有连接模板引擎。您通常可以修复此问题通过将以下内容添加到您的pom文件:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
org.springframework.boot
弹簧启动装置
我面临的另一个常见问题是,当我自动生成HTML文件时,
标记没有关闭。通过将此
更改为:
默认情况下,模板会在项目的src/main/resources/templates
文件夹中搜索。这是您必须放置JSP和HTML模板文件的地方 默认情况下,模板会在项目的src/main/resources/templates
文件夹中搜索。在那里,您必须放置JSP和HTML模板文件