书籍新增类别下拉框上下架
生活随笔
收集整理的這篇文章主要介紹了
书籍新增类别下拉框上下架
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一,書(shū)籍新增界面類(lèi)別下拉框
1.1:根據(jù)下拉框類(lèi)型寫(xiě)實(shí)體類(lèi):
?
?1.2 查詢所有類(lèi)型的方法
public List<Category> listType(Category category,PageBean pageBean) throws Exception{String sql="select * from t_easyui_category where 1=1";return executeQuery(sql, Category.class, pageBean);}?1.3?子控制器(CategoryAction)
package com.xyy.web;import java.util.List;import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;import com.xyy.dao.CategoryDao; import com.xyy.entity.Category; import com.zking.framework.ActionSupport; import com.zking.framework.ModelDriver; import com.zking.util.ResponseUtil;public class CategoryAction extends ActionSupport implements ModelDriver<Category>{public Category category=new Category();public CategoryDao categoryDao=new CategoryDao();@Overridepublic Category getModel() {return category;}public String listType(HttpServletRequest req, HttpServletResponse resp) throws Exception {List<Category> listType = categoryDao.listType(category, null);ResponseUtil.writeJson(resp, listType);return null;} }1.4在點(diǎn)擊菜單欄需彈出一個(gè)增加的窗口
$(function(){$("#bookMenus").tree({url:$("#ctx").val()+"/permission.action?methodName=tree", // 給菜單欄一個(gè)點(diǎn)擊onClick: function(node){ // 判斷面板是否存在var exists=$("#bookTabs").tabs('exists',node.text);if(exists){$("#bookTabs").tabs('select',node.text);}else{$('#bookTabs').tabs('add',{ title:node.text, content:'<iframe width="100%" height="100%" src="'+$("#ctx").val()+node.attributes.self.url+'" />', closable:true}); }}}); })1.5 通過(guò)數(shù)據(jù)庫(kù)內(nèi)的類(lèi)型傳到增加窗口的下拉框,使其靈活性
借助API中的ComboBox(下拉列表框)
?<input id="cid" name="cid" value="" label="類(lèi)別" >
js文件:?
$(function () {$('#cid').combobox({ url:'${pageContext.request.contextPath}/category.action?methodName=combobox', valueField:'id', textField:'text' }); });效果展示:
?
二,書(shū)籍新增
2.1書(shū)籍實(shí)體類(lèi):
//?? ?查詢時(shí)間的時(shí)候用這個(gè)格式
@JsonFormat(pattern="yyyy-mm-dd HH:mm:ss",timezone="GMT+8")
? private Date deployTime;
2.2bookDao
public void add( Book t) throws Exception { // 轉(zhuǎn)化拼音t.setPinyin(PinYinUtil.getAllPingYin(t.getName()));t.setDeployTime(new Date());String sql="insert into t_easyui_book(name,pinyin,cid,author,price,image,publishing,description,state,deployTime,sales) values(?,?,?,?,?,?,?,?,?,?,?)";super.executeUpdate(sql, t, new String[] {"name","pinyin","cid","author","price","image","publishing","description","state","deployTime","sales"});}2.3 bookAction
public void add(HttpServletRequest req, HttpServletResponse resp) {try {bd.add(book);ResponseUtil.writeJson(resp, 1);} catch (Exception e) {e.printStackTrace();try {ResponseUtil.writeJson(resp, 0);} catch (Exception e1) {e1.printStackTrace();}}}2.4 獲取數(shù)據(jù),提交表單
/* ? ? 通過(guò)form控件提交 */function submitForm() {$('#ff').form('submit', { ? ?url:'${pageContext.request.contextPath}/book.action?methodName=add', ? ?success:function(data){ ? ?if(data==1){$('#ff').form('clear');}} ? ?}); ?}/* 刷新 */function clearForm() {$('#ff').form('clear');}效果展示:
新增的書(shū)籍在未上架中。
三,上架&下架
3.1 上架其實(shí)就是修改書(shū)籍屬性
public List<Book> list(Book book, PageBean pageBean) throws Exception {String sql="select * from t_easyui_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 editStatus(Book book) throws Exception {super.executeUpdate("update t_easyui_book set state=? where id=?", book,new String[] {"state","id"});}3.2 子控制器
public void list(HttpServletRequest req, HttpServletResponse resp) {PageBean pageBean=new PageBean();pageBean.setRequest(req);try {List<Book> list = bd.list(book, pageBean);ResponseUtil.writeJson(resp, new R().data("total", pageBean.getTotal()).data("rows", list));} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}// 如果上架,書(shū)籍的狀態(tài)改為2 // 如果下架,書(shū)籍的狀態(tài)改為3public void editStatus(HttpServletRequest req, HttpServletResponse resp) {try {bd.editStatus(book);ResponseUtil.writeJson(resp, 1);} catch (Exception e) {e.printStackTrace();try {ResponseUtil.writeJson(resp, 0);} catch (Exception e1) {e1.printStackTrace();}}3.3 JS文件
function shangjia() {$.messager.confirm('確認(rèn)','您確認(rèn)想要上架此書(shū)籍嗎?',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) {}})} }});}根據(jù)狀態(tài)的不同,改變上下架function xiajia() {$.messager.confirm('確認(rèn)','您確認(rèn)想要下架此書(shū)籍嗎?',function(r){if (r){var row = $('#dg').datagrid('getSelected');if (row){$.ajax({url:'${pageContext.request.contextPath}/book.action?methodName=editStatus&state=3&id=' + row.id,success:function (data) {$('#dg').datagrid('reload'); // 重新載入當(dāng)前頁(yè)面數(shù)據(jù) }})}}});}效果展示:已上架&已下架
?
總結(jié)
以上是生活随笔為你收集整理的书籍新增类别下拉框上下架的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 圣路易斯大学计算机科学,圣路易斯华盛顿大
- 下一篇: 回复热爱计算机的数控生