专业实习课day05

ssm实现登录后进行增删改查

在这里插入图片描述

User类

package com.wsw.bean;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class User {

    public User() {
    }


    public User(int id, String username, String password) {
        this.id = id;
        this.username = username;
        this.password = password;
    }

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    private int id;
    private String username;
    private String password;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}

UserController类

package com.wsw.controller;

import com.wsw.bean.User;
import com.wsw.service.IUserService;
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 java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;


    @RequestMapping("/login.do")
    public ModelAndView login(User user){
        boolean flag= userService.login(user.getUsername(),user.getPassword());
        ModelAndView modelAndView = new ModelAndView();
        if (flag){
            modelAndView.setViewName("main");
        }else {
            modelAndView.setViewName("../failer");
        }
        return modelAndView;
    }
    @RequestMapping("/findAll.do")
    public ModelAndView findAll(){
        List<User> userList=userService.findAll();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("userList",userList);
        modelAndView.setViewName("user-list");
        return modelAndView;
    }
    @RequestMapping("/deletByid.do")
    public String delet(int id){
        userService.deletByid(id);
        return "redirect:findAll.do";
    }

    @RequestMapping("/add.do")
    public String add(User user){
        userService.add(user);
        return "redirect:findAll.do";
    }

    @RequestMapping("toUpdate.do")
    public ModelAndView toUpdate(int id){
        User user=userService.selectUserById(id);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("user-update");
        modelAndView.addObject("user",user);
        return modelAndView;
    }
    @RequestMapping("/updateA.do")
    public String updateA(User user){
        userService.updateA(user);
        return "redirect:findAll.do";
    }
}

UserDao接口

package com.wsw.dao;

import com.wsw.bean.User;

import java.util.List;

public interface UserDao {
    User findUserByUserName(String username);

    List<User> findAll();

    void deletByid(int id);

    void add(User user);

    User selectById(int id);

    void updateAll(User user);
}

UserService类

package com.wsw.service.impl;

import com.wsw.bean.User;
import com.wsw.dao.UserDao;
import com.wsw.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService implements IUserService {
    @Autowired
    private UserDao userDao;
    @Override
    public boolean login(String username, String password) {
        User user =userDao.findUserByUserName(username);
        if (user!=null && user.getPassword().equals(password)){
            return true;
        }
            return false;
    }

    @Override
    public List<User> findAll(){
        return userDao.findAll();
    }

    @Override
    public void deletByid(int id){
        userDao.deletByid(id);
    }

    @Override
    public void add(User user){
        userDao.add(user);
    }

    @Override
    public User selectUserById(int id) {
        return userDao.selectById(id);
    }

    @Override
    public void updateA(User user) {
        userDao.updateAll(user);
    }
}

IUserService接口

package com.wsw.service;

import com.wsw.bean.User;

import java.util.List;

public interface IUserService {
    boolean login(String username,String password);
    List<User> findAll();
    void deletByid(int id);

    void add(User user);

    User selectUserById(int id);

    void updateA(User user);
}

在这里插入图片描述

.jsp关键代码

login.jsp
在这里插入图片描述
index.jsp
在这里插入图片描述
update.jsp
在这里插入图片描述
user-list.jsp
在这里插入图片描述
user-add.jsp
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值