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 ...
随机推荐
- 【xsy1237】 字符转换 矩阵快速幂
题目大意:给你两个长度都为n,字符集为{a,b,c}的字符串S和T. 对于字符串S的任意一个字符,我们可以用cost[0]的代价,把字符a变成字符b.用cost[1]的代价,把字符b变成c,用cost ...
- 【NOIP2016提高组】 Day2 T3 愤怒的小鸟
题目传送门:https://www.luogu.org/problemnew/show/P2831 说个题外话:NOIP2014也有一道题叫做愤怒的小鸟. 这题自测时算错了eps,导致被卡了精度,从1 ...
- selenium+java iframe定位
关于 driver.switchTo().frame(参数).这中间的参数表达有以下几种方式. driver.switchTo().frame(0):用<iframe>标签的位置数量来 ...
- MySQL权限管理(五)
一.什么是MySQL权限 各大帖子及文章都会讲到数据库的权限按最小权限为原则,这句话本身没有错,但是却是一句空话.因为最小权限,这个东西太抽象,很多时候你并弄不清楚具体他需要哪些权限. 现在很多mys ...
- Label Propagation Algorithm LPA 标签传播算法解析及matlab代码实现
转载请注明出处:http://www.cnblogs.com/bethansy/p/6953625.html LPA算法的思路: 首先每个节点有一个自己特有的标签,节点会选择自己邻居中出现次数最多的标 ...
- Kali Linux 弱点分析工具全集
『弱点分析』与『信息收集』类工具的定位非常不同,其中包含大量的模糊测试工具.正确使用这些工具,将有助于我们发现可能存在的零日漏洞.同时此类工具中还包含了大量VoIP相关的渗透测试工具,这可能是安全人员 ...
- (转)rootvg镜像
步骤1:查看当前还未加入到其它vg的可用PV # lspv hdisk0 00027c6a0507fe17 rootvg ...
- SQLServer覆盖索引
为了更好地理解覆盖索引,在正式介绍覆盖索引之前,首先稍微来谈一谈有关索引的一些基础知识. 数据页和索引页 在SQLServer中,数据存储的基本单位是页,一页的大小为8KB,分别由页首,数据行和行偏移 ...
- [webrtc] RTX的处理
以前笔记,整理 webrtc中默认开启rtx用于丢包重传,rtx的介绍可以参考rfc4588,https://tools.ietf.org/html/rfc4588#section-4 rtx使用额外 ...
- springboot自定义错误页面
springboot自定义错误页面 1.加入配置: @Bean public EmbeddedServletContainerCustomizer containerCustomizer() { re ...