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)
相關文章
- 增刪改查
- Node+Express+MySql實現簡單增刪改查和登入ExpressMySql
- Vue+Mock.js模擬登入和表格的增刪改查VueMockJS
- SQL增刪改查SQL
- Mongoose查增改刪Go
- indexedDB 增刪改查Index
- mysql增刪改查MySql
- MySQL 常用命令手冊 增刪改查大法MySql
- 列表的增刪改查
- 字典的增刪改查
- mongodb 基本增刪改查MongoDB
- MongoDB增刪改查操作MongoDB
- layui的增刪改查UI
- 單表增刪改查
- mybatis的增刪改查MyBatis
- EFCore之增刪改查
- redist的增刪改查Redis
- sql指令,增,刪,查,改SQL
- mysql基本增刪改查MySql
- MongoDB入門(介紹、安裝、增刪改查)MongoDB
- 153 多方式登入簽發token&單項/多項的增刪查改
- iOS CoreData (一) 增刪改查iOS
- Jfinal+layui增刪改查UI
- SQL 基礎增、刪、改、查SQL
- elasticsearch7.2增刪改查Elasticsearch
- [express+mongoose](增刪改查)ExpressGo
- CoreData - 簡單 增刪改查
- C# SqlSugar增刪改查C#SqlSugar
- rust sqlx 使用---增刪改查RustSQL
- PHP操作MongoDB(增刪改查)PHPMongoDB
- JavaWeb中jdbc增刪查改JavaWebJDBC
- 基本 SQL 之增刪改查(二)SQL
- JavaScript表格增刪改查詳解JavaScript
- MySQL基礎操作(增刪改查)MySql
- Kendo UI:grid完成增刪改查(*)UI
- mysql資料增刪改查操作MySql
- 02-CoreData 的增刪改查
- Layui(4) 增刪改查 完整案例UI