Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.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
在eclipse中,java ee curd程序更新不起作用_Java_Mysql_Spring - Fatal编程技术网

在eclipse中,java ee curd程序更新不起作用

在eclipse中,java ee curd程序更新不起作用,java,mysql,spring,Java,Mysql,Spring,我现在正在指导EclipseJavaEE,在curdMVC程序中,我生成了四种方法,除了update方法之外,所有方法都可以工作,在编译时我可以读取数据,但是当我更新时,我得到了错误400,我给出了我的控制器和dao类 我的控制器 ---------- import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import or

我现在正在指导EclipseJavaEE,在curdMVC程序中,我生成了四种方法,除了update方法之外,所有方法都可以工作,在编译时我可以读取数据,但是当我更新时,我得到了错误400,我给出了我的控制器和dao类

我的控制器

----------

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.servlet.ModelAndView;
import java.util.List;
import dao.UserDaoImpl;
import model.User;



@Controller
public class Firstcontroller  {

    @Autowired
    UserDaoImpl userDao;

    @RequestMapping(value="/add")
    public ModelAndView redirectUser()
    {
        ModelAndView m=new ModelAndView("add");
        return m;
    }


    @RequestMapping(value="/table")
    public ModelAndView viewUser()
    {
        List<User> list=userDao.viewUsers();
        return new ModelAndView("All_User","list",list);

    }

    @RequestMapping(value="/register",method=RequestMethod.POST)
    public ModelAndView processSaveUser(@ModelAttribute User user)
    {
        if(userDao.saveUser(user))
        {
            ModelAndView m=new ModelAndView("login","response","Successfully Registered");
            return m;
        }

        ModelAndView m1=new ModelAndView("signup","response","Failed Registeration");
        return m1;

    }

    @RequestMapping(value="deleteuser/{id}" ,method = RequestMethod.GET)
    public ModelAndView deleteuser(@PathVariable int id)
    {
        userDao.delete(id);
        return new ModelAndView("redirect:/table");  
    }

    @RequestMapping(value="/edituser/{id}")  
    public ModelAndView edit(@PathVariable int id){  

       User user=userDao.getUserById(id);
        return new ModelAndView("edituser","command",user);  
    }  

    @RequestMapping(value="/save",method = RequestMethod.POST)  
    public ModelAndView edituser(@PathVariable String id){  
        System.out.println("Got In");
        //userDao.update(user);  
        return new ModelAndView("redirect:/table");  
}
}
我的刀是

EditUser.jsp 如果上述代码用于存储更新的用户名和密码,则意味着将@PathVariable更改为@ModelAttribute User 例如:

 @RequestMapping(value="edituser/save",method = RequestMethod.POST)  
   //@RequestMapping(value="/save",method=RequestMethod.PUT)
 public ModelAndView edituser(@ModelAttribute User user){  
    System.out.println("Got In");
    userDao.update(user);  
    return new ModelAndView("redirect:/table");  
 }
有不同的表名

public int delete(int id)
    {
    String sql="delete from userdata where id=?";
    int x=jdbcTemp.update(sql,id);
    if(x>0)
    {
        return(x);
    }
    return (0);
}


public int update(User user)
{
    String sql="update userdata set username=?,password=? where id=?";
    return jdbcTemp.update(sql,user.getLunm(),user.getLpwd(),user.getId());
}

my edituser.jsp问题可能是您试图更新不同的表,userdetails而不是userdatasorry sir但是在写入相同的表名之后,它也显示错误/sir这是我的完整项目Jagadananda Saint更改Url edituser/save并将表名从userdetails更改为userdata,然后像下面这样重新设计sql查询update userdata set username=?,password=?其中id=?这对你来说是个问题
 @RequestMapping(value="/save",method = RequestMethod.POST)  
 public ModelAndView edituser(@PathVariable String id){  
    System.out.println("Got In");
    //userDao.update(user);  
    return new ModelAndView("redirect:/table");  
 }
 @RequestMapping(value="edituser/save",method = RequestMethod.POST)  
   //@RequestMapping(value="/save",method=RequestMethod.PUT)
 public ModelAndView edituser(@ModelAttribute User user){  
    System.out.println("Got In");
    userDao.update(user);  
    return new ModelAndView("redirect:/table");  
 }
public int delete(int id)
    {
    String sql="delete from userdata where id=?";
    int x=jdbcTemp.update(sql,id);
    if(x>0)
    {
        return(x);
    }
    return (0);
}


public int update(User user)
{
    String sql="update userdata set username=?,password=? where id=?";
    return jdbcTemp.update(sql,user.getLunm(),user.getLpwd(),user.getId());
}