2016-11-18 45 views
0

你好,我創建defualt設置的Springboot應用。 創建控制器和工作perefectly春天啓動的應用程序ca't看到我的HTML文件

@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(); 

     } 

該控制器返回從數據庫中的所有用戶,但我想重定向請求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.html的資源文件,布提GET emssage 「尋找指數controller」而我只是得到錯誤信息在瀏覽器中,當我去到/ home網頁

回答

1

很難確定什麼是不沒有看到您的錯誤信息的工作,但是,我最好的猜測是,你沒有一個模板引擎wir編輯。你通常可以通過添加這對您的POM文件解決此問題:

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-thymeleaf</artifactId> 
</dependency> 

我面對的另一個常見問題是,當我一個自動生成的HTML文件中,<meta>標籤未關閉。通過將此<meta charset="UTF-8">更改爲:<meta charset="UTF-8" />

1

該項目的src/main/resources/templates文件夾中默認搜索模板。這就是你必須放置JSP和HTML模板文件的地方。

相關問題