package com.zking.entity;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
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;
@JsonFormat(pattern=“yyyy-MM-dd HH-mm-ss”,timezone=“GMT+8”)
private Date deployTime;
private int sales;
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 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;
}
@Override
public String toString() {
return “Book [id=” + id + “, name=” + name + “, pinyin=” + pinyin + “, cid=” + cid + “, author=” + author
-
“, price=” + price + “, image=” + image + “, publishing=” + publishing + “, description=”
-
description + “, state=” + state + “, deployTime=” + deployTime + “, sales=” + sales + “]”;
}
}
2.书籍的dao方法增改查
public List list(Book book, PageBean pageBean) throws Exception {
String sql = “select * from t_eastui_book where 1=1”;
String name = book.getName();
int state = book.getState();
if (StringUtils.isNotBlank(name)) {
sql += “and name like '%” + name + “%'”;
}
if (state != 0) {
sql += “and state =”+state;
}
return super.executeQuery(sql, Book.class, pageBean);
}
public void edit(Book t) throws Exception {
// TODO Auto-generated method stub
super.executeUpdate(“update t_easyui_book set name=?,pinyin=?,cid=?,image=?,state=?,sales=? where id=?”, t,
new String[] { “name”, “pinyin”, “cid”, “image”, “state”, “sales”, “id” });
}
public void add(Book t) throws Exception {
t.setPinyin(PinYinUtil.getAllPingYin(t.getName()));
super.executeUpdate(
“insert into t_easyui_book(name,pinyin,cid,author,price,image,publishing,description,state,deployTime,sales) values(?,?,?,?,?,?,?,?,?,?,?)”,
t, new String[] { “name”, “pinyin”, “cid”, “author”, “price”, “image”, “publishing”, “description”,
“state”, “deployTime”, “sales” });
}
3.书籍的action
package com.zking.web;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zking.dao.BookDao;
import com.zking.entity.Book;
import com.zking.framework.ActionSupport;
import com.zking.framework.ModelDriver;
import com.zking.util.PageBean;
import com.zking.util.R;
import com.zking.util.ResponseUtil;
public class BookAction extends ActionSupport implements ModelDriver {
private Book book = new Book();
private BookDao bookDao = new BookDao();
@Override
public Book getModel() {
// TODO Auto-generated method stub
return book;
}
public void list(HttpServletRequest req, HttpServletResponse resp) {
PageBean pageBean = new PageBean();
pageBean.setRequest(req);
try {
List list = bookDao.list(book, pageBean);
ResponseUtil.writeJson(resp, new R().data(“total”, pageBean.getTotal()).data(“rows”, list));
} catch (Exception e) {
e.printStackTrace();
}
}
public void add(HttpServletRequest req, HttpServletResponse resp) {
try {
bookDao.add(book);
ResponseUtil.writeJson(resp, 0);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
-
如果上架,书籍的状态改为2
-
如果下架,书籍的状态改为3
-
@param req
-
@param resp
*/
public void upDown(HttpServletRequest req, HttpServletResponse resp) {
try {
bookDao.edit(book);
ResponseUtil.writeJson(resp, 1);
} catch (Exception e) {
e.printStackTrace();
try {
ResponseUtil.writeJson(resp, 1);
} catch (Exception e1) {
e.printStackTrace();
}
}
}
public void editStatus(HttpServletRequest req, HttpServletResponse resp) {
try {
bookDao.editStatus(book);
ResponseUtil.writeJson(resp, 1);
} catch (Exception e) {
e.printStackTrace();
try {
ResponseUtil.writeJson(resp, 1);
} catch (Exception e1) {
e.printStackTrace();
}
}
}
}
4.配置mvc文件
5.上架的js代码
function shangjia() {
$.messager
.confirm(
‘确认’,
‘您确认想要上架此书籍吗?’,
function® {
if ® {
var row = $(‘#dg’).datagrid(‘getSelected’);
if (row) {
$
.ajax({
url : ‘${pageContext.request.contextPath}/book.action?methodName=editStatus&state=2&id=’
- row.id,
success : function(data) {
}
})
}
}
});
}
6.下架的js代码
function xiajia() {
$.messager.confirm(‘确认’,‘您确认想要下架此书籍吗?’,function®{
if ®{
var row = $(‘#dg’).datagrid(‘getSelected’);
if (row){
$.ajax({
url:‘${pageContext.request.contextPath}/book.action?methodName=shangjia&state=3&id=’ + row.id,
success:function (data) {
}
})
}
}
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。**
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-cXewtRSb-1715345951647)]
[外链图片转存中…(img-H81AlgMY-1715345951647)]
[外链图片转存中…(img-urWbARZA-1715345951647)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!