第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將選定的for循環(huán)數(shù)據(jù)保存到mysql數(shù)據(jù)庫中?

如何將選定的for循環(huán)數(shù)據(jù)保存到mysql數(shù)據(jù)庫中?

富國滬深 2023-09-27 10:33:38
我是 Spring Boot 的新手,遇到問題已經(jīng)有一段時間了。在我的 thymeleaf 頁面中,我使用了 for 循環(huán),我需要將當(dāng)前迭代的項目保存在數(shù)據(jù)庫中。(例如:我在 for 循環(huán)中使用一周中的幾天,用戶可以為我的 for loo 中的每個項目選擇一個主題,那么 5 個 sql 行應(yīng)該與日期和主題一起保存),但目前它不保存日期并將 2 個選定的主題保存在 1 個 sql 行中添加時間表 thymeleaf 視圖<!DOCTYPE html><html xmlns:th="https://www.thymeleaf.org"><head>    <link rel="stylesheet" type="text/css" href="static/css/timeTableMapping.css" th:href="@{/css/timeTableMapping.css}">    <meta charset="UTF-8">    <title>Time Table</title></head><body></form><div class="container2">    <form action="#" th:action="@{/timeTableMapping/save}" th:object="${timeTableMapping}" method="post">        <table border="0" cell[adding="10">            <tr>                <td><h1>Time Table:</h1></td>                <td>                    <select th:field="*{time_table_code}">                        <option value="">Choose..</option>                        <option th:each="timeTable: ${timeTables}" th:value="${timeTable.name}" th:text="${timeTable.name}"/>                    </select>                </td>            </tr>        </table>        <table border="1" >            <thead>            <tr>            </tr>            <br>            <th:block th:each="day : ${days}">                <th th:value="${day.name}" th:text="${day.name}"></th>            </th:block>            </thead>            <tbody>                    <th:block th:each="day : ${days}">                        <td>                            <select th:field="*{subject_code}">                                <option value=""></option>                                <option th:each="subject: ${subjects}" th:value="${subject.subject_code}" th:text="${subject.name}"/>                            </select>                        </td>                    </th:block>            <tr>                <td colspan="2">                    <button type="submit">Save</button>                </td>            </tr>            </tbody>        </table>    </form></div></body></html>
查看完整描述

2 回答

?
精慕HU

TA貢獻(xiàn)1845條經(jīng)驗 獲得超8個贊

在 DAO 中自動裝配 TimeTableMappingRepository 之前,您應(yīng)該在 TimeTableMappingRepository 接口上添加 @Repository。

像這樣

@Repository 公共接口 TimeTableMappingRepository 擴(kuò)展 JpaRepository {}

通過在接口上添加@Repository,spring-data-jpa將在運行時創(chuàng)建該接口的代理對象,您將能夠自動裝配它。


查看完整回答
反對 回復(fù) 2023-09-27
?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗 獲得超12個贊

您正在獲取多個數(shù)據(jù)。所以你應(yīng)該使用List<TimeTableMapping> timeTableMapping


在您的服務(wù)實現(xiàn)中,您可以傳遞您獲得的列表并保存所有


@Override

public void saveAll(List<TimeTableMapping> timeTableMapping) {


    List<TimeTableMapping> timetable=new ArrayList<>();

    repository.saveAll(timetable).forEach(timeTableMapping::add);   // TimeTable repository

}


查看完整回答
反對 回復(fù) 2023-09-27
  • 2 回答
  • 0 關(guān)注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號