一个完整的后台项目中踩过的坑

2020-02-25  本文已影响0人  安然在路上

1、同事写的代码已经放到需要返回的BaseResult里了,但是不能返回到前端页面

springMVC的消息转换器(Message Converter)https://www.jianshu.com/p/2f633cb817f5

2、pgsql+tk.mapper新增之后拿不到自增的主键

自己写sql,insert语句之前加上:

<selectKey keyProperty="id" order="BEFORE" resultType="java.lang.Integer">

    SELECT nextval('序列名')  

</selectKey> id也要插入

3、用@Value拿不到配置文件中的值:

使用BeanFactoryPostProcessor的典型应用:PropertyPlaceholderConfigurer,通过实现BeanFactoryPostProcessor接口,BeanFactory会在实例化任何bean之前获得配置信息,从而能够正确解析bean描述文件中的变量引用。

public class PropertyPlaceholder extends PropertyPlaceholderConfigurer {

public static Properties props;

@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
        throws BeansException {
    super.processProperties(beanFactoryToProcess, props);
    PropertyPlaceholder.props = props;
}

public static String getProperty(String key) {
    return PropertyPlaceholder.props.getProperty(key);
}

public static String getProperty(String key, String defaultValue) {
    return PropertyPlaceholder.props.getProperty(key, defaultValue);
}

public Object setProperty(String key, String value) {
    return PropertyPlaceholder.props.setProperty(key, value);
}

}

使用:
@Component
public class AppConstant {

public static String eshp_nas_path=PropertyPlaceholder.getProperty("eshp.nas.path");
public static String iobs_ebcs_bucket_name=PropertyPlaceholder.getProperty("iobs.ebcs.bucketname");
public static String iobs_cacs_bucket_name=PropertyPlaceholder.getProperty("iobs.cacs.bucketname");
public static String iobs_ibcs_bucket_name=PropertyPlaceholder.getProperty("iobs.ibcs.bucketname");

}

上一篇 下一篇

猜你喜欢

热点阅读