当前位置:网站首页>记一个RestControll和Controller 引起的折磨BUG
记一个RestControll和Controller 引起的折磨BUG
2022-06-26 01:27:00 【wow_awsl_qwq】
项目中用的Controller ,然后请求路径无误的情况下,请求/account/list 结果给浏览器返回404,但是调试时却可以获取到信息,即数据库查询无误,仅仅到了返回给浏览器这一步就出错了
解决
后来发现是Controller注解和RestController注解的区别导致的问题
RestController = Controller +
ResponseBody,例如在项目当中,你加上的是RestController,那么返回的内容是你return中的内容,如果是return
“Hello World”,页面显示的就是Hello
World。但是如果你加上Controller,返回的是return中对应的页面,比如return
“hello”,页面的名称是hello,此时如果你的项目中没有hello这个页面,那么必然会出现404的错误
所以如果注解是Controller,那么它返回的是一个map,浏览器把它当做一个路径了,自然是找不到资源,而如果是RestController,相当于加了ResponseBody注解,浏览器会将它当成是内容,以上
@Controller//错误,应该改成@RestController
@RequestMapping("/account")
public class AccountController {
@Autowired
private AccountService accountService;
@RequestMapping("/list")
public Map<String,Object> listPageAccounts(Integer page, Integer rows, String aname){
Map<String,Object> map=new HashMap<>();
map.put("total",accountService.countAccounts(aname));
map.put("rows",accountService.listPageAccounts(page,rows,aname));
return map;
}
@RequestMapping("/saveAccount")
public boolean saveAccount(Account account, Category category){
account.setCategory(category);
return accountService.saveAccount(account);
}
}
边栏推荐
- Shell learning record (IV)
- Thirty ninth step
- MySQL doit maîtriser 4 langues!
- IPhone 13 screen stuck black, unable to shut down? How to solve
- Digital commodity DGE -- the dark horse of wealth in digital economy
- Depth first traversal based on adjacency table
- 基于邻接表的广度优先遍历
- df报错Stale file handle
- Ndk20b ffmpeg4.2.2 compilation and integration
- Breadth first traversal based on adjacency matrix
猜你喜欢

Audio video and CPU architecture

Raspberry pie + AWS IOT Greengrass

表达式的动态解析和计算,Flee用起来真香

IPhone 13 screen stuck black, unable to shut down? How to solve

Pie chart metamorphosis record, the liver has 3000 words, collection is to learn!

音视频与CPU架构

分享一些在内网操作的远程办公经验| 社区征文

Largeur d'abord traversée basée sur la matrice de contiguïté

ROS2+DDS+RTPS

df报错Stale file handle
随机推荐
@Query 疑难杂症
微博评论的高性能高可用计算架构
Fastadmin applet assistant is purchased, but the work order cannot be published in the problem work order
Breadth first traversal based on adjacency table
Analytic hierarchy process
Cross server SQL connection configuration
Which securities company is better and safer to open a mobile stock account?
版本管理工具使用
One year's work
Raspberry pie + AWS IOT introductory experiment
How do I fix the iPhone green screen problem? Try these solutions
Binary search
樹莓派 + AWS IoT Greengrass
55 pictures make you feel a bit B-tree at one time
.NET7之MiniAPI(特别篇) :Preview5优化了JWT验证(下)
Thirty ninth step
请指教同花顺软件究竟是什么?在线开户安全么?
工作一年闲记
Magnifier case
短信插件哪个好用万能表单需要发短信着急测试