Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My controller is not getting mapped in the console.

My main class Application

package com.ruchi.web.sbfirst;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SbFirstApplication {

    public static void main(String[] args) {
        SpringApplication.run(SbFirstApplication.class, args);
    }

}

LoginController

package com.ruchi.web.sbfirst.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoginController {

    @RequestMapping("/login")
    public String loginMessage() {
        return "Hello";
    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
172 views
Welcome To Ask or Share your Answers For Others

1 Answer

Add @RestController annotation before the LoginController class

@RestController
public class LoginController {

    @RequestMapping("/login")
    public String loginMessage() {
        return "Hello";
    }

}

Reason you are using spring boot and also if you want to use @Controller annotation enable WebMVC.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...