小作业 ssm实现简单的增删改查

本文档展示了使用Spring、SpringMVC和MyBatis(SSM)框架实现用户管理的简单CRUD操作。包括DeleteControl、LoginControl、RegisterControl、SelectControl和UpdateControl等控制器类,以及对应的UserInfService和UserInfDao接口和实现。用户可以通过注册、登录、删除、查询和更新来管理自己的信息。
摘要由CSDN通过智能技术生成

 项目结构如图

DeleteControl.代码:

package controls;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import services.UserInfServiceInterface;

@Controller
public class DeleteControl {
    @Autowired
    private UserInfServiceInterface userInfService;
    @RequestMapping("/delete")
    public ModelAndView delete(String userid)
    {
        if(userInfService.delete(userid)==1)
            return new ModelAndView("login_success.jsp");
        else
            return new ModelAndView("login_failure.jsp");
    }


}

LoginControl代码:

package controls;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import services.UserInfServiceInterface;

@Controller
public class LoginControl {
    @Autowired
    private UserInfServiceInterface userInfService;
    @RequestMapping("/login")
    public ModelAndView login(String userid,String userpwd)
    {
        if(userInfService.login(userid, userpwd)==1)
            return new ModelAndView("login_success.jsp");
        else
            return new ModelAndView("login_failure.jsp");
    }

}
RegisterControl代码

package controls;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import services.UserInfServiceInterface;

@Controller
public class RegisterControl {
    @Autowired
    private UserInfServiceInterface userInfService;
    @RequestMapping("/register")
    public ModelAndView login(String userid,String userpwd,String realname)
    {
        if(userInfService.register(userid, userpwd,realname)==1)
            return new ModelAndView("login_success.jsp");
        else
            return new ModelAndView("login_failure.jsp");
    }
}

SelectControl代码

 package controls;

import java.io.IOException;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import model.UserInf;
import services.UserInfServiceInterface;

@Controller
public class SelectControl {
    @Autowired
    private UserInfServiceInterface userInfService;
    @RequestMapping("/select")
    public String select(Model model,String userid) throws IOException {
        UserInf user=new UserInf();
        user=userInfService.select(userid);
        return user.getUserid()+user.getUserpwd()+"selct1";
    }

}

UpdateControl代码

package controls;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import model.UserInf;
import services.UserInfServiceInterface;

@Controller
public class UpdateControl {
    @Autowired
    private UserInfServiceInterface userInfService;
    @RequestMapping("/update")
    public ModelAndView update(UserInf user)
    {
        userInfService.update(user);
            return new ModelAndView("login_success.jsp");
    }
}

UserInfDaoInterface代码

package dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import model.UserInf;

public interface UserInfDaoInterface {
    @Select("select count(*) from user where userid=#{userid} and userpwd=#{userpwd}")
    public int selectByIdPwd(@Param("userid")String userid,@Param("userpwd")String userpwd);
    
    @Insert("insert into user(userid,userpwd,rea

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值