spring boot, problem mapping view with simple driver

0

I started an application with Spring Boot , Generate maven project with Java 1.8 and Spring Boot 2.0.3 I have created a simple controller and a view and it does not map it to me. Should we touch something? Any application propertie?

I have the view in templates ( holamundo.html ) and my controller:

package controladores;

import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/say")

public class holamundoController {

    @GetMapping("/holamundo")

    public String HolaMundo(){

        return "holamundo";
    }

}
    
asked by Unai Longvalley 30.06.2018 в 20:57
source

3 answers

0

It would be good if you could post some of your code to see what could fail. First of all, when working with Spring boot you need this mainly:

-To have your controller CLASS (remember that @Controller must be noted to indicate it).

-Have your view according to whether it is in HTML or with JSP (if it is HTML with template engine Thymeleaf you must place it in / resources / templates, if it is JSP it is normal with webapp).

-In your controlling class, you must point with an @RequestMapping (value="/ test", method = RequestMethod.GET) where VALUE would go the route with which you want to access the page -localhost ../ test- or it is also possible with @GetMapping ("/ test") followed by the skeleton of your method.

-Finally, you must return the name of the page.

Example:

@GetMapping("/test")
public String test{

...
..
return "test"
}

For the case of thymeleaf you do not need to specify the .html

Greetings.

    
answered by 30.06.2018 в 21:29
0

I have the view in templates (helloworld.html) and my controller:

package drivers;

import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping ("/ say")

public class hellomundoController {

@GetMapping("/holamundo")

public String HolaMundo(){

    return "holamundo";
}

}

    
answered by 30.06.2018 в 22:07
-1

You have to write down your controller with @Controller

@Controller
public class HolamundoController {

    @GetMapping("/holamundo")
    public String holaMundo(){

       return "holamundo";
    }

}

Also remember that the classes have to start in Uppercase and the methods in lower case.

Greetings

    
answered by 16.07.2018 в 23:13