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");
} }
Spring Boot—11控制器Controller的更多相关文章
- Spring Boot Web 开发@Controller @RestController 使用教程
在 Spring Boot 中,@Controller 注解是专门用于处理 Http 请求处理的,是以 MVC 为核心的设计思想的控制层.@RestController 则是 @Controller ...
- Spring Boot → 11:项目实战-账单管理系统完整版
Spring Boot → 11:项目实战-账单管理系统完整版
- Spring boot进阶-配置Controller、interceptor...
1.配置SpringBootApplication(对spring boot来说这是最基本) package io.github.syske.springboot31; import org.spri ...
- spring boot(11)-druid监控
druid druid是和tomcat jdbc一样优秀的连接池,出自阿里巴巴.关于druid连接池参数,参考 https://github.com/alibaba/druid/wiki/DruidD ...
- 为spring boot 写的Controller中的rest接口配置swagger
1.pom.xml文件中加入下列依赖: <dependency> <groupId>io.springfox</groupId> <artifactId> ...
- Spring Boot (11) mybatis 关联映射
一对多 查询category中的某一条数据,同时查询该分类下的所有Product. Category.java public class Category { private Integer id; ...
- spring boot之入门Controller常用注解
Controller常用注解 @Controller 处理http请求 @RestController Spring4之后新加的注解,原来返回json数据需要@ResponseBody配合@Cont ...
- 【Bug档案01】Spring Boot的控制器+thymeleaf模板 -使用中出现静态资源加载路径不当的问题 -解决时间:3h
总结 - thymeleaf的模板解析规则不清楚,或者忘了; - 出现bug时,瞎调试, 没有打开NETWORK 进行查看资源的加载情况 - 控制器中的其他代码,可以先注释掉,这样就可以迅速屏蔽掉其他 ...
- spring boot controller路由 url 扫描不到问题
spring boot项目出现controller的路由没被注册,原因:启动类application跟controller不在一个包中,扫描不到controller, 如启动类在com.oyx.a,c ...
随机推荐
- 3. Decision Tree
1. 算法流程 一般的,一颗决策树包含一个根结点.若干内部结点和若干叶结点:叶节点对应于决策结果,其他每个结点则对应于一个属性测试结果:每个结点包含的样本集合根据属性测试的结果被划分到子结点中:根结点 ...
- CentOS7搭建FastDFS V5.11分布式文件系统-第二篇
1.CentOS7 FastDFS搭建 前面已下载好了要用到的工具集,下面就可以开始安装了: 如果安装过程中出现问题,可以下载我提供的,当前测试可以通过的工具包: 点这里点这里 1.1 安装libfa ...
- python操作oracle数据库-查询
python操作oracle数据库-查询 参照文档 http://www.oracle.com/technetwork/cn/articles/dsl/mastering-oracle-python- ...
- POJ 2247
#include<iostream> #include<algorithm> #include<vector> #include<string> #in ...
- POJ 1126
#include <stdio.h> #include <string> #include <iostream> using namespace std; int ...
- Windows10下搭建TensorFlow环境
转载请注明源出处:http://www.cnblogs.com/lighten/p/6753695.html 这篇文章介绍了一下在Windows上安装TensorFlow的步骤,主要是翻译了一下官方的 ...
- spring boot整合RabbitMQ(Fanout模式)
1.Fanout Exchange介绍Fanout Exchange 消息广播的模式,不管路由键或者是路由模式,会把消息发给绑定给它的全部队列,如果配置了routing_key会被忽略. 如上图所示, ...
- 实用的百度下载神奇-proxyee-down
项目地址: https://github.com/monkeyWie/proxyee-down 一.下载适合你的版本 二.运行软件 三.安装证书 四.重启软件和浏览器(注意是浏览器不是客户端),就能看 ...
- Http编程(二)使用Apache 的API实现
要下载jar包 import java.io.FileOutputStream; import java.io.IOException; import org.apache.http.HttpEnti ...
- tomcat启动(四)Catalina分析-server的init()方法
上一回load()方法解析讲到xml解析完成. load()内部接下来会获取server getServer().setCatalina(this); 这个server从createStartDige ...