【发布时间】:2018-01-16 09:44:17
【问题描述】:
实际上,我在 Spring 中的项目通过控制台从数据库发送值,如下所示: Console image,但我想像其他 API 一样通过 JSON 发送这些值,但我不知道如何更改。
{
"depositarios": {
"correo": "correo",
"nombre": "nombre",
"numTel": "numTel",
"pApellido": "pApellido",
"SApellido": "sAellido"
}
}
这是我的主要课程:
@SpringBootApplication
@ComponentScan("com.abner.springpostgresql.service.impl, com.abner.springpostgresql.dao.imp")
public class SpringPostgresqlApplication {
public static void main(String[] args) {
ApplicationContext context= SpringApplication.run(SpringPostgresqlApplication.class, args);
depoService depoService =context.getBean(depoService.class);
depoService.loadAllDepo();
}
}
【问题讨论】:
-
但是您想在控制台中将对象打印为 json 还是将 json 作为 REST API 返回?
-
@JuanCarlosMendoza 作为 REST API
-
@JuanCarlosMendoza 我用源项目更新了我的问题。
-
我在您的源代码中没有看到控制器。您是否检查了我的答案并尝试了该解决方案?
-
我一直在关注这个example
标签: json spring rest spring-boot spring-data