【Android免费音乐下载app】【佳语音乐下载】建议最少2.0.3版本。最新版本:
https://gitlab.com/gaopinqiang/checkversion/raw/master/Music_Download.apk
Spring boot下的Spring mvc 和之前的Spring mvc使用是完全一样的:
1、@Controller
即为Spring mvc的注解,处理http请求;
2、@RestController
Spring4后新增注解;是@Controller与@ResponseBody的组合注解;用于返回字符串或json数据;
示例:
创建一个MVCController
package com.springboot.web.controller;
import com.springboot.web.model.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController//相当于@Controller与@ResponseBody的组合,里面所有的方法都返回的是json格式数据
public class MVCController {
@RequestMapping("/getUser")
public Object getUser(){//加了@RestController注解就不需要@ResponseBody了,直接返回Object
User user = new User();
user.setId(100);
user.setName("qiang");
return user;
}
}
创建一个model包,里面写个User类存放数据
package com.springboot.web.model;
public class User {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
去浏览器中请求:http://localhost:8081/getUser
输出结果:{“id”:100,“name”:“qiang”}
3、@GetMapping
RequestMapping 和 Get请求方法的组合;
示例:
MVCController中增加一个getUser1方法
@GetMapping("/getUser1")//只支持get请求 @GetMapping 等价于 @RequestMapping(value = "/getUser1",method = RequestMethod.GET)
public Object getUser1(){
User user = new User();
user.setId(101);
user.setName("qiang1");
return user;
}
去浏览器中请求:http://localhost:8081/getUser1
输出结果:{“id”:101,“name”:“qiang1”}
4、@PostMapping
RequestMapping 和 Post请求方法的组合;
如果是get请求就会不支持
示例:
MVCController中增加一个getUser2方法
@PostMapping("/getUser2")//只支持get请求 @GetMapping 等价于 @RequestMapping(value = "/getUser2",method = RequestMethod.POST)
public Object getUser2(){
User user = new User();
user.setId(102);
user.setName("qiang2");
return user;
}
去浏览器中请求:http://localhost:8081/getUser2
输出结果:会提示不支持get
5、@PutMapping
RequestMapping 和 Put请求方法的组合;
比较少使用
6、@DeleteMapping
RequestMapping 和 Delete请求方法的组合;
比较少使用