登录注册
登录注册所需要用的的实体类,dao包,web包
实体类
User用户表(用户表中的type类型分为 1 跟2 ,1 代表着老板 ,2 代表着客户)
package com.tang.entity;
/**
*
* @author tangxinlian
*
*2020年7月1日 上午10:11:01
*/
public class User {
private long id;
private String name;//用户名
private String pwd;//密码
private int type;//类型
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public User() {
super();
}
public User(long id, String name, String pwd, int type) {
super();
this.id = id;
this.name = name;
this.pwd = pwd;
this.type = type;
}
@Override
public String toString() {
return "User [id=" + id + ", name=" + name + ", pwd=" + pwd + ", type=" + type + "]";
}
}
dao包
UserDao 中写了登录,注册的方法
package com.tang.dao;
import java.util.List;
import com.tang.entity.User;
import com.tang.util.BaseDao;
import com.tang.util.StringUtils;
public class UserDao extends BaseDao<User>{
//登录
public User login(User user) throws Exception {
String name = user.getName();
String pwd = user.getPwd();
String sql = "select * from t_easyui_user where true";
if(StringUtils.isNotBlank(name)) {
sql += " and name = '"+name+"'";
}
if(StringUtils.isNotBlank(pwd)) {
sql += " and pwd = '"+pwd+"'";
}
List<User> list = super.executeQuery(sql, null, User.class);
if(list.size() == 0) {
return null;
}
return list.get(0);
}
//注册
public int add(User user) throws Exception {
String sql = "insert into t_easyui_user(name,pwd) values(?,?)";
return super.executeUpdate(sql, user, new String[] {"name","pwd"});
}
}
web包
UserAction 中写 你登录成功会跳转到那个界面,如果你没有登录成功会跳回登录界面;注册界面是你注册成功跳转到登录界面,没有成功回到注册界面
package com.tang.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.tang.dao.UserDao;
import com.tang.entity.User;
import com.zking.framework.ActionSupport;
import com.zking.framework.ModelDriven;
public class UserAction extends ActionSupport implements ModelDriven<User>{
private User user = new User();
private UserDao UserDao = new UserDao();
@Override
public User getModel() {
return user;
}
public String login(HttpServletRequest req,HttpServletResponse resp) {
try {
User current = this.UserDao.login(user);
if(current == null) {
// 如果数据库没有这个用户,那么跳转回登录页面
return "login";
}
req.getSession().setAttribute("currentUser", current);
} catch (Exception e) {
e.printStackTrace();
return "login";
}
return "mainTemp";
}
public String add(HttpServletRequest req,HttpServletResponse resp) {
try {
this.UserDao.add(user);
} catch (Exception e) {
e.printStackTrace();
return "register";
}
return "login";
}
}
书籍管理
书籍管理所需要用的的实体类,dao包,web包
实体类
书籍信息表 book
package com.tang.entity;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tang.util.PinYinUtil;
/**
*
* @author tangxinlian
*
*2020年7月1日 上午10:00:45
*
*ctrl+shift+o 快速导包
*/
public class Book {
private long id;
private String name;//书籍名称
private String pinyin;//拼音
private long cid;//书籍分类
private String author;//作者
private float price;//价格
private String image="暂无图片";//图片路径
private String publishing;//出版社
private String description;//描述
private int state;//书籍状态(1 未上架 2已上架 3已下架 默认值1)
@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
private Date deployTime;//上架时间
private int sales;//销量
public void setName(String name) {
this.name = name;
this.pinyin = PinYinUtil.getAllPingYin(name);
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public String getPinyin() {
return pinyin;
}
public void setPinyin(String pinyin) {
this.pinyin = pinyin;
}
public long getCid() {
return cid;
}
public void setCid(long cid) {
this.cid = cid;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getPublishing() {
return publishing;
}
public void setPublishing(String publishing) {
this.publishing = publishing;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public Date getDeployTime() {
return deployTime;
}
public void setDeployTime(Date deployTime) {
this.deployTime = deployTime;
}
public int getSales() {
return sales;
}
public void setSales(int sales) {
this.sales = sales;
}
public Book(long id, String name, String pinyin, long cid, String author, float price, String image,
String publishing, String description, int state, Date deployTime, int sales) {
super();
this.id = id;
this.name = name;
this.pinyin = pinyin;
this.cid = cid;
this.author = author;
this.price = price;
this.image = image;
this.publishing = publishing;
this.description = description;
this.state = state;
this.deployTime = deployTime;
this.sales = sales;
}
public Book() {
super();
}
@Override
public String toString() {
return "Book [id=" + id + ", name=" + name + ", pinyin=" + pinyin +