简体   繁体   中英

Spring Boot GetMapping 404

I'm studying Java Spring Boot. But my get request always return 404, but my post request could succeed. I'm so confused. Here is my Java code:

@Controller
public class LexicalAnalysisController {


    @CrossOrigin 
    @GetMapping(value = "api/LexicalAnalysis/test")
    public String test(){
        return "111";
    }


}

Here is my javaScript code:

scan(){
        this.$axios
          .get('/LexicalAnalysis/test')
          .then((response) => {
            console.log(reponse.data);
          })
          
          .catch(failResponse =>{

          })
        
      }

Here is my error information:

在此处输入图像描述

So what's wrong? Thank you very much!

either change @controller to @RestController or add @ResponseBody below @controller . ResponseBody annotation binds a method return value to the web response body therefore it is required.

You should replace @Controller with @RestController .

This link maybe helpful.

I changed @Controller to @RestController and it worked, but I still don't know why.

Change @Controller to @RestController This will do the job

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM