zoukankan      html  css  js  c++  java
  • Spring中注解

    @Autowired :spring注解

    @Resource :J2EE注解

    @Transactional(rollbackFor=Exception.class):指定回滚

    @RequestMapping(value="/device/snap/{deviceCode}/{channelId}",method=RequestMethod.POST)

    public @ResponseBody void snap(@PathVariable String deviceCode,@PathVariable String channelId, HttpServletRequest request, HttpServletResponse response)

      @responseBody注解的作用是将controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通常用来返回JSON数据或者是XML

      数据,需要注意的呢,在使用此注解之后不会再走试图处理器,而是直接将数据写入到输入流中,他的效果等同于通过response对象输出指定格式的数据。  

      @RequestMapping("/login")
      @ResponseBody
      public User login(User user){
        return user;
      }
      User字段:userName pwd
      那么在前台接收到的数据为:'{"userName":"xxx","pwd":"xxx"}'

      效果等同于如下代码:
      @RequestMapping("/login")
      public void login(User user, HttpServletResponse response){
        response.getWriter.write(JSONObject.fromObject(user).toString());
      }

    public void sendProduct(@RequestParam int productId)    @RequestParam:获取请求参数

    public String submitOrder(@ModelAttribute Order order, Model model) @ModelAttribute:使用键值order将Order实例添加到Model对象中

  • 相关阅读:
    form 编译命令
    Form文件夹开发步骤
    使用View为Data Source的Form开发要点
    spring2.0包说明【转】
    Zero to One读后感
    Fourth glance in Go
    Third glance in Go
    Second glance in Go
    First glance in Go
    MongoDB 安装
  • 原文地址:https://www.cnblogs.com/stanljj/p/7003790.html
Copyright © 2011-2022 走看看