Monika Galińska
Monika Galińska

Reputation: 201

Spring Boot app ca't see my html files

Hello i create a Springboot app with defualt settings. I create controller, and work perefectly

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

        }

This controller return all users from database, but i trying redirect request to html page

@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";
    }
}

I put home.html in resources file, buti get emssage "Looking for index controller" and i just get error message in browser when i go to /home page

Upvotes: 0

Views: 62

Answers (2)

Evil Toad
Evil Toad

Reputation: 3242

The templates are searched by default in the src/main/resources/templates folder of the project. That's where you have to put JSP and HTML template files.

Upvotes: 1

Jonathan Sterling
Jonathan Sterling

Reputation: 604

It's hard to determine what's not working without seeing your error message, however, my best guess is you don't have a template engine wired up. You can generally fix this by adding this to your pom file:

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

Another common problem I face is when I autogenerate a HTML file, the <meta> tag isn't closed. This is fixed by changing this <meta charset="UTF-8"> to this: <meta charset="UTF-8" />

Upvotes: 1

Related Questions