Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
johntostring opened this issue Aug 21, 2015 · 1 comment
Open

Comments

@johntostring
Copy link

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();
    }

}
@rbygrave
Copy link
Member

Ok, I have dropped the ball on this one. Should get to it shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants