I'm trying to get the postgresql table column name. I've tried using information_schema but it doesn't work on my java mvc project. What should I do?
This is actually my first question on StackOverflow, so I'm sorry if my question is difficult to understand. Thank you!
public interface MyFileRepository extends JpaRepository<MyEntityModel, Long> {
@Query("select column_name,data_type from information_schema.columns where table_name = 'MyEntityModel';")
List<MyEntityModel> myList();
}
About schema. You can set default schema by two ways:
Put it to the properties(or.yml file) spring.datasource.schema = #your schema name
Put it in your entity model @Table(schema = "SCHEMA_NAME")
About getting information about table you can look this one open question:
Is there any Simplest way to get Table metadata (column name list) information, in Spring Data JPA? which could I use on universal database
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.