Commit b66e78dada8f71be944e9ca50e8c93baf76172e3
1 parent
3e580097
1.国际化占位
Showing
5 changed files
with
56 additions
and
47 deletions
Too many changes to show.
To preserve performance only 5 of 354 files are displayed.
src/main/java/com/bsth/common/ResponseCode.java
| 1 | -package com.bsth.common; | ||
| 2 | - | ||
| 3 | -/** | ||
| 4 | - * | ||
| 5 | - * @ClassName: ResponseCode | ||
| 6 | - * @Description: TODO(响应状态码) | ||
| 7 | - * @author PanZhao | ||
| 8 | - * @date 2016年3月18日 下午11:12:08 | ||
| 9 | - * | ||
| 10 | - */ | ||
| 11 | -public enum ResponseCode { | ||
| 12 | - | ||
| 13 | - SUCCESS("$$$$$${txt-3324}", 200), | ||
| 14 | - NO_PERMISSION("无资源访问权限", 403), | ||
| 15 | - NO_AUTHENTICATION("客户端未授权", 407), | ||
| 16 | - ERROR("服务器异常", 500); | ||
| 17 | - | ||
| 18 | - private String text; | ||
| 19 | - private int code; | ||
| 20 | - | ||
| 21 | - ResponseCode(String text, int code) { | ||
| 22 | - this.text = text; | ||
| 23 | - this.code = code; | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | - @Override | ||
| 27 | - public String toString() { | ||
| 28 | - return this.code + ""; | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - public String getText() { | ||
| 32 | - return this.text; | ||
| 33 | - } | ||
| 34 | -} | 1 | +package com.bsth.common; |
| 2 | + | ||
| 3 | +import com.bsth.util.I18n; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * | ||
| 7 | + * @ClassName: ResponseCode | ||
| 8 | + * @Description: TODO(响应状态码) | ||
| 9 | + * @author PanZhao | ||
| 10 | + * @date 2016年3月18日 下午11:12:08 | ||
| 11 | + * | ||
| 12 | + */ | ||
| 13 | +public enum ResponseCode { | ||
| 14 | + | ||
| 15 | + SUCCESS(I18n.getInstance().getMessage("txt-3324"), 200), | ||
| 16 | + NO_PERMISSION("无资源访问权限", 403), | ||
| 17 | + NO_AUTHENTICATION("客户端未授权", 407), | ||
| 18 | + ERROR("服务器异常", 500); | ||
| 19 | + | ||
| 20 | + private String text; | ||
| 21 | + private int code; | ||
| 22 | + | ||
| 23 | + ResponseCode(String text, int code) { | ||
| 24 | + this.text = text; | ||
| 25 | + this.code = code; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + @Override | ||
| 29 | + public String toString() { | ||
| 30 | + return this.code + ""; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public String getText() { | ||
| 34 | + return this.text; | ||
| 35 | + } | ||
| 36 | +} |
src/main/java/com/bsth/data/gpsdata_v2/GpsRealData.java
| @@ -41,9 +41,6 @@ public class GpsRealData { | @@ -41,9 +41,6 @@ public class GpsRealData { | ||
| 41 | @Autowired | 41 | @Autowired |
| 42 | ForecastRealServer forecastRealServer; | 42 | ForecastRealServer forecastRealServer; |
| 43 | 43 | ||
| 44 | - @Autowired | ||
| 45 | - private I18n i18n; | ||
| 46 | - | ||
| 47 | /** | 44 | /** |
| 48 | * 构造函数 | 45 | * 构造函数 |
| 49 | */ | 46 | */ |
| @@ -159,7 +156,7 @@ public class GpsRealData { | @@ -159,7 +156,7 @@ public class GpsRealData { | ||
| 159 | gps.setSchId(sch.getId()); | 156 | gps.setSchId(sch.getId()); |
| 160 | if(!sch.getXlBm().equals(lineCode)){ | 157 | if(!sch.getXlBm().equals(lineCode)){ |
| 161 | //车辆在其他线路营运 | 158 | //车辆在其他线路营运 |
| 162 | - gps.setRemark(i18n.getMessage("txt-4445", new String[]{ sch.getXlName(), sch.getDfsj()})); | 159 | + gps.setRemark(I18n.getInstance().getMessage("txt-4445", sch.getXlName(), sch.getDfsj())); |
| 163 | gps.setPlanCode(sch.getXlBm()); | 160 | gps.setPlanCode(sch.getXlBm()); |
| 164 | } | 161 | } |
| 165 | }else | 162 | }else |
src/main/java/com/bsth/service/gps/GpsServiceImpl.java
| @@ -122,9 +122,6 @@ public class GpsServiceImpl implements GpsService { | @@ -122,9 +122,6 @@ public class GpsServiceImpl implements GpsService { | ||
| 122 | @Autowired | 122 | @Autowired |
| 123 | LsSectionRouteRepository lsSectionRouteRepository; | 123 | LsSectionRouteRepository lsSectionRouteRepository; |
| 124 | 124 | ||
| 125 | - @Autowired | ||
| 126 | - private I18n i18n; | ||
| 127 | - | ||
| 128 | // 历史gps查询 | 125 | // 历史gps查询 |
| 129 | @Override | 126 | @Override |
| 130 | public List<Map<String, Object>> history(String device, Long startTime, Long endTime, int directions) { | 127 | public List<Map<String, Object>> history(String device, Long startTime, Long endTime, int directions) { |
| @@ -973,7 +970,7 @@ public class GpsServiceImpl implements GpsService { | @@ -973,7 +970,7 @@ public class GpsServiceImpl implements GpsService { | ||
| 973 | 970 | ||
| 974 | st = st * 1000; | 971 | st = st * 1000; |
| 975 | et = et * 1000; | 972 | et = et * 1000; |
| 976 | - String filename = i18n.getMessage("$$$$$${txt-3320}", new String[] { nbbm, fmt.print(st), fmt.print(et)}); | 973 | + String filename = I18n.getInstance().getMessage("$$$$$${txt-3320}", new String[] { nbbm, fmt.print(st), fmt.print(et)}); |
| 977 | try { | 974 | try { |
| 978 | resp.setContentType("application/x-msdownload"); | 975 | resp.setContentType("application/x-msdownload"); |
| 979 | resp.addHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8")); | 976 | resp.addHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8")); |
src/main/java/com/bsth/service/sys/impl/SysUserServiceImpl.java
| @@ -43,9 +43,6 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, Integer> implem | @@ -43,9 +43,6 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, Integer> implem | ||
| 43 | @Autowired | 43 | @Autowired |
| 44 | private MailUtils mailUtils; | 44 | private MailUtils mailUtils; |
| 45 | 45 | ||
| 46 | - @Autowired | ||
| 47 | - private I18n i18n; | ||
| 48 | - | ||
| 49 | Logger logger = LoggerFactory.getLogger(this.getClass()); | 46 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 50 | 47 | ||
| 51 | @Override | 48 | @Override |
| @@ -104,7 +101,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, Integer> implem | @@ -104,7 +101,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUser, Integer> implem | ||
| 104 | //检查用户名是否存在 | 101 | //检查用户名是否存在 |
| 105 | if(findByUserName(u.getUserName()) != null){ | 102 | if(findByUserName(u.getUserName()) != null){ |
| 106 | rs.put("status", ResponseCode.ERROR); | 103 | rs.put("status", ResponseCode.ERROR); |
| 107 | - rs.put("msg", i18n.getMessage("txt-4421", new String[]{ u.getUserName() })); | 104 | + rs.put("msg", I18n.getInstance().getMessage("txt-4421", u.getUserName())); |
| 108 | } | 105 | } |
| 109 | else{ | 106 | else{ |
| 110 | u.setPassword(new BCryptPasswordEncoder(4).encode(u.getPassword())); | 107 | u.setPassword(new BCryptPasswordEncoder(4).encode(u.getPassword())); |
src/main/java/com/bsth/util/I18n.java
| 1 | package com.bsth.util; | 1 | package com.bsth.util; |
| 2 | 2 | ||
| 3 | +import org.springframework.beans.factory.InitializingBean; | ||
| 3 | import org.springframework.beans.factory.annotation.Autowired; | 4 | import org.springframework.beans.factory.annotation.Autowired; |
| 4 | import org.springframework.context.MessageSource; | 5 | import org.springframework.context.MessageSource; |
| 5 | import org.springframework.stereotype.Component; | 6 | import org.springframework.stereotype.Component; |
| @@ -11,13 +12,23 @@ import java.util.Locale; | @@ -11,13 +12,23 @@ import java.util.Locale; | ||
| 11 | * @Author hill | 12 | * @Author hill |
| 12 | */ | 13 | */ |
| 13 | @Component | 14 | @Component |
| 14 | -public class I18n { | 15 | +public class I18n implements InitializingBean { |
| 15 | 16 | ||
| 16 | private ThreadLocal<Locale> locales = new ThreadLocal<>(); | 17 | private ThreadLocal<Locale> locales = new ThreadLocal<>(); |
| 17 | 18 | ||
| 18 | @Autowired | 19 | @Autowired |
| 19 | private MessageSource messageSource; | 20 | private MessageSource messageSource; |
| 20 | 21 | ||
| 22 | + private static I18n i18n; | ||
| 23 | + | ||
| 24 | + public static I18n getInstance() { | ||
| 25 | + if (i18n == null) { | ||
| 26 | + throw new RuntimeException("I18n not initialized"); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + return i18n; | ||
| 30 | + } | ||
| 31 | + | ||
| 21 | public void setLocale(Locale locale) { | 32 | public void setLocale(Locale locale) { |
| 22 | locales.set(locale); | 33 | locales.set(locale); |
| 23 | } | 34 | } |
| @@ -44,4 +55,9 @@ public class I18n { | @@ -44,4 +55,9 @@ public class I18n { | ||
| 44 | 55 | ||
| 45 | return result; | 56 | return result; |
| 46 | } | 57 | } |
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public void afterPropertiesSet() throws Exception { | ||
| 61 | + i18n = this; | ||
| 62 | + } | ||
| 47 | } | 63 | } |