zoukankan      html  css  js  c++  java
  • Servlet 前端后台交互

    一. URL地址传值

      1.1、 地址传值   

      http://localhost:8080/xj/123/name.json 
      servlet 对应接受方法  
    1     @RequestMapping(value="/{name}/list.json",method = RequestMethod.GET)
    2     public @ResponseBody Object list(HttpServletRequest request, @PathVariable("name") String name) {
    3         
    4         List<School> schools = schoolService.findByNameLike(name);
    5         return schools;
    6     }
    
    
    1.2、 地址参数传值
      http://localhost:8080/xj/sch/name.json?name=123
      servlet 对应接受方法
    1     @RequestMapping(value="/name/list.json",method = RequestMethod.GET)
    2     public @ResponseBody Object list1(HttpServletRequest request, 
    3             @RequestParam(name="name", required=true) String name) {
    4         
    5         List<School> schools = schoolService.findByNameLike(name);
    6         return schools;
    7     }

     

    二. servlet 返回类型

      2.1、 Servlet 返回界面  

    1     @RequestMapping(value="/check",method = RequestMethod.GET)
    2     public String check(HttpServletRequest request, Model model) {
    3         model.addAttribute("name", "张三");
    4         return "credit/check";
    5     }
    
    
      返回类型为:String 
      返回界面需要的值放在 model 中
     1    @RequestMapping(value="/v/a",method = RequestMethod.POST)
     2     public String checkAll(HttpServletRequest request, RedirectAttributes attr,
     3                @Valid @ModelAttribute("ei") EducationInfo educationInfo,
     4                @Valid @ModelAttribute("di") DriverInfo driverInfo, BindingResult result,
     5                @AuthenticationPrincipal User user) {
     6         
     7         if(educationInfo != null && educationInfo.getPersonInfo() != null){
     8             try {
     9                 Map<String, Object> map = checkService.checkAll(user, educationInfo, driverInfo);
    10                 initData(attr, map);
    11             } catch (CreditException e) {
    12                 logger.info("远程服务请求失败:"+e.getMessage());
    13                 attr.addFlashAttribute("msg", e.getMessage());
    14             }
    15         }
    16         return "redirect:/check";
    17     }
      通过地址重定向进行绑定,保证了返回的界面地址栏上没有多余的参数;

      2.2. servlet 返回对象

      返回类型:@ResponseBody Object
      同例1.1或1.2代码
  • 相关阅读:
    提取轮廓后的画图处理
    提取视频中的前景物体
    写入视频帧
    处理视频序列
    视频读写
    三维重建-相机标定
    图像拼接相关
    计算两幅图像之间的单应矩阵
    ransac算法(随机抽样一致性)
    图像间投影关系
  • 原文地址:https://www.cnblogs.com/xx0405/p/5503958.html
Copyright © 2011-2022 走看看