zoukankan      html  css  js  c++  java
  • Spring Boot—11控制器Controller


    package com.sample.smartmap.controller;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.http.MediaType;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import com.sample.smartmap.entity.User;
    import com.sample.smartmap.service.UserService;
    /**
     * url映射到方法
     *
     */
    @Controller
    @RequestMapping("/user4")
    public class Sample34Controller {
        
        @Autowired UserService userService;
        
        @GetMapping("/" )
        public  @ResponseBody String index() {
            return "hell";
        }
        
    
        
        /**
         * 客户端请求必须包含application/json 才会处理
         * @return
         */
        @GetMapping(value="/all1.json",consumes = "application/json" )
        @ResponseBody
        public   User forJson() {
            return userService.getUserById(1l);
        }
        
        @GetMapping(path = "/user/{userId}.json", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
        @ResponseBody
        public User getUser(@PathVariable Long userId, Model model) {
             return userService.getUserById(userId);
        }
        
        
        @GetMapping(path = "/update.json", params = "action=save")
        @ResponseBody
        public void saveUser() {
             System.out.println("call save");
        }
        
        @GetMapping(path = "/update.json", params = "action=update")
        @ResponseBody
        public void updateUser() {
             System.out.println("call update");
        }
        
        
        
    }
  • 相关阅读:
    Jenkins tomcat 一键发布 (三)
    Jenkins docker 一键发布 (二)
    Jenkins docker 一键发布 (一)
    jenkins构建maven项目:找不到本地依赖包的解决办法
    Linux socket编程示例
    Linux虚拟机环境搭建
    Linux vim 配置
    vs2013 Qt5.7.0环境安装搭建
    Linux下如何生成core dump 文件
    QT5新建工程错误->无法打开源文件QtWidgets/QApplication
  • 原文地址:https://www.cnblogs.com/gispathfinder/p/8921194.html
Copyright © 2011-2022 走看看