欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

2020-11-03登录注册增删改查

程序员文章站 2022-05-08 11:27:08
...

2020-11-03登录注册增删改查

一、实体层(Pojo/Entity )

package com.pjion233.pojo;

public class UserPojo {
	private Integer uid;
	private Integer uphone;
	private String upwd;
	private String uname;
	private String usex;
	private Integer uage;
	private String uimg;
	public Integer getUid() {
		return uid;
	}
	public void setUid(Integer uid) {
		this.uid = uid;
	}
	public Integer getUphone() {
		return uphone;
	}
	public void setUphone(Integer uphone) {
		this.uphone = uphone;
	}
	public String getUpwd() {
		return upwd;
	}
	public void setUpwd(String upwd) {
		this.upwd = upwd;
	}
	public String getUname() {
		return uname;
	}
	public void setUname(String uname) {
		this.uname = uname;
	}
	public String getUsex() {
		return usex;
	}
	public void setUsex(String usex) {
		this.usex = usex;
	}
	public Integer getUage() {
		return uage;
	}
	public void setUage(Integer uage) {
		this.uage = uage;
	}
	public String getUimg() {
		return uimg;
	}
	public void setUimg(String uimg) {
		this.uimg = uimg;
	}
	@Override
	public String toString() {
		return "UserPojo [uid=" + uid + ", uphone=" + uphone + ", upwd=" + upwd
				+ ", uname=" + uname + ", usex=" + usex + ", uage=" + uage
				+ ", uimg=" + uimg + "]";
	}
}

二、数据访问层(Dao/Mapper )

package com.pjion233.mapper;

import java.util.List;

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

import org.springframework.stereotype.Repository;

import com.pjion233.pojo.UserPojo;

public interface UserMapper {
	// 增加(注册)
	@Insert("insert into tb_user values (default,#{uphone},#{upwd},#{uname},default,default,#{uimg})")
	Integer insertUsers(UserPojo users);

	// 删除
	@Delete("delete	from tb_user where uid = #{uid}")
	Integer deleteUsers(int uid);

	// 修改
	@Update("update	tb_user set uphone=#{uphone},upwd=#{upwd},uname=#{uname},usex=#{usex},uage=#{uage},uimg=#{uimg} where uid=#{uid}")
	Integer updateUsers(UserPojo users);

	// 查询(展示所有信息)
	@Select("select * from tb_user")
	List<UserPojo> selectUsers();

	// id查询(用户信息)
	@Select("select	* from tb_user where uid = #{uid}")
	UserPojo selectById(Integer uid);

	// 登录查询
	@Select("select	* from tb_user where uphone=#{uphone} and upwd=#{upwd}")
	UserPojo selectLogin(UserPojo users);
}

三、服务层(业务逻辑)Service+Impl

package com.pjion233.service;

import java.util.List;

import com.pjion233.pojo.UserPojo;

public interface UserService {
	// 增加UserPojo
	int addUsers(UserPojo user);
	// 删除UserPojo
	int delUsers(int uid);
	// 修改UserPojo
	int updUsers(UserPojo user);
	// 查询(展示所有信息)
	List<UserPojo> showUsers();
	// id查询(用户信息)
	UserPojo showById(int uid);
	// 登录查询
	UserPojo showByLogin(UserPojo user);
	// 下载头像
	void downLoadFile(UserPojo user, String fileName);
}
package com.pjion233.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.pjion233.mapper.UserMapper;
import com.pjion233.pojo.UserPojo;
import com.pjion233.service.UserService;

@Service
//加载业务逻辑层类的注解
public class UserServiceImpl implements UserService{
	//用业务逻辑层调用数据访问层中的方法(实现增删改查功能)
	@Resource
	private UserMapper usersMapper;
	/*增加用户*/
	@Override
	public int addUsers(UserPojo user) {
		return usersMapper.insertUsers(user);
	}
	/*删除用户*/
	@Override
	public int delUsers(int uid) {
		return usersMapper.deleteUsers(uid);
	}
	/*修改用户*/
	@Override
	public int updUsers(UserPojo user) {
		return  usersMapper.updateUsers(user);
	}
	/*查询用户*/
	@Override
	public List<UserPojo> showUsers() {
		return usersMapper.selectUsers();
	}
	/*id查询*/
	@Override
	public UserPojo showById(int uid) {
		return  usersMapper.selectById(uid);
	}
	/*登录查询*/
	@Override
	public UserPojo showByLogin(UserPojo user) {
		return  usersMapper.selectLogin(user);
	}
	/*下载头像*/
	@Override
	public void downLoadFile(UserPojo user, String fileName) {
		// 用日志类显示对应的日志信息
		Logger logger = Logger.getLogger(UserServiceImpl.class);
		String userphone = user.getUphone().toString();
		logger.info(userphone + "下载了" + fileName);
	}
}

四、控制层(Servlet/Controller)

 

相关标签: 增删改查