Compare commits
2 Commits
cb31c17ce4
...
da04f6b766
Author | SHA1 | Date | |
---|---|---|---|
da04f6b766 | |||
1935eb352e |
@@ -2,9 +2,7 @@ package com.inmind.controller;
|
|||||||
|
|
||||||
import com.inmind.pojo.User;
|
import com.inmind.pojo.User;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -83,4 +81,19 @@ public class RequestController {
|
|||||||
System.out.println(updateTime.getDayOfMonth());
|
System.out.println(updateTime.getDayOfMonth());
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//接收json请求数据
|
||||||
|
@RequestMapping("/jsonParam")
|
||||||
|
public String jsonParam(@RequestBody User user){
|
||||||
|
System.out.println(user);
|
||||||
|
return "OK";
|
||||||
|
}
|
||||||
|
|
||||||
|
//路径参数(REST风格)
|
||||||
|
@RequestMapping("/path/{id}/{name}")
|
||||||
|
public String pathParam(@PathVariable Integer id,@PathVariable String name) {
|
||||||
|
System.out.println("id:"+id+"name:"+name);
|
||||||
|
return "OK";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,82 @@
|
|||||||
|
package com.inmind.controller;
|
||||||
|
|
||||||
|
import com.inmind.pojo.Address;
|
||||||
|
import com.inmind.pojo.Result;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController//RestController中包含@ResponseBody,如果在类上添加了@ResponseBody,那就代表类中所有方法上都设置了@ResponseBody
|
||||||
|
public class ResponseController {
|
||||||
|
|
||||||
|
/*//响应普通的字符串
|
||||||
|
@RequestMapping("/hello")
|
||||||
|
public String hello(){
|
||||||
|
System.out.println("hello World");
|
||||||
|
return "hello World";
|
||||||
|
}
|
||||||
|
|
||||||
|
//响应对象
|
||||||
|
@RequestMapping("/getAddr")
|
||||||
|
public Address getAddr(){
|
||||||
|
Address address = new Address();
|
||||||
|
address.setProvince("江苏");
|
||||||
|
address.setCity("常州");
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
//响应集合
|
||||||
|
@RequestMapping("/listAddr")
|
||||||
|
public List<Address> listAddr(){
|
||||||
|
ArrayList<Address> list = new ArrayList<>();
|
||||||
|
|
||||||
|
Address address = new Address();
|
||||||
|
address.setProvince("江苏");
|
||||||
|
address.setCity("常州");
|
||||||
|
|
||||||
|
list.add(address);
|
||||||
|
Address address1 = new Address();
|
||||||
|
address1.setProvince("江苏");
|
||||||
|
address1.setCity("苏州");
|
||||||
|
|
||||||
|
list.add(address1);
|
||||||
|
return list;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
//响应普通的字符串
|
||||||
|
@RequestMapping("/hello")
|
||||||
|
public Result hello(){
|
||||||
|
System.out.println("hello World");
|
||||||
|
return new Result(1,"成功","hello world");
|
||||||
|
}
|
||||||
|
|
||||||
|
//响应对象
|
||||||
|
@RequestMapping("/getAddr")
|
||||||
|
public Result getAddr(){
|
||||||
|
Address address = new Address();
|
||||||
|
address.setProvince("江苏");
|
||||||
|
address.setCity("常州");
|
||||||
|
return new Result(1,"成功",address);
|
||||||
|
}
|
||||||
|
|
||||||
|
//响应集合
|
||||||
|
@RequestMapping("/listAddr")
|
||||||
|
public Result listAddr(){
|
||||||
|
ArrayList<Address> list = new ArrayList<>();
|
||||||
|
|
||||||
|
Address address = new Address();
|
||||||
|
address.setProvince("江苏");
|
||||||
|
address.setCity("常州");
|
||||||
|
|
||||||
|
list.add(address);
|
||||||
|
Address address1 = new Address();
|
||||||
|
address1.setProvince("江苏");
|
||||||
|
address1.setCity("苏州");
|
||||||
|
|
||||||
|
list.add(address1);
|
||||||
|
return new Result(1,"成功",list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,49 @@
|
|||||||
|
package com.inmind.pojo;
|
||||||
|
|
||||||
|
public class Result {
|
||||||
|
private Integer code;//1:成功 0:失败
|
||||||
|
private String msg;//提示信息
|
||||||
|
private Object data;//数据data
|
||||||
|
|
||||||
|
public Result() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result(Integer code, String msg, Object data) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(Integer code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(Object data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Result{" +
|
||||||
|
"code=" + code +
|
||||||
|
", msg='" + msg + '\'' +
|
||||||
|
", data=" + data +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user