回答編集履歴

2

追記

2018/07/26 05:24

投稿

yukihisa
yukihisa

スコア672

test CHANGED
@@ -17,3 +17,163 @@
17
17
 
18
18
 
19
19
  として一週間ごとにリストに格納していけばうまくいくと思いますよ。
20
+
21
+ ### 追記
22
+
23
+
24
+
25
+ もう少し詳しく。
26
+
27
+ クラス
28
+
29
+ ```Java
30
+
31
+ public class week {
32
+
33
+
34
+
35
+ private String[] weekday = new String[6];
36
+
37
+
38
+
39
+ public String getWeekday(int index) {
40
+
41
+ return getWeekday[index];
42
+
43
+ }
44
+
45
+
46
+
47
+ public void setWeekday(int index, String weekday) {
48
+
49
+ this.weekday[index] = weekday;
50
+
51
+ }
52
+
53
+ }
54
+
55
+
56
+
57
+ ```
58
+
59
+ ソース
60
+
61
+ ```Java
62
+
63
+ /* 今月のはじまり(曜日) */
64
+
65
+ rightNow.set(year, month, 1);
66
+
67
+ int startWeek = rightNow.get(Calendar.DAY_OF_WEEK);
68
+
69
+ /* 今月末日 */
70
+
71
+ rightNow.set(year, month + 1, 0);
72
+
73
+ int thisMonthlastDay = rightNow.get(Calendar.DATE);
74
+
75
+ int lastWeek = rightNow.get(Calendar.DAY_OF_WEEK);
76
+
77
+
78
+
79
+ /* 先月末日 */
80
+
81
+ rightNow.set(year, month, 0);
82
+
83
+ int beforeMonthlastDay = rightNow.get(Calendar.DATE);
84
+
85
+
86
+
87
+ List<week> calendarDay = new List<week>(); /* 一週間分データのリスト */
88
+
89
+ int count = 0;
90
+
91
+
92
+
93
+ week week = new week();
94
+
95
+ String strWeekday = new String();
96
+
97
+ // 日曜日始まりでなければ前月の日付を格納する。
98
+
99
+ if (startWeek != 1) {
100
+
101
+ for (int i = startWeek - 2; i >= 0; i--) {
102
+
103
+ strWeekday = String.valueOf(beforeMonthlastDay - i); + " "
104
+
105
+ week.setWeekday(count, strWeekday)
106
+
107
+ count++;
108
+
109
+ }
110
+
111
+ }
112
+
113
+
114
+
115
+ // 当月分の日付を格納する。
116
+
117
+ for (int i = 1; i <= thisMonthlastDay; i++) {
118
+
119
+ if (calendarDay[j] < 10) {
120
+
121
+ strWeekday = " " + String.valueOf(beforeMonthlastDay - i); + " "
122
+
123
+ } else {
124
+
125
+ strWeekday = String.valueOf(beforeMonthlastDay - i); + " "
126
+
127
+ }
128
+
129
+ week.setWeekday(count, strWeekday)
130
+
131
+ if (count == 6) {
132
+
133
+ calendarDay.add(week);
134
+
135
+ count = 0;
136
+
137
+ } else {
138
+
139
+ count++;
140
+
141
+ }
142
+
143
+ }
144
+
145
+
146
+
147
+ // 翌月分の日付を格納する。
148
+
149
+ if (lastWeek != 7) {
150
+
151
+ for (int i = lastWeek; i < 7; i++) {
152
+
153
+ strWeekday = " " + String.valueOf(beforeMonthlastDay - i); + " "
154
+
155
+ week.setWeekday(count, strWeekday)
156
+
157
+ count++;
158
+
159
+ }
160
+
161
+
162
+
163
+ }
164
+
165
+
166
+
167
+ calendarDay.add(week);
168
+
169
+ model.addAttribute("calendarDay", calendarDay);
170
+
171
+
172
+
173
+
174
+
175
+ ```
176
+
177
+
178
+
179
+ これでmodelに格納できると思います。

1

ちょっと修正

2018/07/26 05:24

投稿

yukihisa
yukihisa

スコア672

test CHANGED
@@ -8,9 +8,11 @@
8
8
 
9
9
  ここまでできているようなので、
10
10
 
11
+ weekクラス(mon,tue,...,sunで一週間のデータを格納する)を作って
11
12
 
12
13
 
14
+
13
- List<int[]> calendarDay = new List<int[7]>; /* 一週間分データのリスト */
15
+ List<week> calendarDay = new List<week>; /* 一週間分データのリスト */
14
16
 
15
17
 
16
18