spring boot是基于restful吗
1个回答
展开全部
package com.rest.service;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class firstService {
public static void main(String[] args) {
SpringApplication.run(firstService.class, args);
}
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@RestController
public class AppointServiceHandler {
@RequestMapping("/doctor")
public String getDoctor(@RequestParam(value="name",defaultValue="world") String name,@RequestParam(value="id",defaultValue="12") int id){
System.out.println("come in getDoctor");
String msg = ObjectToJSON(new Doctor(id,name));
System.out.println(msg);
return msg;
}
public String ObjectToJSON(Object obj){
JSONObject json = JSONObject.fromObject(obj);
return json.toString();
}
}
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class firstService {
public static void main(String[] args) {
SpringApplication.run(firstService.class, args);
}
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@RestController
public class AppointServiceHandler {
@RequestMapping("/doctor")
public String getDoctor(@RequestParam(value="name",defaultValue="world") String name,@RequestParam(value="id",defaultValue="12") int id){
System.out.println("come in getDoctor");
String msg = ObjectToJSON(new Doctor(id,name));
System.out.println(msg);
return msg;
}
public String ObjectToJSON(Object obj){
JSONObject json = JSONObject.fromObject(obj);
return json.toString();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询