Spring MVC返回到Snake案例中。

时间:2022-09-15 12:58:30

I am stuck with something and need some help. Specifically, I have a POJO defined like this:

我有事要做,需要帮助。具体来说,我有这样一个POJO定义:

private String uid;
private String userName;
private String firstName;
private String lastName;

My DAO looks something like:

我的刀看起来是这样的:

@Override
public AAAUserCountDTO getUserCount(final String userName, final Date startDate, final Date endDate)
        throws BadParameterException {
    final String sql = "select uid, user_name, first_name, last_name from usage where user_name = :user_name and process_time >= :start_date and process_time < :end_date";

    final SqlParameterSource namedParameters = new MapSqlParameterSource().addValue("user_name", userName)
            .addValue("start_date", startDate).addValue("end_date", endDate);

    try {
        return jdbcTemplate.queryForObject(sql, namedParameters,
                new BeanPropertyRowMapper<DTO>(DTO.class).se);

    } catch (EmptyResultDataAccessException e) {
        throw new BadParameterException();
    }
}

I also have this set in my application yml file:

我的应用程序yml文件中也有这个集合:

spring:
   application:
      name: Usage Service
   jackson:
      property-naming-strategy: CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES

My response is looking like:

我的回答是:

uid: 1234,
userName: "Bob",
firstName: "Bob",
lastName: "Hopkins",
etc...

How can I enforce without having to tell each one in the JSON property notation as part of the POJO

如何在无需将JSON属性表示法中的每一个都作为POJO的一部分进行强制执行

Thanks

谢谢

1 个解决方案

#1


1  

This line of code helps:

这行代码有助于:

@Override
public void onApplicationEvent(ObjectMapperConfigured event) {
    event.getObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);        
}

#1


1  

This line of code helps:

这行代码有助于:

@Override
public void onApplicationEvent(ObjectMapperConfigured event) {
    event.getObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);        
}