翻译月份名称回复
translate month name response
我有一个名为 CREATED_AT 的 table
我写了一个查询并收到这样的回复:
Score D
27 01
17 02
80 03
55 06
这是我的查询:
SELECT SUM(AMOUNT) as scores,to_char(CREATED_AT, 'MONTH') as d
FROM C_SCORES
WHERE USER_ID =201 and to_char(CREATED_AT, 'YYYY') ='1398'
GROUP BY to_char(CREATED_AT, 'MONTH');
实体代码为:
public class ScoreCategorizeWithMonth {
private int Scores;
private int month;
private String monthfa;
public String getMonthfa() {
switch (month) {
case 1:
monthfa = "فروردین";
break;
case 2:
monthfa = "اردیبهشت";
break;
case 3:
monthfa = "خرداد";
break;
case 4:
monthfa = "تیر";
break;
case 5:
monthfa = "مرداد";
break;
case 6:
monthfa = "شهریور";
break;
case 7:
monthfa = "مهر";
break;
case 8:
monthfa = "آبان";
break;
case 9:
monthfa = "آذر";
break;
case 10:
monthfa = "دی";
break;
case 11:
monthfa = "بهمن";
break;
case 12:
monthfa = "اسفند";
default:
monthfa = "";
}
return monthfa;
}
}
此代码在控制器中:
@GetMapping(value = "score-Categorize-months")
public List<ScoreCategorizeWithMonth> scoreCategorizedWithMonths()
{
return iScoresSrv.scoreCategorizeWithMonths(userInfo.getUserId());
}
我的问题是:
2- 我的回答是 database.how 中存在的月份,以显示即使它不在数据库中的月份
{
"scores": 27,
"month": 1,
"monthfa": "فروردین"
},
{
"scores": 17,
"month": 2,
"monthfa": "اردیبهشت"
},
{
"scores": 84,
"month": 3,
"monthfa": "خرداد"
},
{
"scores": 55,
"month": 6,
"monthfa": "شهریور"
}
我还想显示分数为 0 的 4..5 月份
谢谢
您可以使用属性文件...
此 link 提供了众多示例中的一个:
http://zetcode.com/java/resourcebundle/
在该教程中,'words.properties'
是您的默认和后备语言文件,words_de.properties
和 words_sk.properties
是自定义翻译语言
在这一行中:source.setBasenames("messages/words");
他试图将翻译文件传递给算法。
并使用 messageSource.getMessage("w1", null, Locale.GERMAN)
他获取了所需的语言....
注意 words_sk.properties
中的 sk
是语言 iso 代码,波斯语是 fa
,英语是 en
...
一些系统也使用本地化,它们定义自定义字符和格式,我不确定这个算法是否支持那种命名......你传递一个额外的参数: fa-IR
,或者en-US
说实话我看的不深,但是我几年前用过,就是这个原理
第 2 步和第 3 步:您可以通过以下查询实现:
select sum(AMOUNT) as scores, month from
(select AMOUNT ,to_char(CREATED_AT, 'MONTH') as month from C_SCORES WHERE USER_ID
=201 and to_char(CREATED_AT, 'YYYY') ='1398'
union
select 0 as AMOUNT, Month from
(SELECT 1 AS MONTH
UNION SELECT 2 AS MONTH
UNION SELECT 3 AS MONTH
UNION SELECT 4 AS MONTH
UNION SELECT 5 AS MONTH
UNION SELECT 6 AS MONTH
UNION SELECT 7 AS MONTH
UNION SELECT 8 AS MONTH
UNION SELECT 9 AS MONTH
UNION SELECT 10 AS MONTH
UNION SELECT 11 AS MONTH
UNION SELECT 12 AS MONTH) TBL1) TBL2
group by month;
只需将 1-12 替换为您的月份值即可
我只是在 java 中添加了 sume 代码来填充无效的索引。
很容易解决。但我有点困惑,none 的答案对我没有帮助
public List<ScoreCategorizedWithMonth> scoreCategorizeWithMonths(Long userId) {
List<ScoreCategorizedWithMonth> monthCategory = scoreDao.scoreCategorizeWithMonths(userId);
List<ScoreCategorizedWithMonth> result = new ArrayList<>();
for (int i=1; i<=12;i++)
{
ScoreCategorizedWithMonth scoreCategorizedWithMonth = checkMonthCatIsExist(i, monthCategory);
result.add(scoreCategorizedWithMonth);
}
return result;
}
private ScoreCategorizedWithMonth checkMonthCatIsExist(int month, List<ScoreCategorizedWithMonth> monthCategory) {
for (ScoreCategorizedWithMonth cat:monthCategory) {
if(cat.getMonth() == month){
return cat;
}
}
ScoreCategorizedWithMonth temp= new ScoreCategorizedWithMonth();
temp.setMonth(month);
temp.setScores(0);
return temp;
}
我有一个名为 CREATED_AT 的 table
我写了一个查询并收到这样的回复:
Score D
27 01
17 02
80 03
55 06
这是我的查询:
SELECT SUM(AMOUNT) as scores,to_char(CREATED_AT, 'MONTH') as d
FROM C_SCORES
WHERE USER_ID =201 and to_char(CREATED_AT, 'YYYY') ='1398'
GROUP BY to_char(CREATED_AT, 'MONTH');
实体代码为:
public class ScoreCategorizeWithMonth {
private int Scores;
private int month;
private String monthfa;
public String getMonthfa() {
switch (month) {
case 1:
monthfa = "فروردین";
break;
case 2:
monthfa = "اردیبهشت";
break;
case 3:
monthfa = "خرداد";
break;
case 4:
monthfa = "تیر";
break;
case 5:
monthfa = "مرداد";
break;
case 6:
monthfa = "شهریور";
break;
case 7:
monthfa = "مهر";
break;
case 8:
monthfa = "آبان";
break;
case 9:
monthfa = "آذر";
break;
case 10:
monthfa = "دی";
break;
case 11:
monthfa = "بهمن";
break;
case 12:
monthfa = "اسفند";
default:
monthfa = "";
}
return monthfa;
}
}
此代码在控制器中:
@GetMapping(value = "score-Categorize-months")
public List<ScoreCategorizeWithMonth> scoreCategorizedWithMonths()
{
return iScoresSrv.scoreCategorizeWithMonths(userInfo.getUserId());
}
我的问题是:
2- 我的回答是 database.how 中存在的月份,以显示即使它不在数据库中的月份
{
"scores": 27,
"month": 1,
"monthfa": "فروردین"
},
{
"scores": 17,
"month": 2,
"monthfa": "اردیبهشت"
},
{
"scores": 84,
"month": 3,
"monthfa": "خرداد"
},
{
"scores": 55,
"month": 6,
"monthfa": "شهریور"
}
我还想显示分数为 0 的 4..5 月份
谢谢
您可以使用属性文件...
此 link 提供了众多示例中的一个: http://zetcode.com/java/resourcebundle/
在该教程中,'words.properties'
是您的默认和后备语言文件,words_de.properties
和 words_sk.properties
是自定义翻译语言
在这一行中:source.setBasenames("messages/words");
他试图将翻译文件传递给算法。
并使用 messageSource.getMessage("w1", null, Locale.GERMAN)
他获取了所需的语言....
注意 words_sk.properties
中的 sk
是语言 iso 代码,波斯语是 fa
,英语是 en
...
一些系统也使用本地化,它们定义自定义字符和格式,我不确定这个算法是否支持那种命名......你传递一个额外的参数: fa-IR
,或者en-US
说实话我看的不深,但是我几年前用过,就是这个原理
第 2 步和第 3 步:您可以通过以下查询实现:
select sum(AMOUNT) as scores, month from
(select AMOUNT ,to_char(CREATED_AT, 'MONTH') as month from C_SCORES WHERE USER_ID
=201 and to_char(CREATED_AT, 'YYYY') ='1398'
union
select 0 as AMOUNT, Month from
(SELECT 1 AS MONTH
UNION SELECT 2 AS MONTH
UNION SELECT 3 AS MONTH
UNION SELECT 4 AS MONTH
UNION SELECT 5 AS MONTH
UNION SELECT 6 AS MONTH
UNION SELECT 7 AS MONTH
UNION SELECT 8 AS MONTH
UNION SELECT 9 AS MONTH
UNION SELECT 10 AS MONTH
UNION SELECT 11 AS MONTH
UNION SELECT 12 AS MONTH) TBL1) TBL2
group by month;
只需将 1-12 替换为您的月份值即可
我只是在 java 中添加了 sume 代码来填充无效的索引。 很容易解决。但我有点困惑,none 的答案对我没有帮助
public List<ScoreCategorizedWithMonth> scoreCategorizeWithMonths(Long userId) {
List<ScoreCategorizedWithMonth> monthCategory = scoreDao.scoreCategorizeWithMonths(userId);
List<ScoreCategorizedWithMonth> result = new ArrayList<>();
for (int i=1; i<=12;i++)
{
ScoreCategorizedWithMonth scoreCategorizedWithMonth = checkMonthCatIsExist(i, monthCategory);
result.add(scoreCategorizedWithMonth);
}
return result;
}
private ScoreCategorizedWithMonth checkMonthCatIsExist(int month, List<ScoreCategorizedWithMonth> monthCategory) {
for (ScoreCategorizedWithMonth cat:monthCategory) {
if(cat.getMonth() == month){
return cat;
}
}
ScoreCategorizedWithMonth temp= new ScoreCategorizedWithMonth();
temp.setMonth(month);
temp.setScores(0);
return temp;
}