当前位置:网站首页>EasyUI drop-down box, add and put on and off shelves of products
EasyUI drop-down box, add and put on and off shelves of products
2022-07-25 17:01:00 【Sooner or later, I will go bald】
One 、 A drop-down box
1. Write the value to be displayed in the drop-down box to the entity class
package com.mjx.entity;
public class Category {
private long id;
private String name;
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;
}
@Override
public String toString() {
return "Category [id=" + id + ", name=" + name + "]";
}
}
2.dao Method to query
public List<Category> list(Category category, PageBean pageBean) throws Exception {
String sql = "select * from t_easyui_category";
long id = category.getId();
if (id != 0) {
sql += "and id=" + id;
}
return super.executeQuery(sql, Category.class, pageBean);
}
3.action Call in the sub controller
public String combobox(HttpServletRequest req, HttpServletResponse resp) {
try {
List<Category> list = categoryDao.list(category, null);
ResponseUtil.writeJson(resp, list);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
4. To configure mvc file
<action path="/category" type="com.mjx.web.CategoryAction">
</action>
5. Add a drop-down box component to the form
<input id="cid" name="cid" value="" label=" Category " >
$(function () {
$('#cid').combobox({
url:'${pageContext.request.contextPath}/category.action?methodName=list',
valueField:'id',
textField:'name'
});
});

Two 、 add to
1. Add form
<form id="ff" action="" method="post">
<div style="margin-bottom:20px">
<input class="easyui-textbox" name="name" style="width:100%" data-options="label:' Title :',required:true">
</div>
<div style="margin-bottom:20px">
<input id="cid" name="cid" value="" label=" Category " >
<%--<select class="easyui-combobox" name="cid" label=" Category " style="width:100%">--%>
<%--<option value="1"> literature </option>--%>
<%--<option value="2"> A novel </option>--%>
<%--<option value="3"> youth </option>--%>
<%--</select>--%>
</div>
<div style="margin-bottom:20px">
<input class="easyui-textbox" name="author" style="width:100%" data-options="label:' author :',required:true">
</div>
<div style="margin-bottom:20px">
<input class="easyui-textbox" name="price" style="width:100%"
data-options="label:' Price :',required:true">
</div>
<div style="margin-bottom:20px">
<input class="easyui-textbox" name="publishing" style="width:100%"
data-options="label:' Press. :',required:true">
</div>
<div style="margin-bottom:20px">
<input class="easyui-textbox" name="description" style="width:100%;height:60px"
data-options="label:' brief introduction :',required:true">
</div>
<%-- Default not on shelves --%>
<input type="hidden" name="state" value="1">
<%-- The default starting sales volume is 0--%>
<input type="hidden" name="sales" value="0">
</form>
2. Add a click event to the form
<div style="text-align:center;padding:5px 0">
<a href="javascript:void(0)" class="easyui-linkbutton" οnclick="submitForm()" style="width:80px">Submit</a>
<a href="javascript:void(0)" class="easyui-linkbutton" οnclick="clearForm()" style="width:80px">Clear</a>
</div>
3. Submit forms and empty
// Submit the form of editing information
function submitForm() {
$('#ff').form('submit', {
success : function(param) {
$('#dd').dialog('close');
$('#dg').datagrid('reload');
$('#ff').form('clear');
}
});
}
function clearForm() {
$('#ff').form('clear');
}
3、 ... and 、 On and off the shelf
1. Book entity class
package com.mjx.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. Of books dao Methods add, modify and check
public List<Book> 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. Of books action
package com.mjx.web;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mjx.dao.BookDao;
import com.mjx.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<Book> {
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<Book> 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();
}
}
/** * If put on the shelf , The status of the book is changed to 2 * If you get off the shelf , The status of the book is changed to 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. To configure mvc file
<action path="/book" type="com.mjx.web.BookAction">
</action>
5. On the shelf js Code
function shangjia() {
$.messager
.confirm(
' confirm ',
' Are you sure you want to put this book on the shelf ?',
function(r) {
if (r) {
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. Off shelf js Code
function xiajia() {
$.messager.confirm(' confirm ',' Are you sure you want to take this book off the shelf ?',function(r){
if (r){
var row = $('#dg').datagrid('getSelected');
if (row){
$.ajax({
url:'${pageContext.request.contextPath}/book.action?methodName=shangjia&state=3&id=' + row.id,
success:function (data) {
}
})
}
}
});
}
Be careful : Book status (1 Not on the shelves 2 It's on the shelf 3 It's off the shelf The default value is 1)
effect :
Added a new book 
shelves 
Off the shelf 
边栏推荐
- SAP Fiori 的附件处理(Attachment handling)
- [cloud co creation] explore how gaussdb helps ICBC create core financial data
- win10如何删除微软拼音输入法
- Budget report ppt
- [MySQL] takes you to the database
- 【MySQL篇】一文带你初识数据库
- 第六章 继承
- 【obs】发送前丢帧及帧优先级
- Briefly describe the implementation principle of redis cluster
- Register service instances in ngmodule through dependency injection
猜你喜欢

Replicate swin on Huawei ascend910_ transformer

Hcip notes 12 days

Mindoc makes mind map

Rainbow plug-in extension: monitor MySQL based on MySQL exporter

博云容器云、DevOps平台斩获可信云“技术最佳实践奖”

【目标检测】YOLOv5跑通VOC2007数据集(修复版)

Briefly describe the implementation principle of redis cluster

如何使用 4EVERLAND CLI 在 IPFS 上部署应用程序

柏睿数据加入阿里云PolarDB开源数据库社区

MySQL linked table query, common functions, aggregate functions
随机推荐
Exception handling mechanism topic 1
easyui下拉框,增加以及商品的上架,下架
复旦大学EMBA2022毕业季丨毕业不忘初心 荣耀再上征程
Box selection screenshot shortcut key of win10
从数字化到智能运维:有哪些价值,又有哪些挑战?
企业直播风起:目睹聚焦产品,微赞拥抱生态
Chapter VI succession
Chapter 4: operators
【目标检测】YOLOv5跑通VOC2007数据集(修复版)
第四章:操作符
月薪1万在中国是什么水平?答案揭露残酷的收入真相
Chapter V: process control
Data analysis and privacy security become the key factors for the success or failure of Web3.0. How do enterprises layout?
Outlook 教程,如何在 Outlook 中搜索日历项?
Birui data joins Alibaba cloud polardb open source database community
首页门户分类查询
Getting started with easyUI
mindoc制作思维导图
[target detection] yolov5 Runtong voc2007 dataset (repair version)
多租户软件开发架构