{"id":114,"date":"2025-03-08T18:24:21","date_gmt":"2025-03-08T09:24:21","guid":{"rendered":"https:\/\/suyasuyahirohiro.com\/?p=114"},"modified":"2025-03-08T18:25:45","modified_gmt":"2025-03-08T09:25:45","slug":"%e5%89%8a%e9%99%a4%e6%a9%9f%e8%83%bd%e8%bf%bd%e5%8a%a0","status":"publish","type":"post","link":"https:\/\/suyasuyahirohiro.com\/?p=114","title":{"rendered":"\u524a\u9664\u6a5f\u80fd\u8ffd\u52a0"},"content":{"rendered":"\n<p>\u521d\u671f\u6bb5\u968e\u3044\u3060\u3068\u524a\u9664\u30dc\u30bf\u30f3\u304c\u306a\u3044\u305f\u3081\u8ffd\u52a0\u3057\u3066\u3044\u304d\u307e\u3059<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">. \u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3068\u524a\u9664\u30dc\u30bf\u30f3\u3092\u8a2d\u7f6e\u3059\u308b<\/h3>\n\n\n\n<p>\u307e\u305a\u3001\u30bf\u30b9\u30af\u4e00\u89a7\u753b\u9762\uff08Thymeleaf \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\uff09\u306b\u3001\u30bf\u30b9\u30af\u3092\u524a\u9664\u3059\u308b\u305f\u3081\u306e\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3068\u524a\u9664\u30dc\u30bf\u30f3\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>HTML<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;table&gt;\n  &lt;thead&gt;\n    &lt;tr&gt;\n      &lt;th&gt;\u9078\u629e&lt;\/th&gt;\n      &lt;th&gt;\u30bf\u30b9\u30af\u540d&lt;\/th&gt;\n      &lt;\/tr&gt;\n  &lt;\/thead&gt;\n  &lt;tbody&gt;\n    &lt;tr th:each=\"task : ${tasks}\"&gt;\n      &lt;td&gt;&lt;input type=\"checkbox\" name=\"taskIds\" th:value=\"${task.id}\"&gt;&lt;\/td&gt;\n      &lt;td th:text=\"${task.name}\"&gt;&lt;\/td&gt;\n      &lt;\/tr&gt;\n  &lt;\/tbody&gt;\n&lt;\/table&gt;\n\n&lt;form id=\"deleteForm\" th:action=\"@{\/tasks\/deleteSelected}\" method=\"post\"&gt;\n  &lt;button type=\"submit\"&gt;\u9078\u629e\u3057\u305f\u30bf\u30b9\u30af\u3092\u524a\u9664&lt;\/button&gt;\n&lt;\/form&gt;\n<\/code><\/pre>\n\n\n\n<p><strong>\u30dd\u30a4\u30f3\u30c8:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>&lt;input type=\"checkbox\" name=\"taskIds\" th:value=\"${task.id}\"><\/code>\uff1a\u5404\u30bf\u30b9\u30af\u306e\u884c\u306b\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<code>name=\"taskIds\"<\/code> \u3068\u3059\u308b\u3053\u3068\u3067\u3001\u9078\u629e\u3055\u308c\u305f\u30bf\u30b9\u30af\u306e ID \u304c\u30ea\u30b9\u30c8\u3068\u3057\u3066\u30b5\u30fc\u30d0\u30fc\u306b\u9001\u4fe1\u3055\u308c\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>&lt;form id=\"deleteForm\" th:action=\"@{\/tasks\/deleteSelected}\" method=\"post\"><\/code>\uff1a\u9078\u629e\u3055\u308c\u305f\u30bf\u30b9\u30af\u3092\u524a\u9664\u3059\u308b\u305f\u3081\u306e\u30d5\u30a9\u30fc\u30e0\u3067\u3059\u3002<code>th:action=\"@{\/tasks\/deleteSelected}\"<\/code> \u3067\u3001Spring Boot \u306e <code>\/tasks\/deleteSelected<\/code> \u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306b POST \u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u4fe1\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. Controller \u3067\u524a\u9664\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u51e6\u7406\u3059\u308b<\/h3>\n\n\n\n<p>\u6b21\u306b\u3001Controller \u306b\u524a\u9664\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u51e6\u7406\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>Java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Controller;\nimport org.springframework.web.bind.annotation.PostMapping;\nimport org.springframework.web.bind.annotation.RequestParam;\nimport java.util.List;\n\n@Controller\npublic class TaskController {\n\n    @Autowired\n    private TaskService taskService;\n\n    @PostMapping(\"\/tasks\/deleteSelected\")\n    public String deleteSelectedTasks(@RequestParam(name = \"taskIds\", required = false) List&lt;Long&gt; taskIds) {\n        if (taskIds != null &amp;&amp; !taskIds.isEmpty()) {\n            taskService.deleteTasks(taskIds);\n        }\n        return \"redirect:\/tasks\";\n    }\n}\n<\/code><\/pre>\n\n\n\n<p><strong>\u30dd\u30a4\u30f3\u30c8:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>@PostMapping(\"\/tasks\/deleteSelected\")<\/code>\uff1a<code>\/tasks\/deleteSelected<\/code> \u3078\u306e POST \u30ea\u30af\u30a8\u30b9\u30c8\u3092\u51e6\u7406\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>@RequestParam(name = \"taskIds\", required = false) List&lt;Long> taskIds<\/code>\uff1a\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3067\u9078\u629e\u3055\u308c\u305f\u30bf\u30b9\u30af\u306e ID \u30ea\u30b9\u30c8\u3092\u53d7\u3051\u53d6\u308a\u307e\u3059\u3002<code>required = false<\/code> \u3068\u3059\u308b\u3053\u3068\u3067\u3001\u30bf\u30b9\u30af\u304c\u9078\u629e\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u3067\u3082\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u305b\u3093\u3002<\/li>\n\n\n\n<li><code>taskService.deleteTasks(taskIds);<\/code>\uff1aService \u306e <code>deleteTasks<\/code> \u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3001\u30bf\u30b9\u30af\u3092\u524a\u9664\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>return \"redirect:\/tasks\";<\/code>\uff1a\u30bf\u30b9\u30af\u4e00\u89a7\u753b\u9762\u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. Service \u3067\u524a\u9664\u51e6\u7406\u3092\u5b9f\u88c5\u3059\u308b<\/h3>\n\n\n\n<p>\u6b21\u306b\u3001Service \u306b\u524a\u9664\u51e6\u7406\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>Java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\nimport java.util.List;\n\n@Service\npublic class TaskService {\n\n    @Autowired\n    private TaskRepository taskRepository;\n\n    public void deleteTasks(List&lt;Long&gt; taskIds) {\n        taskRepository.deleteAllById(taskIds);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p><strong>\u30dd\u30a4\u30f3\u30c8:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>taskRepository.deleteAllById(taskIds);<\/code>\uff1aRepository \u306e <code>deleteAllById<\/code> \u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3001\u30bf\u30b9\u30af\u3092\u4e00\u62ec\u524a\u9664\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. Repository \u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u64cd\u4f5c\u3092\u5b9f\u88c5\u3059\u308b<\/h3>\n\n\n\n<p>\u6700\u5f8c\u306b\u3001Repository \u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u64cd\u4f5c\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>Java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import org.springframework.data.jpa.repository.JpaRepository;\nimport org.springframework.stereotype.Repository;\nimport java.util.List;\n\n@Repository\npublic interface TaskRepository extends JpaRepository&lt;TaskEntity, Long&gt; {\n    void deleteAllById(Iterable&lt;? extends Long&gt; ids);\n}\n<\/code><\/pre>\n\n\n\n<p><strong>\u30dd\u30a4\u30f3\u30c8:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>TaskRepository<\/code> \u306f <code>JpaRepository<\/code> \u3092\u7d99\u627f\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>deleteAllById(Iterable&lt;? extends Long> ids);<\/code>\uff1a<code>JpaRepository<\/code> \u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u306e\u5bfe\u51e6\u6cd5<\/h3>\n\n\n\n<p><code>@RequestParam<\/code> \u3067 <code>List<\/code> \u3092\u53d7\u3051\u53d6\u308b\u969b\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3001\u89e3\u6d88\u3059\u308b\u305f\u3081\u306b<code>build.gradle<\/code> \u306b\u4ee5\u4e0b\u306e\u8a2d\u5b9a\u3092\u8ffd\u52a0\u3057\u307e\u3044\u305f\u3002<\/p>\n\n\n\n<p>Gradle<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tasks.withType(JavaCompile) {\n    options.compilerArgs &lt;&lt; \"-parameters\"\n}\n<\/code><\/pre>\n\n\n\n<p>\u3053\u306e\u8a2d\u5b9a\u306b\u3088\u308a\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u540d\u304c\u4fdd\u6301\u3055\u308c\u3001<code>@RequestParam<\/code> \u3067 <code>List<\/code> \u3092\u6b63\u5e38\u306b\u53d7\u3051\u53d6\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h3>\n\n\n\n<p>\u3053\u308c\u3067\u3001Spring Boot + Thymeleaf \u3067\u30bf\u30b9\u30af\u4e00\u89a7\u304b\u3089\u8907\u6570\u30bf\u30b9\u30af\u3092\u524a\u9664\u3059\u308b\u6a5f\u80fd\u304c\u5b9f\u88c5\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521d\u671f\u6bb5\u968e\u3044\u3060\u3068\u524a\u9664\u30dc\u30bf\u30f3\u304c\u306a\u3044\u305f\u3081\u8ffd\u52a0\u3057\u3066\u3044\u304d\u307e\u3059 . \u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3068\u524a\u9664\u30dc\u30bf\u30f3\u3092\u8a2d\u7f6e\u3059\u308b \u307e\u305a\u3001\u30bf\u30b9\u30af\u4e00\u89a7\u753b\u9762\uff08Thymeleaf \u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\uff09\u306b\u3001\u30bf\u30b9\u30af\u3092\u524a\u9664\u3059\u308b\u305f\u3081\u306e\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3068\u524a\u9664 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":117,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-114","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/suyasuyahirohiro.com\/index.php?rest_route=\/wp\/v2\/posts\/114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/suyasuyahirohiro.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/suyasuyahirohiro.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/suyasuyahirohiro.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/suyasuyahirohiro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=114"}],"version-history":[{"count":2,"href":"https:\/\/suyasuyahirohiro.com\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/suyasuyahirohiro.com\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions\/118"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/suyasuyahirohiro.com\/index.php?rest_route=\/wp\/v2\/media\/117"}],"wp:attachment":[{"href":"https:\/\/suyasuyahirohiro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/suyasuyahirohiro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/suyasuyahirohiro.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}