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");
} }

Spring Boot—11控制器Controller的更多相关文章

  1. Spring Boot Web 开发@Controller @RestController 使用教程

    在 Spring Boot 中,@Controller 注解是专门用于处理 Http 请求处理的,是以 MVC 为核心的设计思想的控制层.@RestController 则是 @Controller ...

  2. Spring Boot → 11:项目实战-账单管理系统完整版

    Spring Boot → 11:项目实战-账单管理系统完整版

  3. Spring boot进阶-配置Controller、interceptor...

    1.配置SpringBootApplication(对spring boot来说这是最基本) package io.github.syske.springboot31; import org.spri ...

  4. spring boot(11)-druid监控

    druid druid是和tomcat jdbc一样优秀的连接池,出自阿里巴巴.关于druid连接池参数,参考 https://github.com/alibaba/druid/wiki/DruidD ...

  5. 为spring boot 写的Controller中的rest接口配置swagger

    1.pom.xml文件中加入下列依赖: <dependency> <groupId>io.springfox</groupId> <artifactId> ...

  6. Spring Boot (11) mybatis 关联映射

    一对多 查询category中的某一条数据,同时查询该分类下的所有Product. Category.java public class Category { private Integer id; ...

  7. spring boot之入门Controller常用注解

    Controller常用注解 @Controller  处理http请求 @RestController Spring4之后新加的注解,原来返回json数据需要@ResponseBody配合@Cont ...

  8. 【Bug档案01】Spring Boot的控制器+thymeleaf模板 -使用中出现静态资源加载路径不当的问题 -解决时间:3h

    总结 - thymeleaf的模板解析规则不清楚,或者忘了; - 出现bug时,瞎调试, 没有打开NETWORK 进行查看资源的加载情况 - 控制器中的其他代码,可以先注释掉,这样就可以迅速屏蔽掉其他 ...

  9. spring boot controller路由 url 扫描不到问题

    spring boot项目出现controller的路由没被注册,原因:启动类application跟controller不在一个包中,扫描不到controller, 如启动类在com.oyx.a,c ...

随机推荐

  1. Python小白学习之路(十八)—【内置函数三】

    一.对象操作 help() 功能:返回目标对象的帮助信息 举例: print(help(input)) #执行结果 Help on built-in function input in module ...

  2. 【xsy1230】 树(tree) 点分治+线段树

    题目大意:有一棵$n$个节点的树,点的标号为$1$到$n$.树中的边有边权.给你$m$个询问,每个询问包含三个参数$l,r,pos$,你要求出标号在$l$到$r$之间的所有点中,到节点$pos$距离最 ...

  3. 直接插入排序实现(Java)

    直接插入排序介绍 直接插入排序的基本操作是将一个记录插入到已经排好序的有序表中,从而得到一个新的.记录数增1的有序表.     怎么理解呢?就是将n个待排序的元素看成一个有序表和一个无序表,开始时有序 ...

  4. <context:component-scan>详解 转发 https://www.cnblogs.com/fightingcoding/p/component-scan.html

    <context:component-scan>详解   默认情况下,<context:component-scan>查找使用构造型(stereotype)注解所标注的类,如@ ...

  5. yum安装报错:Failure when receiving data from the peer

    系统:Centos6.9 操作:yum install -y *.rpm 报错信息: Transaction Summary ===================================== ...

  6. Spring Security构建Rest服务-0701-个性化用户认证流程

    上一篇说了用户认证的基本流程,但是上一篇当访问一个受保护的服务后,如果未认证会调到默认的登录页面,这样是不行的,而且认证成功后,就直接访问了那个服务,如果想要做认证成功后做一些操作,还需要自定义. 个 ...

  7. Spring Security构建Rest服务-0200-搭建项目

    一.代码结构: 二.使用Springmvc开发restful API 传统url和rest区别: 三.写代码 1,编写RestfulAPI的测试用例:使用MockMvc伪造mvc package co ...

  8. JVM-调优命令

    jps JVM Process Status Tool,显示指定系统内所有的HotSpot虚拟机进程. 命令格式:   jps [options] [hostid] option参数: -l : 输出 ...

  9. postman—post方式几种请求参数区别

    postman中 form-data.x-www-form-urlencoded.raw.binary的区别 版权声明参考: https://blog.csdn.net/wangjun5159/art ...

  10. Java基础知识01

    1. String,StringBuffer和StringBuilder的区别? String:final修饰,String对象创建后不可修改:StringBuffer和StringBuilder对象 ...