users/list.html的问题
来源:13-6 -前台实现、测试-2
慕容5410851
2018-02-22
qq群里的users/list.html的代码为什么直接是一个div,没有头部,也没引入命名空间之类的?我加上了也不对啊?和视频里的不一样
写回答
5回答
-
可以不用头。因为是片段引用,只需要html的部分元素即可。望采纳
00 -
慕容5410851
提问者
2018-02-22
UserController:
@RestController @RequestMapping("/users") public class UserController { @Autowired private UserService userService; //获取所有用户的列表 @GetMapping public ModelAndView list(@RequestParam(value = "async", required = false) boolean async, @RequestParam(value = "pageIndex", required = false, defaultValue = "0") int pageIndex, @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize, @RequestParam(value = "name", required = false, defaultValue = "") String name, Model model ){ Pageable pageable = new PageRequest(pageIndex, pageSize); Page<User> page = userService.listUserByNameLike(name, pageable); List<User> list = page.getContent(); model.addAttribute("page", page); model.addAttribute("userList", list); return new ModelAndView(async==true?"users/list :: #mainContainerRepleace":"users/list", "userModel", model); } //获取创建表单页面 @GetMapping("/add") public ModelAndView createForm(Model model){ model.addAttribute("user", new User(null, null, null, null)); return new ModelAndView("users/add","userModel",model); } //保存或修改用户 @PostMapping public ResponseEntity<Response> saveOrUpdate(User user){ try { userService.saveOrUpdate(user); }catch (ConstraintViolationException e){ return ResponseEntity.ok().body(new Response(false, ConstraintViolationExceptionHandler.getMessage(e))); } return ResponseEntity.ok().body(new Response(true, "处理成功", user)); } //删除用户 @DeleteMapping(value = "/{id}") public ResponseEntity<Response> delete(@PathVariable("id") Long id, Model model){ try { userService.removeUser(id); }catch (Exception e){ return ResponseEntity.ok().body(new Response(false, e.getMessage())); } return ResponseEntity.ok().body(new Response(true, "处理成功")); } //获取修改用户的页面 @GetMapping("/edit/{id}") public ModelAndView modifyForm(@PathVariable("id") Long id, Model model){ User user = userService.getUserById(id); model.addAttribute("user", user); return new ModelAndView("users/edit", "userModel", model); } }
AdminController:
@Controller @RequestMapping("/admins") public class AdminController { @GetMapping public ModelAndView listUsers(Model model){ List<Menu> list = new ArrayList<Menu>(); list.add(new Menu("用户管理","/users")); model.addAttribute("list", list); return new ModelAndView("/admins/index", "model", model); } }
012018-02-22 -
慕容5410851
提问者
2018-02-22
老师我还是没明白红框里的这部分内容是从哪来的?
022018-02-22 -
慕容5410851
提问者
2018-02-22
我的意思是这么个疑问:admins/index.html里引入的不就是users/list.html了吗?如果把list.html加上头那么就和admins/index.html的头重叠了。但是如果list.html不加头的话就会像图片那样没有样式了
012018-02-22 -
慕容5410851
提问者
2018-02-22
你给的users/list的代码是下面这样的,没效果了??
012018-02-22
基于Spring Boot技术栈博客系统企业级前后端实战
毕设 Elasticsearch搜索+Thymeleaf模板+JPA+Security+BootStrap
1296 学习 · 738 问题
相似问题