Advertisement
greyflavour

FPT 2019

Feb 28th, 2020
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.84 KB | None | 0 0
  1. <b>190420: json vs rest</b>
  2. - Retrofit (giống browser) -> get json
  3. - Gson -> parse json
  4. jackson
  5. mochi
  6. simple xml -> parse xml
  7.  
  8. - list view, view
  9.  
  10. MainGrid
  11. Background Grid
  12.  
  13.  
  14. <b>190928</b>
  15. ${}
  16. @: link
  17. *
  18. #
  19. field: đối tượng có sẵn -> i18n, làm việc với lỗi
  20.  
  21. chủ thế có jointable/joincolumn -> thao tác
  22. không có mappedby: không phải chủ thế
  23. 1tomany: joincolumn
  24. manytomany: jointable
  25.  
  26.  
  27. <b>191003_security</b>
  28. check authen bằng session
  29. session: tự động trả về sau khi login thành công, tự động ghi cookie bên trình duyệt người dùng, cookie tự động gửi lên trong từng req -> tự động
  30. token: chủ động gửi lên server -> làm thủ công
  31.  
  32. api:
  33.  
  34. component, bean, service, repository -> nhét vào context (implement application context) -> chứa tất cả biến đấy -> lấy biến đây ra
  35.  
  36.  
  37. @Component
  38. public class ApplicationContextHolder implements ApplicationContextAware {
  39.    
  40.     private static ApplicationContext context;
  41. @Override
  42.     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  43.         context = applicationContext;
  44.     }
  45.  
  46.     public static ApplicationContext getContext() {
  47.         return context;
  48.     }
  49. }
  50.  
  51. accountRepository = ApplicationContextHolder.getContext().getBean(AccountRepository.class);
  52.  
  53.  
  54.  
  55. @Bean("messageSource")
  56.     public MessageSource messageSource() {
  57.         ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
  58.         messageSource.setBasename("classpath:locale/language");
  59.         messageSource.setDefaultEncoding("UTF-8");
  60.         messageSource.setUseCodeAsDefaultMessage(true);
  61.         return messageSource;
  62.     }
  63.  
  64. @Configuration
  65. public class ApplicationConfig implements WebMvcConfigurer {
  66.  
  67.     @Bean
  68.     public MessageSource messageSource() {
  69.         ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
  70.         messageSource.setBasename("classpath:locale/message");
  71.         messageSource.setDefaultEncoding("UTF-8");
  72.         messageSource.setUseCodeAsDefaultMessage(true);
  73.         return messageSource;
  74.     }
  75.  
  76.     @Bean
  77.     public LocaleResolver localeResolver() {
  78.         CookieLocaleResolver localeResolver = new CookieLocaleResolver();
  79.         localeResolver.setDefaultLocale(new Locale.Builder().setLanguage("vi").build());
  80.         localeResolver.setCookieName("lang");
  81.         localeResolver.setCookieMaxAge(24  60  60);
  82.         return localeResolver;
  83.     }
  84.  
  85.     @Override
  86.     public void addInterceptors(InterceptorRegistry registry) {
  87.         LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
  88.         localeChangeInterceptor.setParamName("language");
  89.         registry.addInterceptor(localeChangeInterceptor);
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement