@RequestMapping("/infoList") public String infoList(Model model, String keyword) { LambdaQueryWrapper<Notice> noticeLambdaQueryWrapper = new LambdaQueryWrapper<>(); noticeLambdaQueryWrapper.like(ObjectUtils.isNotEmpty(keyword), Notice::getTitle, keyword); noticeLambdaQueryWrapper.or().like(ObjectUtils.isNotEmpty(keyword), Notice::getContent, keyword); List<Notice> list = noticeService.list(noticeLambdaQueryWrapper); model.addAttribute("noticeinfoList", list); return "infoList"; }请详细解释每一行代码
时间: 2023-06-26 21:05:21 浏览: 55
好的,我来为你逐行解释这段代码的含义:
1. `@RequestMapping("/infoList")`:这是一个Spring MVC注解,用于映射URL请求到该方法上。在这里,当用户请求"/infoList"时,该方法会被调用。
2. `public String infoList(Model model, String keyword)`:这是一个Java方法,它的返回值是一个字符串。该方法使用了两个参数:一个是Spring提供的Model对象,一个是字符串类型的keyword参数。
3. `LambdaQueryWrapper<Notice> noticeLambdaQueryWrapper = new LambdaQueryWrapper<>();`:这行代码创建了一个Notice类型的LambdaQueryWrapper对象。该对象用于构建mybatis-plus的查询条件。
4. `noticeLambdaQueryWrapper.like(ObjectUtils.isNotEmpty(keyword), Notice::getTitle, keyword);`:这行代码添加了一个like查询条件,如果keyword不为空,则查询Notice表中标题中包含该关键字的记录。
5. `noticeLambdaQueryWrapper.or().like(ObjectUtils.isNotEmpty(keyword), Notice::getContent, keyword);`:这行代码添加了另外一个like查询条件,如果keyword不为空,则查询Notice表中内容中包含该关键字的记录。注意,这里使用了or()方法,表示两个条件之间是或的关系。
6. `List<Notice> list = noticeService.list(noticeLambdaQueryWrapper);`:这行代码使用mybatis-plus提供的service方法list(),执行查询,将查询结果保存在一个List中。
7. `model.addAttribute("noticeinfoList", list);`:这行代码将查询结果保存在Spring提供的Model对象中,以便在视图中使用。
8. `return "infoList";`:这行代码指定了该方法的返回值,即返回名为"infoList"的视图。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
作为管理员,你可以 查看所有图书 查看所有用户 查看所有订单 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>用户</title> <style type="text/css"> .odd{ background-color: antiquewhite; } .even{ background-color: aquamarine; } </style> <script type="text/javascript" th:src="@{/webjars/jquery/3.5.1/jquery.js}"></script> <script type="text/javascript" th:src="@{/webjars/bootstrap/4.5.3/js/bootstrap.min.js}"></script> </head> <body> 序号 用户名 角色 </body> </html>@RequestMapping ("/findAllUser") public String findAllUser(Model model){ List<User> users = userService.findAllUser(); model.addAttribute("users",users); return "/oss/peoples"; }出现不好意思,你的请求路径可能错误了,请查看!
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
@PreAuthorize("hasRole('admin')") @RequestMapping ("/oss/peoples") public ModelAndView findAllUser(Model model){ List<User> users = userService.findAllUser(); model.addAttribute("users",users); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("/oss/peoples"); return modelAndView; }<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>用户</title> <style type="text/css"> .odd{ background-color: antiquewhite; } .even{ background-color: aquamarine; } </style> <script type="text/javascript" th:src="@{/webjars/jquery/3.5.1/jquery.js}"></script> <script type="text/javascript" th:src="@{/webjars/bootstrap/4.5.3/js/bootstrap.min.js}"></script> </head> <body> 序号 用户名 角色 </body> </html>查看所有用户不好意思,你的请求路径可能错误了,请查看!
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)