Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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 HTTP状态400–;错误的请求-休眠_Java_Spring_Hibernate_Spring Mvc - Fatal编程技术网

Java HTTP状态400–;错误的请求-休眠

Java HTTP状态400–;错误的请求-休眠,java,spring,hibernate,spring-mvc,Java,Spring,Hibernate,Spring Mvc,我对hibernate和Spring MVC还很陌生。我在一个演示web应用程序上尝试hibernate和SpringMVC。问题是,当我进入编辑页面并在点击保存后点击保存按钮时,我会得到“HTTP状态400-错误请求”。如果你们能帮我,我会非常感激的 这是我的index.jsp:(其中有一个操作列,其中包含编辑和删除按钮) Mysql端口应该是3306而不是3308(persistence.xml) 您的CustomerRepository界面必须标记为@Repository @Reposit

我对hibernate和Spring MVC还很陌生。我在一个演示web应用程序上尝试hibernate和SpringMVC。问题是,当我进入编辑页面并在点击保存后点击保存按钮时,我会得到“HTTP状态400-错误请求”。如果你们能帮我,我会非常感激的

这是我的index.jsp:(其中有一个操作列,其中包含编辑和删除按钮)


Mysql端口应该是3306而不是3308(persistence.xml)

您的CustomerRepository界面必须标记为@Repository

@Repository
public interface CustomerRepository extends CrudRepository<Customer, Long>
@存储库
公共接口CustomerRepository扩展了CrudeRepository

很抱歉在这件事上浪费了你的时间,但我已经解决了我的问题。原因是我的地图。我应该在requestmapping中完成/编辑/保存。但我真的很感谢你们帮我。非常感谢

您是否可以添加左右登录
服务。保存(客户)?可能有问题。还要检查您的
“重定向:/”
,它是否有效?@Boris是的,我在我的新客户添加页面上也使用了“重定向:/”,因此没有问题。但我会看看日志记录。很抱歉,我可能会反应缓慢,因为我以前从未使用过日志记录。请将您的项目推送到gihub并在此处共享。这将更容易得到帮助you@Boris对不起,我不能做日志记录,你能给我一个example@Achille_vanhoutte这是我的GitHub存储库的链接。我使用的是wamp服务器,所以我使用的是3308端口。在编辑页面上点击save时,我仍然收到400个错误请求。我不知道wamp。根据persistence.xml文件,我假设您的数据库是Mysql。不管怎样,Mysql和Tomcat8对我来说很有效。我查看了您的GitHub存储库,但没有看到太大的差异。我认为您更改了persistence.xml,但这对我来说没有任何改变。非常感谢,我真的很感激。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
     <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Edit Customer</title>
</head>
<body>
    <div align="center">
        <h2>Edit Customer</h2>
        <form:form action="save" method="post" modelAttribute="customer">
            <table border="0" cellpadding="5">
                <tr>
                    <td>ID:</td>
                    <td>${ customer.id }</td>
                    <form:hidden path = "id"></form:hidden>
                </tr>
                <tr>
                    <td>Name: </td>
                    <td><form:input path="name" /></td>
                </tr>
                <tr>
                    <td>Email: </td>
                    <td><form:input path="email" /></td>
                </tr>
                <tr>
                    <td>Address: </td>
                    <td><form:input path="address" /></td>
                </tr>    
                <tr>
                    <td colspan="2"><input type="submit" value="Save"></td>
                </tr>                    
            </table>
        </form:form>
    </div>
</body>
</html>
package net.codejava.customer;

import java.util.List;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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 CustomerController {

    @Autowired
    private CustomerService service;

    @RequestMapping("/")
    public ModelAndView home(){
        ModelAndView mav = new ModelAndView("index");

        List<Customer> listCustomer = service.listAll();
        mav.addObject("listCustomer", listCustomer);
        return mav;
    }
    @RequestMapping("/new")
    public String newCustomerForm(Map<String, Object> model) {
        model.put("customer", new Customer());
        return "new_customer";
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST )
    public String saveCustomer(@ModelAttribute("customer") Customer customer) {
        service.save(customer);
        return "redirect:/"; 


    }
    @RequestMapping(value="/edit/{id}" , method = RequestMethod.POST )
    public ModelAndView editCustomer(@PathVariable(value="id") Long id) {
        ModelAndView mav = new ModelAndView("edit_customer");
        Customer customer = service.get(id);

        mav.addObject("customer", customer);
        return mav;
    }

    @RequestMapping(value="/delete/{id}" , method = RequestMethod.POST )
    public String deleteCustomerForm(@PathVariable(value="id") Long id) {
        service.delete(id);
        return "redirect:/";       
    }

    @RequestMapping("/search")
    public ModelAndView search(@RequestParam String keyword) {
        ModelAndView mav = new ModelAndView("search");
        List<Customer> listCustomer = service.search(keyword);
        mav.addObject(listCustomer);
        return mav;
    }



}
package net.codejava.customer;

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

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CustomerService {
    @Autowired CustomerRepository repo;

    public void save(Customer customer) {
        repo.save(customer);
    }

    public List<Customer> listAll() {
        return (List<Customer>) repo.findAll();
    }

    public void delete(Long id) {
        repo.deleteById(id);
    }

    public Customer get(Long id) {
        Optional<Customer> result = repo.findById(id);
        return result.get();
    }
    public List<Customer> search(String keyword) {
        return repo.search(keyword);
    }

}
package net.codejava.customer;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Customer {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name;
    private String email;
    private String address;

    public Customer() {

    }
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }

}
@Repository
public interface CustomerRepository extends CrudRepository<Customer, Long>