jpa创建表时字段大写
在 application.properties里面添加如下内容即可
spring.jpa.hibernate.naming.physical-strategy = cn.studyBoot.dao.strategy.UpperTableStrategy

  

import org.apache.commons.lang3.StringUtils;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;

/**
 * @Author: luojie
 * @Date: 2023/4/25 10:47
 */
public class UpperCaseStrategy extends PhysicalNamingStrategyStandardImpl {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    @Override
    public Identifier toPhysicalSchemaName(Identifier name, JdbcEnvironment context) {
        if(name != null){
            String schemaName = name.getText();
            if(StringUtils.isNotBlank(schemaName)){
                schemaName = "\""+schemaName.toUpperCase()+"\"";
                return name.toIdentifier(schemaName);
            }
        }
        return super.toPhysicalSchemaName(name, context);
    }

    @Override
    public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
        //mysql用这个
//        String tableName = name.getText().toLowerCase();
        //postgres用这个
        String tableName = "\""+name.getText().toUpperCase()+"\"";
        return name.toIdentifier(tableName);
    }

    @Override
    public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment context) {
        //mysql用这个
//        String colnumName = name.getText().toLowerCase();
        //postgres用这个
        String colnumName = "\""+name.getText().toUpperCase()+"\"";
        return name.toIdentifier(colnumName);
    }

}

  

postgres的问题

 

posted on 2023-02-27 14:33  james-roger  阅读(105)  评论(0编辑  收藏  举报