试图在百里香叶/春天做一个删除按钮

时间:2017-05-25 01:34:56

标签: java spring thymeleaf

试图制作一个比一个按钮长得多的按钮会假设它需要一个新手。

我得到的错误信息是:

if(!empty($_POST)){
    require ('conLocal.php');

    $email = HTMLSPECIALCHARS ( $_POST ['email'] );
    $username = HTMLSPECIALCHARS ( $_POST ['username'] );
    $Password = HTMLSPECIALCHARS ( $_POST ['Password'] );
    $Password = md5 ( $Password );
    $rname = HTMLSPECIALCHARS ( $_POST ['rname'] );

    $sql = 'insert into user (email, username, Password, rname) values(?,?,?,?)';
    $query = $con->prepare ( $sql );
    $query->bind_param ( 'ssss', $email, $username, $Password, $rname );
    if ($query->execute ()) {
        $message = "New account created for " . $rname;
        $sql = 'insert into notifications (UserID, message) values ("1", ?)';
        $query2 = $con->prepare ( $sql );
        $query2->bind_param ( 's', $message );

        if ($query2->execute ()) {
        // header ( "Refresh: 2; registerlogin.php" );
            } else {
                echo '<h2>Error creating table: ' . $con->error . ' ' . $con->errno . ' Test 1</h2>';
        }
    $sql = "select * from user where username='".$username."' and Password='".$Password."'";

    if ($result3 = $con->query($sql)) {
        $row = $result3->fetch_assoc ();
        $UserID = $row ['UserID'];
    } else {
        echo '<h2>Login Failure</h2><h4>Redirecting to register page...</h4>';
        //header ( "Refresh: 1; registerlogin.php" );
    }

    $sql = 'insert into notifications (UserID, message) values (?,"Hello, I would like to thank you for taking the time out of your day to explore the full functionality of my website. If you would like, look around my projects page and play some of the games I have worked on. I recently launched the discussion board functionality of this site, so feel free to post and interact with other members of this site. ~ Stephen McIntosh")';
    $query4 = $con->prepare ( $sql );
    $query4->bind_param ( 'i', $UserID );
    if ($query4->execute ()) {
        //header ( "Refresh: 0; registerlogin.php" );
    } else {
        echo '<h2>Error: ' . $con->error . ' ' . $con->errno . ' Test 2</h2>';
    }
    include 'logUser.php';
} else {
    echo '<h2>Error: ' . $con->error . ' ' . $con->errno . ' Test 3</h2>';
    require 'registerlogin.php';
}
    }

我做错了什么?提前谢谢。

我的控制器:

'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "${id}"

查看:

@Controller
public class BuyerController {

    private BuyerService buyerService;

    @Autowired
    public void setBuyerService(BuyerService buyerService){
        this.buyerService = buyerService;
    }

    @RequestMapping("/add-buyer")
    public String showBuyerPager(Model model){
        List<Buyer> buyers = buyerService.findAllBuyers();
        model.addAttribute("buyers", buyers);
        model.addAttribute("buyer", new Buyer());
        return "add-buyer";
    }

    @GetMapping("/showBuyerForm")
    public String addBuyerForm(Model model){
        model.addAttribute("buyer", new Buyer());
        model.addAttribute("buyerId", new Buyer().getBuyerId());
        return "add-buyer";
    }

    @PostMapping("/addBuyer")
    public String postBuyerForm(@ModelAttribute("buyer") Buyer buyer, Model model){
        buyerService.saveBuyer(buyer);
        model.addAttribute("buyer", new Buyer());
        return "redirect:/";
    }


    @PostMapping("/deleteBuyer/{id}")
    public String deleteBuyer(@PathVariable Long id){
        buyerService.deleteBuyer(id);
        return "redirect:/";
    }
}

1 个答案:

答案 0 :(得分:2)

我不是百万美元专家,但您的表单th:action="@{/deleteBuyer/${id}}"看起来应该是th:action="@{/deleteBuyer/{id}(id=${buyer.buyerId})}"