2020-11-03登入註冊增刪改查

pjion233發表於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)

 

相關文章