About creating an application with springboot

We are currently creating an app that has the following functions. ・ Data entry and registration ・ List display of registered data ・ Delete registration data ・ Ambiguous search of registered data

Of the above, only the ambiguous search has not yet been completed due to an error or the like.

Can you tell me where and how to fix it so that the error goes away and the search function works? ◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆ Database sp → Variable to enter tourist spots (String type)

◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆

code //MyDataRepository.java

package com.example.demo;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import org.springframework.stereotype.Repository;

@Repository

public interface MyDataRepository extends JpaRepository<MyData, Integer> {

List<MyData> findBySpLike(String sp);

}

◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆

//MyController.java

package com.example.demo;

import java.util.List;

import java.util.Optional;

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

import org.springframework.stereotype.Controller;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.bind.annotation.ModelAttribute;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.ModelAndView;

@Controller

public class MyController {

@Autowired

MyDataRepository repository;

//トップ

@RequestMapping("/")

public String index() {

	return "index";

}

//入力

@RequestMapping("/write")

public ModelAndView write(@ModelAttribute("formModel") MyData mydata,ModelAndView mv) {

	mv.setViewName("write");

	return mv;

}



@RequestMapping(value="/form", method=RequestMethod.POST)

@Transactional(readOnly=false)

public ModelAndView form(@ModelAttribute("formModel") MyData mydata, ModelAndView mv) {

	repository.saveAndFlush(mydata);

	return new ModelAndView("redirect:/");

}

//一覧

@RequestMapping(value="/list",method=RequestMethod.GET)

public ModelAndView list(ModelAndView mv) {

	mv.setViewName("list");

	List<MyData> list = repository.findAll();

	mv.addObject("datalist", list);

	return mv;

}

//詳細

@RequestMapping(value="/data/{id}",method=RequestMethod.GET)

public ModelAndView data(@ModelAttribute MyData mydata, @PathVariable int id, ModelAndView mv) {

	mv.setViewName("data");

	Optional<MyData> data = repository.findById(id);

	mv.addObject("formModel", data.get());

	return mv;

}

//削除

@RequestMapping(value="/delete/{id}",method=RequestMethod.GET)

public ModelAndView delete(@PathVariable int id, ModelAndView mv) {

	mv.setViewName("delete");

	Optional<MyData> data = repository.findById(id);

	mv.addObject("formModel", data.get());

	return mv;

}

@RequestMapping(value="/delete",method=RequestMethod.POST)

@Transactional(readOnly = false)

public ModelAndView remove(@RequestParam int id) {

	repository.deleteById(id);

	return new ModelAndView("redirect:/");

}

//検索

@RequestMapping(value="/search")

public ModelAndView search(@RequestParam("sp") String sp,ModelAndView mv) {

	List<MyData> list = repository.findBySpLike("%" + sp + "%");

	mv.setViewName("list");

	mv.addObject("dataList", list);

	return mv;

}

}

◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆

Top page </ title> </head> <body> <table> <tr> <th> <h2> Travel app </ h2> </ th> </ tr> </table> <br> <input type = "button" value = "input" onclick = "location.href ='/ write'"> <br> <input type = "button" value = "list" onclick = "location.href ='/ list'"> <br> <input type = "button" value = "search" onclick = "location.href ='/ search'"> <br> </body> </html> <p>◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆</p> <p><--search.html--></p> <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org" > <head> <meta charset="UTF-8"> <title> Search screen </ title> </head> <body> <form action="/search"> <p>Tourist destinations, etc .: <input type = "text" name = "sp" th: value = "* {tm}" /></p> <p><input type = "submit" value = "search" /> <a href="/list"> </a></p> <input type = "button" value = "search" onclick = "location.href ='/ list'"> </form> </body> </html> <!-- ENDDDDDDDDDDDDDDDDDDDDDDDDDDDDD --> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- ng_ads_new_ui --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6575041992772322" data-ad-slot="8191531813" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <div style="margin-top: 30px;"> <div class="link-top" style="margin-top: 1px;"></div> <p> <font size="4">Recommended Posts</font> <!-- BEGIN LINK ************************* --> <div style="margin-top: 10px;"> <a href="/en/6488353db0f26edea132">About creating an application with springboot</a> </div> <div style="margin-top: 10px;"> <a href="/en/e9747531976b5329c4d4">Run an application made with Java8 with Java6</a> </div> <div style="margin-top: 10px;"> <a href="/en/f3c107a2eeae0f1dcd64">Try creating an iOS library with CocoaPods</a> </div> <div style="margin-top: 10px;"> <a href="/en/95f61a39ca3303a6c85f">Run an application made with Go on Heroku</a> </div> <div style="margin-top: 10px;"> <a href="/en/ff829561238440437b99">From creating a Spring Boot project to running an application with VS Code</a> </div> <div style="margin-top: 10px;"> <a href="/en/2e6d26c4c3d229d3006f">About rails application server</a> </div> <div style="margin-top: 10px;"> <a href="/en/c039ca4a42573a2eb962">Supports multi-port with SpringBoot</a> </div> <div style="margin-top: 10px;"> <a href="/en/d55d94c316d3c1acde7f">I made an Android application that GETs with HTTP</a> </div> <div style="margin-top: 10px;"> <a href="/en/dd078d7d074bc8faf61b">[Rails] Create an application</a> </div> <div style="margin-top: 10px;"> <a href="/en/23b771298f6ed45158e9">I made an interpreter (compiler?) With about 80 lines in Ruby.</a> </div> <div style="margin-top: 10px;"> <a href="/en/242a92d06c9d9b28d914">Getting started with Java and creating an AsciiDoc editor with JavaFX</a> </div> <div style="margin-top: 10px;"> <a href="/en/39d6b12f02f274cd4a08">Rough procedure verbalized output when creating an app with Rails</a> </div> <div style="margin-top: 10px;"> <a href="/en/4953a708e752cc806b93">What to do when you launch an application with rails</a> </div> <div style="margin-top: 10px;"> <a href="/en/5d269341ff1c4e4f50fd">Summary of initial work when creating an app with Rails</a> </div> <div style="margin-top: 10px;"> <a href="/en/7dba25f4fa30ab0b1246">Procedure for publishing an application using AWS (4) Creating a database</a> </div> <div style="margin-top: 10px;"> <a href="/en/95cef8189a45e597f41c">How to specify db when creating an app with rails</a> </div> <div style="margin-top: 10px;"> <a href="/en/f5e8b4cccab6f6217516">Building an environment for creating apps with Rails and Vue</a> </div> <div style="margin-top: 10px;"> <a href="/en/f663ee93606225976688">Create a simple DRUD application with Java + SpringBoot + Gradle + thymeleaf (1)</a> </div> <div style="margin-top: 10px;"> <a href="/en/166f7aa8a69922e34d99">About an instance of java</a> </div> <div style="margin-top: 10px;"> <a href="/en/3552a51cf1d29a54c1f7">Change the port with SpringBoot</a> </div> <div style="margin-top: 10px;"> <a href="/en/c0055e732460be3b8945">Web application built with docker (1)</a> </div> <div style="margin-top: 10px;"> <a href="/en/cde66f1f81c9ddc4c2ea">Post an image with POSTMAN</a> </div> <div style="margin-top: 10px;"> <a href="/en/dffba03df3c201d5d053">Hello World with SpringBoot / Gradle</a> </div> <div style="margin-top: 10px;"> <a href="/en/e2fda3397531a504d446">UnitTest with SpringBoot + JUnit + Mockito</a> </div> <div style="margin-top: 10px;"> <a href="/en/9de7baf4748b95f06e8b">Do not add @GeneratedValue unnecessarily when creating an Entity with JPA</a> </div> <div style="margin-top: 10px;"> <a href="/en/a245edec975c596534fd">I tried to make an Android application with MVC now (Java)</a> </div> <div style="margin-top: 10px;"> <a href="/en/ba13d78aefe821600357"># 1 [Beginner] Create a web application (website) with Eclipse from knowledge 0. "Let's build an environment for creating web applications"</a> </div> <!-- END LINK ************************* --> </p> </div> </div> </div> <div class="footer text-center" style="margin-top: 40px;"> <!-- <p> Licensed under cc by-sa 3.0 with attribution required. </p> --> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.1.2/build/highlight.min.js"></script> <!-- ads --> <script data-ad-client="ca-pub-6575041992772322" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- end ads --> </body> </html>