ThymeleafApplication.java 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2012-2018 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. * 本示例参数于:
  17. * https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-ui
  18. */
  19. package com.neo;
  20. import com.neo.model.Message;
  21. import com.neo.repository.InMemoryMessageRepository;
  22. import com.neo.repository.MessageRepository;
  23. import org.springframework.boot.SpringApplication;
  24. import org.springframework.boot.autoconfigure.SpringBootApplication;
  25. import org.springframework.context.annotation.Bean;
  26. import org.springframework.core.convert.converter.Converter;
  27. @SpringBootApplication
  28. public class ThymeleafApplication {
  29. @Bean
  30. public MessageRepository messageRepository() {
  31. return new InMemoryMessageRepository();
  32. }
  33. @Bean
  34. public Converter<String, Message> messageConverter() {
  35. return new Converter<String, Message>() {
  36. @Override
  37. public Message convert(String id) {
  38. return messageRepository().findMessage(Long.valueOf(id));
  39. }
  40. };
  41. }
  42. public static void main(String[] args) {
  43. SpringApplication.run(ThymeleafApplication.class, args);
  44. }
  45. }