Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java “更新问题”;电影";使用Thymeleaf和spring的数据_Java_Spring_Thymeleaf - Fatal编程技术网

Java “更新问题”;电影";使用Thymeleaf和spring的数据

Java “更新问题”;电影";使用Thymeleaf和spring的数据,java,spring,thymeleaf,Java,Spring,Thymeleaf,嘿,我在更新我的对象时遇到了问题。我有一个电影表,我可以在那里删除它或转到详细信息。在细节上,我想有我的“更新”选项。我把整个对象交给movieDetailPage,它在输入字段中显示对象的详细信息,但我不能更新它。我的“updateMovie”方法看不到我在输入中键入的内容。例如,我把名字从“Movie1”改为“Movie2”,方法仍然是“Movie1” 这是我的movieDetailsPage.html <!DOCTYPE html> <html lang="en

嘿,我在更新我的对象时遇到了问题。我有一个电影表,我可以在那里删除它或转到详细信息。在细节上,我想有我的“更新”选项。我把整个对象交给movieDetailPage,它在输入字段中显示对象的详细信息,但我不能更新它。我的“updateMovie”方法看不到我在输入中键入的内容。例如,我把名字从“Movie1”改为“Movie2”,方法仍然是“Movie1”

这是我的movieDetailsPage.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>

    <form  th:object="${movieToUpdate}" method=post >
        <p>Movie name: <input type="text" th:field="*{name}"></p>
        <p>Movie description: <input type="text" th:field="*{description}"></p>
        <img th:src="${movieToUpdate.getImageUrl()}" th:width="300" th:height="300"><br>
        <p>Nowy image url: <input type="text" th:field="*{imageUrl}" class="cloudinary-fileupload"></p>

        <a th:href="${'/movie/update/'+movieToUpdate.getId()}">Update</a><br>
    </form>

</body>
</html>

标题
电影名称:

电影描述:


Nowy图像url:


还有我的控制器类

package pl.fsaaa.filmapp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import pl.fsaaa.filmapp.model.Movie;
import pl.fsaaa.filmapp.service.CloudinaryImageUploader;
import pl.fsaaa.filmapp.service.MovieService;

import java.io.IOException;
import java.util.List;

@Controller
public class MovieController {

    private CloudinaryImageUploader cloudinaryImageUploader;
    private MovieService movieService;

    @Autowired
    public MovieController(MovieService movieService, CloudinaryImageUploader cloudinaryImageUploader) {
        this.movieService = movieService;
        this.cloudinaryImageUploader = cloudinaryImageUploader;
    }

    @GetMapping("/addmovie")
    public String getNewMovie(Model model) {
        model.addAttribute("newMovie",new Movie());
//        model.addAttribute("newImage",new File(""));
        return "addMoviePage";
    }

    @PostMapping("/add-movie")
    public String addMovie(@ModelAttribute Movie movie) throws IOException {
        cloudinaryImageUploader.saveImageToCloudinary(movie.getImageUrl());
        movie.setImageUrl(cloudinaryImageUploader.getCloudinaryImageUrl());
        movieService.addMovie(movie);
        return "redirect:/addmovie";
    }

    @GetMapping("/movies")
    public String getAllMovies(Model model) {
        List<Movie> movieList = movieService.getAllMovies();
        model.addAttribute("allMovies",movieList);
        return "moviesPage";
    }

    @GetMapping("/movie/{id}")
    public String getMovieDetail(Model model, @PathVariable Long id) {
        Movie movieToUpdate = movieService.getMovieById(id);
        System.out.println(movieToUpdate);
        model.addAttribute("movieToUpdate", movieToUpdate);
        return "movieDetailsPage";
    }

    @RequestMapping(value = "/movie/update/{id}", method = {RequestMethod.GET,RequestMethod.PUT})
//    @PutMapping("movie/update/{id}")
    public String updateMovie(@PathVariable Long id, @ModelAttribute Movie movieToUpdate){
//        movieToUpdate = movieService.getMovieById(id);
//        System.out.println(movieToUpdate);
        movieService.addMovie(movieToUpdate);
        return "redirect:/movies";
    }

