Skip to content

I'm using Spring MVC. How to customize the date format pattern #4

@johntostring

Description

@johntostring

Didn't work like this way

public class StartupListener implements ServerConfigStartup {

    @Override
    public void onStart(ServerConfig serverConfig) {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setDateFormat(new SimpleDateFormat("yyyy年MM月dd日 HH点mm分ss秒"));
        serverConfig.setObjectMapper(objectMapper);
        //serverConfig.setJsonDateTime(JsonConfig.DateTime.ISO8601);
    }
}
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {

    private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);

    static {
        if (!AgentLoader.loadAgentFromClasspath(
                "avaje-ebeanorm-agent",
                "debug=1;packages=com.millinch.ebean.demo.domain")) {
            LOGGER.info("avaje-ebeanorm-agent not found in classpath - not dynamically loaded");
        }
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public ObjectMapper objectMapper(){
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setDateFormat(new SimpleDateFormat("yyyy年MM月dd日 HH点mm分ss秒"));
        objectMapper.registerModule(new JacksonEbeanModule());
        return objectMapper;
    }

    @Bean
    public MappingJackson2JsonView mappingJackson2JsonView() {
        MappingJackson2JsonView jsonView = new MappingJackson2JsonView();
        jsonView.setObjectMapper(objectMapper());
        return jsonView;
    }

    @Bean
    public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(){
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        converter.setObjectMapper(objectMapper());
        return converter;
    }
}
@RestController
public class UserApi {

    @RequestMapping(value = "/user")
    public List<User> getUsers() {
        return User.find.findList();
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions