宁波实习第五天日志

用户管理系统环境搭建和查询

本次项目基于ssm框架和数据库的增删改查功能
搭建ssm框架参考[link]https://blog.csdn.net/qq_37052983/article/details/95613979
数据库 的增删改查功能参考[ink]https://blog.csdn.net/qq_37052983/article/details/95732252

1.打开idea新建一个项目

宁波实习第五天日志_第1张图片
宁波实习第五天日志_第2张图片
宁波实习第五天日志_第3张图片
宁波实习第五天日志_第4张图片

2.新建完成后,搭建ssm,配置相关文件(详情见第一条链接)。导入事先准备好的各个jsp文件css文件等,按照下图所示文件目录结构进行创建相关文件和包。

宁波实习第五天日志_第5张图片
宁波实习第五天日志_第6张图片

3.编写相关文件代码

UserInfo文件:

package com.zhongruan.bean;

public class UserInfo {
    private int id;
    private String username;
    private String password;

    public int getId() {
        return id;
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

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

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

    public void setPassword(String password) {
        this.password = password;
    }
    @Override
    public String toString() {
        return "UserInfo{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}

IUserInfoDao文件

package com.zhongruan.dao;

import com.zhongruan.bean.UserInfo;

import java.util.List;

public interface IUserInfoDao {
    public List<UserInfo> findAll();
    public UserInfo doLogin(UserInfo user);

}

IUserInfoService文件

package com.zhongruan.service;

import com.zhongruan.bean.UserInfo;

import java.util.List;

public interface IUserInfoService {
    public List<UserInfo> findAll();
    public boolean doLogin(UserInfo userInfo);
}

UserInfoServiceImpl文件

package com.zhongruan.service.impl;

import com.zhongruan.bean.UserInfo;
import com.zhongruan.dao.IUserInfoDao;
import com.zhongruan.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("userInfoService")
public class UserInfoServiceImpl implements IUserInfoService {
    @Autowired
    IUserInfoDao userInfoDao;
    @Override
    public List<UserInfo> findAll() {
        return userInfoDao.findAll();
    }
    public boolean doLogin(UserInfo userInfo) {
        UserInfo user = userInfoDao.doLogin(userInfo);
        if(null!=user){
            return true;
        }else {
            return false;
        }
    }
}

UserInfoController文件

package com.zhongruan.controller;

import com.zhongruan.bean.UserInfo;
import com.zhongruan.service.IUserInfoService;
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 javax.xml.registry.infomodel.User;
import java.util.List;

@Controller
@RequestMapping("user")
public class UserInfoController {
    @Autowired
    IUserInfoService userInfoService;
    @RequestMapping("findAll.do")
    public ModelAndView findAll(){
        List<UserInfo> users=userInfoService.findAll();
        ModelAndView mv=new ModelAndView();
        mv.addObject("users",users);
        mv.setViewName("user-list");
        return mv;
    }
    @RequestMapping("login.do")
    public ModelAndView dologin(UserInfo userInfo){
        boolean flag = userInfoService.doLogin(userInfo);
        ModelAndView modelAndView=new ModelAndView();
        if(flag){
            modelAndView.setViewName("main");
        }else{
            modelAndView.setViewName("../failer");
        }
        return modelAndView;
    }
}

UserInfoMapper.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.zhongruan.dao.IUserInfoDao" >
    <select id="findAll" resultType="com.zhongruan.bean.UserInfo">
         select * from userinfo
</select>
    <select id="doLogin" parameterType="com.zhongruan.bean.UserInfo" resultType="com.zhongruan.bean.UserInfo">
        select * from userinfo where username=#{username} and password=#{password}
    </select>

</mapper>
4.界面展示

宁波实习第五天日志_第7张图片
宁波实习第五天日志_第8张图片

你可能感兴趣的:(宁波实习第五天日志)