    @RequestMapping(value = "/movie/delete/{id}", method = {RequestMethod.DELETE,RequestMethod.GET})
    public String deleteMovie(@PathVariable Long id){
        movieService.deleteMovie(id);
        return "redirect:/movies";
    }

}
包pl.fsaaa.filmapp.controller;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Controller;
导入org.springframework.ui.Model;
导入org.springframework.web.bind.annotation.*;
导入pl.fsaaa.filmapp.model.Movie;
导入pl.fsaaa.filmapp.service.CloudinaryImageUploader;
导入pl.fsaaa.filmapp.service.MovieService;
导入java.io.IOException;
导入java.util.List;
@控制器
公共级电影控制器{
私有CloudinaryImageUploader CloudinaryImageUploader;
私人电影服务;
@自动连线
公共MovieController(MovieService MovieService,CloudinaryImageUploader CloudinaryImageUploader){
this.movieService=movieService;
this.cloudinarymageuploader=cloudinarymageuploader;
}
@GetMapping(“/addmovie”)
公共字符串getNewMovie(模型){
model.addAttribute(“newMovie”,newMovie());
//model.addAttribute(“newImage”,新文件(“”);
返回“addMoviePage”;
}
@后期贴图(“添加电影”)
公共字符串addMovie(@modeldattribute Movie Movie)引发IOException{
cloudinaryImageUploader.saveImageToCloudinary(movie.getImageUrl());
setImageUrl(cloudinaryImageUploader.getCloudinaryImageUrl());
movieService.addMovie(电影);
返回“重定向:/addmovie”;
}
@GetMapping(“/movies”)
公共字符串getAllMovies(模型){
List movieList=movieService.getAllMovies();
model.addAttribute(“所有电影”,movieList);
返回“moviesPage”;
}
@GetMapping(“/movie/{id}”)
公共字符串getMovieDetail(模型模型,@PathVariable长id){
Movie movieToUpdate=movieService.getMovieById(id);
系统输出打印LN(电影组日期);
model.addAttribute(“movieToUpdate”,movieToUpdate);
返回“movieDetailsPage”;
}
@RequestMapping(value=“/movie/update/{id}”,method={RequestMethod.GET,RequestMethod.PUT})
//@PutMapping(“movie/update/{id}”)
公共字符串updateMovie(@PathVariable Long id,@ModelAttribute Movie movieToUpdate){
//movieToUpdate=movieService.getMovieById(id);
//系统输出打印LN(电影组日期);
movieService.addMovie(movieToUpdate);
返回“重定向:/movies”;
}
@RequestMapping(value=“/movie/delete/{id}”,method={RequestMethod.delete,RequestMethod.GET})
公共字符串deleteMovie(@PathVariable Long id){
movieService.deleteMovie(id);
返回“重定向:/movies”;
}
}

问题已解决。 我已将提交按钮添加到详细信息页面,而不是链接:

  <form th:action="'/movies/update/'+*{id}" th:object="${movieToUpdate}" method=put >
        <p>Movie name: <input type="text" th:field="*{name}"></p>
        <p>Movie description: <input type="text" th:field="*{description}"></p>
        <img th:src="${movieToUpdate.getImageUrl()}" th:width="300" th:height="300"><br>
        <p>New image url: <input type="text" th:field="*{imageUrl}" class="cloudinary-fileupload"></p>
        <p><input type="submit" value="Update"></p>
    </form>

问题已解决。 我已将提交按钮添加到详细信息页面,而不是链接:

  <form th:action="'/movies/update/'+*{id}" th:object="${movieToUpdate}" method=put >
        <p>Movie name: <input type="text" th:field="*{name}"></p>
        <p>Movie description: <input type="text" th:field="*{description}"></p>
        <img th:src="${movieToUpdate.getImageUrl()}" th:width="300" th:height="300"><br>
        <p>New image url: <input type="text" th:field="*{imageUrl}" class="cloudinary-fileupload"></p>
        <p><input type="submit" value="Update"></p>
    </form>

提交按钮在哪里?您无法使用链接更新请将您的解决方案添加为答案您的提交按钮在哪里?您无法使用链接更新。请添加您的解决方案作为答案