-
springmvc的一部分技术细节查看全部
-
各模块协作示意图查看全部
-
宏观 - 着重考虑业务逻辑查看全部
-
@PathVariable - @RequestMapping("/xxx/{xxxId}")中的id能够通过@PathVariable注解绑定它传过来的值到方法的参数上查看全部
-
文件上传 @RequestMapping(value="/doUpload",method = RequestMethod.GET) public String doUploadFile(@RequestParam("file") MultipartFile file) throws IOException { if(file.isEmpty()) { log.debug("处理文件",file.getOriginalFilename()); FileUtils.copyInputStreamToFile(file.getInputStream(),new File("C:\\Users\\Administrator\\Desktop\\5595e54e0001530f00000000\\spring-mvc-study\\src\\main\\webapp\\WEB-INF\\jsps\\course_admin\\testFile",System.currentTimeMillis()+"file.getOriginalFilename()")); } return "success"; }查看全部
-
file.jsp中的<input type="file" name="file"/>中绑定到了@RequestParam("file")中查看全部
-
通过返回值再次调用"redirect:view2/"+course.getCourseId();重定向到/view2页面方法并且传入的ID是刚写入的CourseId @RequestMapping(value = "/save", method = RequestMethod.POST) public String doSave(@ModelAttribute Course course) { log.debug("Course的信息"); log.debug(ReflectionToStringBuilder.toString(course)); //在此进行业务操作,比如数据库持久化 course.setCourseId(123); return "redirect:view2/" + course.getCourseId(); }查看全部
-
action="<%= request.getContextPath()%>/courses/save" 因为courses下有一个save方法,所以要在controller中的@RequestMapping映射一个save查看全部
-
<div> <span>课程名称:</span><input type="text" id="title" name="title"> </div> <div> <span>课程时长:</span><input type="text" id="duration" name="duration"> 秒 </div> 页面中控件的名称要和model中属性的名称一致查看全部
-
//本方法将处理 /courses/view3?courseId=123 形式的URL //http://localhost:8080/courses/view3?courseId=123 @RequestMapping("/view3") public String viewCourse3(HttpServletRequest request) { Integer courseId = Integer.valueOf(request.getParameter("courseId")); Course course = courseService.getCourseById(courseId); request.setAttribute("course",course); return "course_overview"; }查看全部
-
//本方法将处理 /courses/view2/123 形式的URL //http://localhost:8080/courses/view2/123 @RequestMapping("/view2/{courseId}") public String viewCourse2(@PathVariable("courseId") Integer courseId, Map<String, Object> model) { log.debug("In viewCourse2, courseId = {}", courseId); Course course = courseService.getCourseById(courseId); model.put("course", course); return "course_overview"; }查看全部
-
//本方法将处理/courses/view?courseId=123 形式的URL //项目地址http://localhost:8080/courses/viewaaa?courseId=123 @RequestMapping(value = "/viewaaa", method = RequestMethod.GET) public String viewCourse(@RequestParam("courseId") Integer courseId, Model model) { log.debug("In viewCourse,courseId = {}", courseId); Course course = courseService.getCourseById(courseId); model.addAttribute(course); return "course_overview"; }查看全部
-
@RequestMapping(value="/save", method = RequestMethod.POST) public String doSave(@ModelAttribute Course course){ log.debug("Info of Course:"); log.debug(ReflectionToStringBuilder.toString(course)); //在此进行业务操作,比如数据库持久化 course.setCourseId(123); return "redirect:view2/"+course.getCourseId(); } @RequestMapping(value="/{courseId}",method=RequestMethod.GET) public @ResponseBody Course getCourseInJson(@PathVariable Integer courseId){ return courseService.getCoursebyId(courseId); }查看全部
-
//本方法将处理 /courses/view2/123 形式的URL @RequestMapping("/view2/{courseId}") public String viewCourse2(@PathVariable("courseId") Integer courseId, Map<String, Object> model) { log.debug("In viewCourse2, courseId = {}", courseId); Course course = courseService.getCoursebyId(courseId); model.put("course",course); return "course_overview"; } //本方法将处理 /courses/view3?courseId=123 形式的URL @RequestMapping("/view3") public String viewCourse3(HttpServletRequest request) { Integer courseId = Integer.valueOf(request.getParameter("courseId")); Course course = courseService.getCoursebyId(courseId); request.setAttribute("course",course); return "course_overview"; } @RequestMapping(value="/admin", method = RequestMethod.GET, params = "add") public String createCourse(){ return "course_admin/edit"; }查看全部
-
- @Controller 声明一个controller - @RequestMapping 映射URL和方法,通常出现在类级别和方法级别,二者共同组合完成对一个url映射请求的拦截 - URL template(@RequestParam and @PathVariable)可以将路径之中的参数绑定到requestmethod的get或者post - HttpServletRequest and / or HttpSession 获取想要的结果 @Controller @RequestMapping("/courses") // /courses/** public class CourseController { private static Logger log = LoggerFactory.getLogger(CourseController.class); private CourseService courseService; @Autowired public void setCourseService(CourseService courseService) { this.courseService = courseService; } //本方法将处理 /courses/view?courseId=123 形式的URL @RequestMapping(value="/view", method=RequestMethod.GET) public String viewCourse(@RequestParam("courseId") Integer courseId, Model model) { log.debug("In viewCourse, courseId = {}", courseId); Course course = courseService.getCoursebyId(courseId); model.addAttribute(course); return "course_overview"; }查看全部
举报
0/150
提交
取消