书籍新增类别下拉框上下架
生活随笔
收集整理的這篇文章主要介紹了
书籍新增类别下拉框上下架
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一,書籍新增界面類別下拉框
1.1:根據下拉框類型寫實體類:
?
?1.2 查詢所有類型的方法
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在點擊菜單欄需彈出一個增加的窗口
$(function(){$("#bookMenus").tree({url:$("#ctx").val()+"/permission.action?methodName=tree", // 給菜單欄一個點擊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 通過數據庫內的類型傳到增加窗口的下拉框,使其靈活性
借助API中的ComboBox(下拉列表框)
?<input id="cid" name="cid" value="" label="類別" >
js文件:?
$(function () {$('#cid').combobox({ url:'${pageContext.request.contextPath}/category.action?methodName=combobox', valueField:'id', textField:'text' }); });效果展示:
?
二,書籍新增
2.1書籍實體類:
//?? ?查詢時間的時候用這個格式
@JsonFormat(pattern="yyyy-mm-dd HH:mm:ss",timezone="GMT+8")
? private Date deployTime;
2.2bookDao
public void add( Book t) throws Exception { // 轉化拼音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 獲取數據,提交表單
/* ? ? 通過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');}效果展示:
新增的書籍在未上架中。
三,上架&下架
3.1 上架其實就是修改書籍屬性
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();}}// 如果上架,書籍的狀態改為2 // 如果下架,書籍的狀態改為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('確認','您確認想要上架此書籍嗎?',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) {}})} }});}根據狀態的不同,改變上下架function xiajia() {$.messager.confirm('確認','您確認想要下架此書籍嗎?',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'); // 重新載入當前頁面數據 }})}}});}效果展示:已上架&已下架
?
總結
以上是生活随笔為你收集整理的书籍新增类别下拉框上下架的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 圣路易斯大学计算机科学,圣路易斯华盛顿大
- 下一篇: 回复热爱计算机的数控生