Java 我想将jdbc语句的结果转换为json,以便能够在postman中看到
这是我的密码 当我转到postman中的url时,我应该看到about_us表的文本字段中有什么Java 我想将jdbc语句的结果转换为json,以便能够在postman中看到,java,spring,spring-boot,Java,Spring,Spring Boot,这是我的密码 当我转到postman中的url时,我应该看到about_us表的文本字段中有什么 @RequestMapping("/about_us") @GetMapping public void about_us() { String x; jdbc.execute("select text from about_us"); } 据我所知,您希望以JSON格式获取或发送请求数据,借助下面的注释,我们可以这样做 @请求主体 Sprin
@RequestMapping("/about_us")
@GetMapping
public void about_us() {
String x;
jdbc.execute("select text from about_us");
}
据我所知,您希望以JSON格式获取或发送请求数据,借助下面的注释,我们可以这样做
@请求主体
Spring automatically deserializes the JSON into a Java type assuming an appropriate one is specified. By default, the type we annotate with the @RequestBody annotation must correspond to the JSON sent from our client-side controller
@应答器
The @ResponseBody annotation tells a controller that the object returned is automatically serialized into JSON and passed back into the HttpResponse object.
您的控制器没有任何响应。
@GetMapping是@RequestMappingmethod=GET的别名。仅使用@GetMapping或@RequestMapping
如果需要json响应,请使用@RestController或@Controller+@ResponseBody
比如说
@RestController
public class YourController {
@GetMapping("/about_us")
public String aboutUs() {
String x;
String text = jdbc.execute("select text from about_us");
return text;
}
}
请提供更多信息;你试过什么?什么不起作用?您的代码在这5行中包含了太多的问题,因此您可能需要在请求工作解决方案之前进行更多的研究。这样您将从中受益更多。它说不能从void转换为string.jdbc.execute。。。这只是一个例子。它不返回实际结果,而是返回结果语句。这不是春天的问题。Java Jdbc编程问题。