我的控制器无法接收到来自用户的输入(春季启动)

时间:2019-07-23 07:23:51

标签: eclipse spring-boot thymeleaf

我的控制器不起作用-就像将数据添加到我的数据库中一样。

public class BukuController {

    @Autowired
    private BukuService bukuservice;

    @PostMapping(value = "/createBuku", method = RequestMethod.POST)
    public String createBook(@RequestParam("judul") String judul, @RequestParam("tahun") int tahun, @RequestParam("penulis") String penulis) {
        System.out.println("Judul   : " + judul);
        System.out.println("Tahun   : " + tahun);
        System.out.println("Penulis : " + penulis);
        try {
            bukuservice.getCreate(judul, penulis, tahun);
            System.out.println("Berhasil");
        } 
        catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
            System.out.println("Gagal");
        }
        //
        return "detail";
    }
}

detail.html(编辑3:48 PM,因为有人评论需要我用于插入数据的html文件)

<body>
<form action="/buku/createBuku" method="post">Form Detail Buku<br><br>
    Judul Buku&nbsp;: <input type="text" name="judul"><br>
    Tahun&nbsp;&nbsp;: <input type="text" name="tahun"><br>
    Nama Penulis&nbsp;: <input type="text" name="penulis"><br>
    <input type="submit" value = "Submit">
</form>

我是百里香的新手。你能给点建议吗?也许我使用了错误的依赖项,或者在其他Java文件(例如模型或服务)上使用的是错误的。

它无法将输入保存到表中,并且没有警告或错误弹出,它运行平稳。

0 个答案:

没有答案