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.