spring boot +mybatis + html 学生招聘信息管理系统(分角色登录)简易版
项目结构:
登录模块:
控制层
package com.wzxy.qingjia.controller;
@Controller
public class LoginController {
@Autowired
private UserServiceImpl userServiceImpl;
@Autowired
private StudentServiceImpl studentServiceImpl;
@RequestMapping("/toLogin")
public String toLogin(){
return "login";
}
@RequestMapping("/Login")
public String LoginSuccess(Model model, HttpSession session, User user){
//先查询看该用户名是否存在
User user1 = userServiceImpl.login(user.getUsername(),user.getPassword(),user.getRole());
if(user1 != null){ // 如果查询的用户不为空
session.setAttribute("user",user1);
System.out.println(user1.toString());
return "index";
}
else{
//返回到登录页面
model.addAttribute("data","该用户不存在,请先注册");
return "login";
}
}
@RequestMapping("/toLogon")
public String toRegister(){
return "logon";
}
@RequestMapping("/Welcome")
public String Welcome(){
return "Welcom";
}
// @PostMapping(value = "/register")
@RequestMapping("/logon")
public String register(@RequestParam("myfile") MultipartFile file, Model model, Student student){
//判断文件是否为空
if(file.isEmpty()){
model.addAttribute("result_singlefile", "文件为空");
return "logon";
}
//创建输入输出流
InputStream inputStream = null;
OutputStream outputStream = null;
// 拿到文件名
String filename = file.getOriginalFilename();
System.out.println(filename);
// 存放上传图片的文件夹
File fileDir = UploadUtils.getImgDirFile();
// 输出文件夹绝对路径 -- 这里的绝对路径是相当于当前项目的路径而不是“容器”路径
System.out.println(fileDir.getAbsolutePath());
try {
// 构建真实的文件路径
File newFile = new File(fileDir.getAbsolutePath() + File.separator + filename);
System.out.println(newFile.getAbsolutePath());
// 上传图片到 -》 “绝对路径”
file.transferTo(newFile);
} catch (IOException e) {
e.printStackTrace();
}
filename = "http://localhost:8081/image/" + filename;
student.setStu_photo(filename);
int pd = studentServiceImpl.add(student);
return "login";
}
}
用户服务层:
package com.wzxy.qingjia.service;
import com.wzxy.qingjia.entity.User;
import java.util.List;
public interface UserService {
public User login(String username, String password,int role);
public List getUserList();
public int addUser(User user);
public int editUser(User user);
public User updateUser(int id);
public int deleteUser(int id);
}
用户实现登录接口:serviceimpl
package com.wzxy.qingjia.service.serviceImpl;
import com.wzxy.qingjia.dao.UserDao;
import com.wzxy.qingjia.entity.User;
import com.wzxy.qingjia.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override
public User login(String username, String password,int role){
return userDao.login(username,password,role);
}
@Override
public List<User> getUserList(
){
return userDao.getUserList();
}
@Override
public int addUser(User user){
return userDao.addUser(user);
}
@Override
public int editUser(User user){
return userDao.editUser(user);
}
@Override
public User updateUser(int id){
return userDao.updateUser(id);
}
@Override
public int deleteUser(int id){
return userDao.deleteUser(id);
}
}
dao层:
package com.wzxy.qingjia.dao;
import com.wzxy.qingjia.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface UserDao {
public User login(@Param(“username”) String username, @Param(“password”) String password,@Param(“role”) int role);
public List<User> getUserList();
public int addUser(User user);
public int editUser(User user);
public User updateUser(int id);
public int deleteUser(int id);
}
用户与数据库连接 mapper.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.wzxy.qingjia.dao.UserDao">
<select id="login" resultType="com.wzxy.qingjia.entity.User">
SELECT * FROM user WHERE username=#{username} AND password=#{password}
</select>
<select id="getUserList" resultType="com.wzxy.qingjia.entity.User">
SELECT * FROM user
</select>
<insert id="addUser">
INSERT INTO user
(userid,role,username,password,phone)
VALUE
(#{userid},#{role},#{username},#{password},#{phone})
</insert>
<select id="updateUser" resultType="com.wzxy.qingjia.entity.User">
SELECT * FROM user WHERE id = #{id}
</select>
<update id="editUser">
UPDATE user SET userid = #{userid} ,role = #{role} ,username = #{username} , password = #{password},phone=#{phone}
WHERE id = #{id}
</update>
<delete id="deleteUser" >
DELETE FROM user WHERE id = #{id}
</delete>
<select id="selectUserById" resultType="com.wzxy.qingjia.entity.User">
SELECT * FROM user WHERE MERNO = #{userid}
</select>
</mapper>
效果图:
登录界面:
管理员界面:
技术员界面:
增删改查功能:
其他功能省略。。。
qq联系:2940074647