spring mvc,控制器中用RequestMapping,但是能访问?

[复制链接]
查看11 | 回复10 | 2021-1-27 07:15:45 | 显示全部楼层 |阅读模式
控制器里用了@RequestMapping(method=RequestMethod.GET),但是访问的时候不会去执行,而是返回一个值HelloWorld!
这个值是不存在的
分 -->
回复

使用道具 举报

千问 | 2021-1-27 07:15:45 | 显示全部楼层
没有人回答吗?
回复

使用道具 举报

千问 | 2021-1-27 07:15:45 | 显示全部楼层
RequestMapping你是不是少了个value即url
回复

使用道具 举报

千问 | 2021-1-27 07:15:45 | 显示全部楼层
引用2楼fangyuandoit的回复:RequestMapping你是不是少了个value即url
2楼说的对,应该是这样的@RequestMapping(value="saveXXX",method=RequestMethod.GET)
回复

使用道具 举报

千问 | 2021-1-27 07:15:45 | 显示全部楼层
代码是这样的,这里不需要value啊
@Controller
@RequestMapping("/")
publicclassHelloWorldController{
/*
*ThismethodwillserveasdefaultGEThandler.
*
*/
@RequestMapping(method=RequestMethod.GET)
publicStringnewRegistration(ModelMapmodel){
Studentstudent=newStudent();
model.addAttribute("student",student);
return"enroll";
}
}
回复

使用道具 举报

千问 | 2021-1-27 07:15:45 | 显示全部楼层


引用4楼caobingyi的回复:代码是这样的,这里不需要value啊
@Controller
@RequestMapping("/")
publicclassHelloWorldController{
/*
*ThismethodwillserveasdefaultGEThandler.
*
*/
@RequestMapping(method=RequestMethod.GET)
publicStringnewRegistration(ModelMapmodel){
Studentstudent=newStudent();
model.addAttribute("student",student);
return"enroll";
}
}





回复

使用道具 举报

千问 | 2021-1-27 07:15:45 | 显示全部楼层
引用5楼u012445835的回复:Quote: 引用4楼caobingyi的回复:
代码是这样的,这里不需要value啊
@Controller
@RequestMapping("/")
publicclassHelloWorldController{
/*
*ThismethodwillserveasdefaultGEThandler.
*
*/
@RequestMapping(method=RequestMethod.GET)
publicStringnewRegistration(ModelMapmodel){
Studentstudent=newStudent();
model.addAttribute("student",student);
return"enroll";
}
}





如何我要访问的地址是:http://127.0.0.1:8080/项目名
返回的应该是enroll.jsp
回复

使用道具 举报

千问 | 2021-1-27 07:15:45 | 显示全部楼层
我要访问的地址是:http://127.0.0.1:8080/项目名,然后跳转到enroll.jsp,奇怪的是,我访问http://127.0.0.1:8080/项目名,返回浏览器的是HelloWorld!
我知道加value是可以的,但是,我这样的思路不对吗?


回复

使用道具 举报

千问 | 2021-1-27 07:15:45 | 显示全部楼层
引用7楼caobingyi的回复:我要访问的地址是:http://127.0.0.1:8080/项目名,然后跳转到enroll.jsp,奇怪的是,我访问http://127.0.0.1:8080/项目名,返回浏览器的是HelloWorld!
我知道加value是可以的,但是,我这样的思路不对吗?

这样好像不行的,http://127.0.0.1:8080/项目名好像默认是进入index
回复

使用道具 举报

千问 | 2021-1-27 07:15:45 | 显示全部楼层
引用8楼u012445835的回复:Quote: 引用7楼caobingyi的回复:
我要访问的地址是:http://127.0.0.1:8080/项目名,然后跳转到enroll.jsp,奇怪的是,我访问http://127.0.0.1:8080/项目名,返回浏览器的是HelloWorld!
我知道加value是可以的,但是,我这样的思路不对吗?

这样好像不行的,http://127.0.0.1:8080/项目名好像默认是进入index

我把index.jsp删除了,还能正常运行,还能返回helloworld,怎么回事?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行