当前位置:网站首页>Record a torture bug caused by restcontrol and controller
Record a torture bug caused by restcontrol and controller
2022-06-26 02:56:00 【wow_ awsl_ qwq】
Used in the project Controller , Then the request path is correct , request /account/list The result is returned to the browser 404, However, information can be obtained during debugging , That is, the database query is correct , Just return to the browser and an error occurs
solve
Later it was found that Controller Notes and RestController Differences in annotations cause problems
RestController = Controller +
ResponseBody, For example, in the project , You added RestController, Then the content returned is you return The content in , If it is return
“Hello World”, The page shows Hello
World. But if you add Controller, The return is return The corresponding page in , such as return
“hello”, The name of the page is hello, At this point, if your project does not have hello This page , Then there must be 404 Error of
So if the annotation is Controller, Then it returns a map, The browser takes it as a path , Naturally, there is no resource to be found , And if it is RestController, It's equivalent to adding ResponseBody annotation , Browsers will think of it as content , above
@Controller// error , Should be changed into @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);
}
}
边栏推荐
- 分享一些在内网操作的远程办公经验| 社区征文
- Mysql常用sql语句之修改表名、删除表、获取表信息、删除指定日期的表记录
- Thirty ninth step
- 请指教同花顺软件究竟是什么?在线开户安全么?
- Here comes the official zero foundation introduction jetpack compose Chinese course!
- [机器翻译]—BLEU值的计算
- A few simple ways for programmers to exercise their waist
- IPhone 13 screen stuck black, unable to shut down? How to solve
- Limit the input character length to 1 character in English and 2 characters in Chinese
- UTONMOS坚持“藏品、版权”双优原则助力传统文化高质量发展
猜你喜欢
随机推荐
df报错Stale file handle
Little p weekly Vol.10
. Net7 miniapi (special part):preview5 optimizes JWT verification (Part 2)
股票开户怎么开户?网上开户是否安全么?
请指教同花顺开户选选择哪家券商比较好?网上开户是否安全么?
Camtasia 2022 nouvelle vidéo d'ordinateur d'enregistrement ultra - clair
Arthas(阿尔萨斯) 能为你做什么?
R language survival analysis
OpenAPI 3.0 specification - Food Guide
UTONMOS坚持“藏品、版权”双优原则助力传统文化高质量发展
Camtasia 2022全新版超清录制电脑视频
Fresh graduates talk about their graduation stories
Learn Tai Chi Maker - mqtt (IV) server connection operation
Gd32 ADC acquisition voltage
Google 推荐在 MVVM 架构中使用 Kotlin Flow
How to adjust face input size
What is the sudden power failure of iPhone and how to solve it?
ORB-SLAM3论文概述
A few simple ways for programmers to exercise their waist
7 tips to change your life