0

以下の質問の続きとなります。

SpringBootにて、List内の要素を一つずつHTML側に表示したい

Spring Bootでカレンダーを作成しており、日付を押下した際に該当の日付に対してスケジュールがあった場合、DBからその内容を呼び出し、更新があった場合の処理を記載しています。
入力フォーム内を変更後にボタンを押下すると以下エラーが発生してしまい更新できませんでした。

There was an unexpected error (type=Internal Server Error, status=500).
Mapper method 'com.example.demo.repository.PlanMapper.update' has an unsupported return type: interface java.util.List
org.apache.ibatis.binding.BindingException: Mapper method 'com.example.demo.repository.PlanMapper.update' has an unsupported return type: interface java.util.List

お手数ですが、記載のソースコード以外で良きアイデア等ございましたら、ご教示いただけますと幸いです。

MainController

package com.example.demo.controller;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.temporal.TemporalField;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.example.demo.entity.Day;
import com.example.demo.entity.MyCalendar;
import com.example.demo.entity.Plan_search;
import com.example.demo.service.PlanService;

@Controller
public class MainController {
    
    @Autowired
    private PlanService planService;
    
    /* Calendar画面 */
    
    // 週の始まりが日曜日
    private static final TemporalField DAY_OF_WEEK = WeekFields.SUNDAY_START.dayOfWeek();
    
    @GetMapping("/")
    public String calendar(final Model model) {
        // 今日
        final LocalDate today = LocalDate.now();
        // 今月初日
        final LocalDate beginOfMonth = today.withDayOfMonth(1);
        // 今月末日
        final LocalDate endOfMonth = today.withDayOfMonth(today.lengthOfMonth());
        // カレンダー初日
        // 月曜日の週の1日目(=日曜日)
        final LocalDate beginOfCalendar = beginOfMonth.with(DAY_OF_WEEK, 1);
        // カレンダーの末日
        // 月末日の週の7日目(=土曜日)
        final LocalDate endOfCalendar = endOfMonth.with(DAY_OF_WEEK, 7);
        
        final List<List<Day>> weeks = new ArrayList<>();
        for (LocalDate day = beginOfCalendar; day.isBefore(endOfCalendar);) {
            final List<Day> week = new ArrayList<>();
            weeks.add(week);
            for (int i = 0; i < 7; i++) {
                final Day d = new Day();
                d.setDayOfMonth(day.getDayOfMonth());
                if (day.isEqual(today)) {
                    d.setToday(true);
                }
                week.add(d);
                day = day.plusDays(1);
            }
        }

        final MyCalendar cal = new MyCalendar();
        cal.setWeeks(weeks);
        
        // タイトル部分の年月の取得
       YearMonth year = YearMonth.now();

       model.addAttribute("calendar", cal);
       model.addAttribute("year", year);
        return "index";
    }
    
/* Schedule画面 */
    
    // 検索
    @RequestMapping(value="plan", method=RequestMethod.POST)
    public String daysearch(@RequestParam int day, Model model) {
        List<Plan_search> search = planService.daysearch(day);
        model.addAttribute("Planlist", search);
        return "plan";
    }
    
    // 更新
    @PostMapping(path = "plan", params="edit")
    public String update(@RequestParam String schedule,String day, Model model) {
        planService.planupdate(schedule, day);
        return "redirect:plan";
    }
    
    // 削除
    @PostMapping(path = "plan", params="delete")
    public String delete(@RequestParam String schedule, Model model) {
        planService.plandelete(schedule);
        return "redirect:plan";
    }
    
    // 閉じる
    @PostMapping(path = "plan", params="close")
    public String close() {
        return "redirect:/";
    }

}

PlanService

package com.example.demo.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.entity.Plan_search;
import com.example.demo.repository.PlanRepository;

@Service
public class PlanService{
    
    @Autowired
    private PlanRepository planRepository;
    
    // 検索
    public List<Plan_search> daysearch(int day) {
        return planRepository.daysearch(day);
    }
    
    // 更新
    public List<Plan_search> planupdate(String schedule, String day){
        return planRepository.planupdate(schedule, day);
    }
    
    // 削除
    public List<Plan_search> plandelete(String schedule){
        return planRepository.plandelete(schedule);
    }

}

PlanRepository

package com.example.demo.repository;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.example.demo.entity.Plan_search;

@Repository
public class PlanRepository {
    
    @Autowired
    private PlanMapper planMapper;
    
    // 検索
    public List<Plan_search> daysearch(int day) {
        return planMapper.daysearch(day);
    }
    
    // 更新
    public List<Plan_search> planupdate(String schedule, String day){
        return planMapper.update(schedule, day);
    }
    
    // 削除
    public List<Plan_search> plandelete(String schedule){
        return planMapper.delete(schedule);
    }

}

PlanMapper

package com.example.demo.repository;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import com.example.demo.entity.Plan_search;

@Mapper
public interface PlanMapper {
    
    // 検索
    public List<Plan_search> daysearch(int day);
    
    // 更新
    public List<Plan_search> update(@Param("schedule") String schedule, @Param("day") String day);
    
    // 削除
    public List<Plan_search> delete(String schedule);

}

Plan_search

package com.example.demo.entity;

import lombok.Data;

@Data
public class Plan_search {
    private String day;
    private String schedule;

}

plan.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css">
<title>スケジュール</title>
</head>
<body>
<form th:action="@{plan}" th:method="post">
<table th:object="${Planlist}" class="plan_table">
<tr>
<th class="plan_th">スケジュール内容</th>
<th class="plan_th">日付</th>
</tr>
<tr th:each="search : ${Planlist}">
<td class="plan_td">
<input type="text" name="schedule" size="50" th:value="${search.schedule}">
</td>
<td class="plan_td">
<input type="text" name="day" size="10" th:value="${search.day}">
</td>
</tr>
</table>
<div>
<p>
<input type="submit" name="delete" value="削除">
<input type="submit" name="edit" value="登録">
<input type="submit" name="close" value="閉じる">
</p>
</div>
</form>
</body>
</html>

1 件の回答 1

0
// 更新
    public List<Plan_search> update(@Param("schedule") String schedule, @Param("day") String day);

PlanMapperにおいて、updateメソッドの型はListですが、updateの場合、戻り値はintのはずなので、一致するようにListからintに変更してみてください。

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。