
プログラミング未経験の初心者です。また、こちらのサイトでの質問が初めてなので至らぬ点ばかりかと思いますが、
どうかお知恵をお貸しいただければ幸いです。
前提・実現したいこと
Springとthymeleafを使ってHTML上にカレンダーを表示させたい
該当のソースコード
java
1@Controller 2@RequestMapping(value = "topPage") 3public class TopPageController { 4 5 @Autowired 6 private ScheduleService scheduleService; 7 8 @Autowired 9 private User user; 10 11 @RequestMapping(value = "getPage", method = RequestMethod.GET) 12 public String getPage(LoginForm form, Model model) { 13 14 Calendar rightNow = Calendar.getInstance(); 15 int day = rightNow.get(Calendar.DATE); 16 int year = rightNow.get(Calendar.YEAR); 17 int month = rightNow.get(Calendar.MONTH); 18 19 /* 今月のはじまり */ 20 rightNow.set(year, month, 1); 21 int startWeek = rightNow.get(Calendar.DAY_OF_WEEK); 22 23 /* 先月分の日数 */ 24 rightNow.set(year, month, 0); 25 int beforeMonthlastDay = rightNow.get(Calendar.DATE); 26 27 /* 今月分の日数 */ 28 rightNow.set(year, month + 1, 0); 29 int thisMonthlastDay = rightNow.get(Calendar.DATE); 30 31 int[] calendarDay = new int[42]; /* 最大で7日×6週 */ 32 int count = 0; 33 34 for (int i = startWeek - 2; i >= 0; i--) { 35 calendarDay[count++] = beforeMonthlastDay - i; 36 } 37 38 for (int i = 1; i <= thisMonthlastDay; i++) { 39 calendarDay[count++] = i; 40 } 41 42 int nextMonthDay = 1; 43 while (count % 7 != 0) { 44 calendarDay[count++] = nextMonthDay++; 45 } 46 47 int weekCount = count / 7; 48 49 for (int i = 0; i < weekCount; i++) { 50 for (int j = i * 7; j < i * 7 + 7; j++) { 51 if (calendarDay[j] < 10) { 52 System.out.print(" " + calendarDay[j] + " "); 53 } else { 54 System.out.print(calendarDay[j] + " "); 55 56 } 57 } 58 System.out.println(); 59 } 60 61 62 return "mypage"; 63 }
HTML
1<!DOCTYPE html> 2<html xmlns:th="http://www.thymeleaf.org"> 3<head> 4 5<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 6<meta http-equiv="Content-Style-Type" content="text/css" /> 7<meta http-equiv="Content-Script-Type" content="text/javascript" /> 8<meta http-equiv="Pragma" content="no-cache" /> 9<meta http-equiv="Cache-Control" content="no-cache" /> 10<meta http-equiv="Expires" content="0" /> 11 12<meta http-equiv="imagetoolbar" content="no" /> 13<title>スケジュール管理</title> 14 15</head> 16 17<body> 18 <h3>スケジュール管理</h3> 19<table> 20 <tr> 21 <td class="week">日</td> 22 <td class="week">月</td> 23 <td class="week">火</td> 24 <td class="week">水</td> 25 <td class="week">木</td> 26 <td class="week">金</td> 27 <td class="week">土</td> 28 </tr> 29!この部分にカレンダーを表示させたいです。! 30</table> 31</body> 32</html>
Javaのソースコード上に記載した、for文でコンソール上にカレンダーを出力させた流れを
thymeleafを使って、HTML上に同じように出力できるようにさせたいのですが、初心者のため解決策が思い浮かびません。もし、何か方法がございましたらご教示いただければ幸いです。


あなたの回答
tips
プレビュー