首页 > 解决方案 > 是否可以从 jpa/hibernate 获取数据,而无需在 Spring Boot 中定义实体或模型?

问题描述

是否可以从 jpa/hibernate 获取数据,而无需在 Spring Boot 中定义实体或模型?如果可能的话,怎么做?谢谢你...

标签: springoraclehibernatespring-bootspring-data-jpa

解决方案


是的,它可能适用于您首先阅读的服务器端和数据库

https://spring.io/guides/gs/relational-data-access/

对于 restful,您必须使用 RequestEntity<> 来获取没有模型的字段并从 JSON 发送或接收数据。

// Field class is a response and this is not model class
    public class Field{
      private String name;

      //getter and seter
    }



@PostMapping("/test")
public void getFields(RequestEntity<Map<String,String>> entity){

   Field field = new Field();
   field.setName(entity.getBody().get("name"));
   System.out.println(field);
}

推荐阅读