目标一:主页面显示书籍所有类别,点击类别出来对应的书籍数据。
目标二:后台的图片上传功能
这里有一个小知识 如何把死的页面书籍类别数据变成活得
原本的书籍类别数据是根据传进来的数字然后返回对应的类别,数据是死的
方案一:数据遍历
第一步:写dao层(CategoryDao)
package com.lj.dao; import java.util.List; import com.lj.entity.Category; import com.zking.util.BaseDao; import com.zking.util.PageBean; public class CategoryDao extends BaseDao<Category>{ public List<Category> list(Category category, PageBean pageBean) throws Exception { // TODO Auto-generated method stub String sql="select * from t_easyui_category where 1=1"; long id=category.getId(); if(id!=0) { sql+=" and id="+id; } return super.executeQuery(sql, Category.class, pageBean); } }
第二步:写web层(CategoryAction)
public String load(HttpServletRequest req, HttpServletResponse resp) { // TODO Auto-generated method stub try { Category c = categoryDao.list(category, null).get(0); ResponseUtil.writeJson(resp, c); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return null; }
第三步:将原本的
修改为
var cid=row.cid; var typeName=""; $.ajax({ url: '${pageContext.request.contextPath}/category.action?methodName=load&&id='+cid, async:false, success:function(data){ var jsonObj=eval("("+data+")"); typeName=jsonObj.name; } });
缺陷:
方案二:新建Vo类
第一步:写实体类
package com.lj.vo; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; /* * vo:view object视图模型对象 * 用在哪:在同一个页面显示多张表的数据 */ public class BookVo { 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; private String cname; public String getCname() { return cname; } public void setCname(String cname) { this.cname = cname; } public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.na