当前位置:网站首页>记一个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);
}
}
边栏推荐
猜你喜欢

程序员的八年工资变动,令网友羡慕不已:你一个月顶我一年工资

饼图变形记,肝了3000字,收藏就是学会!
![[image filtering] image filtering system based on Matlab GUI [including Matlab source code 1913]](/img/53/6683e7db960fbba773a9013985dcca.jpg)
[image filtering] image filtering system based on Matlab GUI [including Matlab source code 1913]

Cross server SQL connection configuration

College Students' big factory road

Scala 基础 (二):变量和数据类型

奶牛排序问题

【图像过滤】基于matlab GUI图像过滤系统【含Matlab源码 1913期】

Explain the JVM clearly at one time and don't be asked by the interviewer again

A high-frequency interview question from a large factory: tell me about the solution of high and low interface idempotence? Solutions are attached.
随机推荐
How do I take a screenshot of the iPad? 7 ways to take quick screenshots of iPad
[defect detection] automatic defect detection of printed circuit board based on Matlab GUI [including Matlab source code 1912]
Depth first traversal of Graphs
PyQt theme
How do I fix the iPhone green screen problem? Try these solutions
2022-06-25:给定一个正数n, 表示有0~n-1号任务, 给定一个长度为n的数组time,time[i]表示i号任务做完的时间, 给定一个二维数组matrix, matrix[j] = {a,
How to improve code execution efficiency with arm pipeline
Bloc入门之Cubit详解
Ardiuno smart mosquito racket
Redis6.0 new feature - ACL (permission control list) implements the restriction of user executable commands and keys
vs2015+PCL1.8.1+qt5.12-----(1)
[untitled] vsbiji ESP thirty-two
ROS2+DDS+RTPS
Breadth first traversal of Graphs
How to solve the problem that the iPhone 13 lock screen cannot receive the wechat notification prompt?
win32
Breadth first traversal based on adjacency table
One year's work
为 ServiceCollection 实现装饰器模式
Qtvtkvs2015 test code