package www.csdn.jdshop.action;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hibernate.criterion.Restrictions;
import www.csdn.jdshop.domain.Good;
import www.csdn.jdshop.domain.GoodType;
import www.csdn.jdshop.domain.Image;
import www.csdn.jdshop.domain.Message;
import www.csdn.jdshop.domain.Orders;
import www.csdn.jdshop.domain.OrdersDetail;
import www.csdn.jdshop.service.GoodTypeService;
import www.csdn.jdshop.service.impl.GoodTypeServiceImpl;
import www.csdn.jdshop.util.DeleteUtil;
import www.csdn.jdshop.util.HibernateSessionFactory;
import www.csdn.jdshop.util.Pagination;
import www.csdn.jdshop.util.StringUtil;
import www.csdn.jdshop.util.TreeBean;
public class GoodTypeAction extends BaseAction {
private static final long serialVersionUID = 1L;
private GoodTypeService service = new GoodTypeServiceImpl();
private GoodType parentType;
private GoodType goodType;
private String idss;
private Set<TreeBean> sets = new HashSet<TreeBean>();
public String getIdss() {
return idss;
}
public void setIdss(String idss) {
this.idss = idss;
}
public Set<TreeBean> getSets() {
return sets;
}
public GoodType getParentType() {
return parentType;
}
public void setParentType(GoodType parentType) {
this.parentType = parentType;
}
public GoodType getGoodType() {
return goodType;
}
public void setGoodType(GoodType goodType) {
this.goodType = goodType;
}
// 查询所有操作
public String query() {
// 查询所有
if (goodType == null) {
// 封装pagination对象,设置当前页、总记录数和数据实体
this.pagination = new Pagination(this.page,
service.getCount(GoodType.class), this.rows);
// 查询当前页的数据
List<GoodType> rows = service.getObjects(GoodType.class,
pagination.getFrom(), pagination.getTo(), this.order,
this.sort);
// 设置当前的数据
this.pagination.setRows(rows);
} else { // 按条件查询
String whereSql = spliceSql();
this.pagination = new Pagination(this.page, service.getCount(
GoodType.class, whereSql), this.rows);
List<GoodType> rows = service.getObjects(GoodType.class, whereSql,
pagination.getFrom(), pagination.getTo(), this.order,
this.sort);
this.pagination.setRows(rows);
}
return "query";
}
/**
* 批量删除操作
*
* @return
*/
public String delete() {
Map<Integer, Integer> mids = new HashMap<Integer, Integer>();
Integer key = 0;
Integer value = 0;
String[] ides = ids.split(",");
for (int i = 0; i < ides.length; i++) {
key = Integer.parseInt(ides[i]);
}
String[] idess = idss.split(",");
for (int i = 0; i < idess.length; i++) {
String ide = idess[i];
if (ide == "d") {
value = null;
} else {
value = Integer.parseInt(ide);
}
}
mids.put(key, value);
Set<Integer> dids = DeleteUtil.getDeleteIds(mids);
Iterator<Integer> its = dids.iterator();
while (its.hasNext()) {
Integer id = (Integer) its.next();
GoodType entity = (GoodType) service.getObjectById(GoodType.class,id);
Set<Good> goods = entity.getGoodTypes();
for(Good good: goods){
service.deleteObject(good);
}
this.msg = service.deleteObject(entity);
if (!msg) {
break;
}
}
return "msg";
}
/**
* 更新实体操作
*
* @return
*/
public String update() {
Iterator<GoodType> it = goodType.getChildTypes().iterator();
while (it.hasNext()) {
it.next().setParentType(goodType);
}
this.msg = service.saveOrUpdateObject(goodType);
return "msg";
}
/**
* 添加实体操作
*
* @return
*/
public String add() {
this.msg = service.saveObject(goodType);
return "msg";
}
/**
* 拼接sql语句的操作
*
* @return
*/
private String spliceSql() {
String whereSql = " as tt where 1=1";
// 商品类型查询
if (!"".equals(goodType.getName()) && (goodType.getName() != null)) {
whereSql += " and tt.name like '%" + goodType.getName() + "%'";
}
parentType = goodType.getParentType();
if (parentType != null) {
String name = parentType.getName();
if (!"".equals(name) && (name != null)) {
whereSql += " and tt.parentType.name ='" + name + "'";
}
}
return whereSql;
}
public String tree() {
// List<GoodType> goodtypes = baseService.getAllObjects(GoodType.class);
// 查找id为空的最大的类
List<GoodType> goodtypes = HibernateSessionFactory.getSession()
.createCriteria(GoodType.class)
.add(Restrictions.isNull("parentType")).list();
for (GoodType gdtype : goodtypes) {
TreeBean treeBean = new TreeBean();
treeBean.setId(gdtype.getId());
treeBean.setText(gdtype.getName());
goodTypetoTreeBean(gdtype, treeBean);
sets.add(treeBean);
}
return "tree";
}
public void goodTypetoTreeBean(GoodType entity, TreeBean treeBean) {
Set<TreeBean> tbs = new HashSet<TreeBean>();
Set<GoodType> set = entity.getChildTypes();
Iterator<GoodType> its = set.iterator();
while (its.hasNext()) {
GoodType gtype = its.next();
TreeBean tb = new TreeBean();
tb.setId(gtype.getId());
tb.setText(gtype.getName());
tbs.add(tb);
treeBean.setChildren(tbs);
goodTypetoTreeBean(gtype, tb);
}
}
public String checkName() {
this.msg = service.checkField(GoodType.class, "name", "id",
goodType.getId(), goodType.getName());
return "msg";
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ssh编写的仿京东项目 (849个子文件)
GoodAction.class 8KB
GoodTypeAction.class 8KB
ImageAction.class 7KB
MemberAction.class 6KB
BaseDaoImpl.class 6KB
BaseDaoTest.class 6KB
OrdersDetailAction.class 6KB
OrdersAction.class 5KB
OrtherTest.class 5KB
MessageAction.class 5KB
Good.class 4KB
AddressAction.class 4KB
AdminAction.class 4KB
Orders.class 3KB
RandomAction.class 3KB
Member.class 3KB
BaseServiceImpl.class 3KB
GoodType.class 3KB
HibernateSessionFactory.class 3KB
HibernateSessionFilter.class 3KB
GoodDaoImpl.class 2KB
BaseAction.class 2KB
Address.class 2KB
OrdersDetail.class 2KB
Admin.class 2KB
GoodsListAction.class 2KB
Pagination.class 2KB
TreeBean.class 2KB
Message.class 2KB
MemberDaoImpl.class 2KB
Image.class 2KB
CacheFilter.class 2KB
DeleteUtil.class 2KB
AdminDaoImpl.class 1KB
GoodServiceImpl.class 1KB
BoxBean.class 1KB
BaseDao.class 1KB
BaseService.class 1KB
StringUtil.class 917B
MemberServiceImpl.class 782B
AdminServiceImpl.class 773B
GoodService.class 554B
GoodDao.class 534B
OrdersDetailServiceImpl.class 431B
GoodTypeServiceImpl.class 415B
AddressServiceImpl.class 411B
MessageServiceImpl.class 411B
OrdersServiceImpl.class 407B
ImageServiceImpl.class 403B
OrdersDetailDaoImpl.class 395B
GoodTypeDaoImpl.class 379B
AddressDaoImpl.class 375B
MessageDaoImpl.class 375B
OrdersDaoImpl.class 371B
ImageDaoImpl.class 367B
MemberService.class 262B
AdminService.class 259B
MemberDao.class 242B
AdminDao.class 239B
OrdersDetailService.class 186B
GoodTypeService.class 178B
AddressService.class 176B
MessageService.class 176B
OrdersService.class 174B
ImageService.class 172B
OrdersDetailDao.class 166B
GoodTypeDao.class 158B
MessageDao.class 156B
AddressDao.class 156B
OrdersDao.class 154B
ImageDao.class 152B
easyui.css 44KB
easyui.css 44KB
easyui.css 43KB
easyui.css 43KB
easyui.css 40KB
jquery-ui-1.10.2.custom.css 31KB
Default.css 9KB
tabs.css 8KB
tabs.css 8KB
tabs.css 8KB
tabs.css 8KB
tabs.css 6KB
User_Login.css 6KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
xtree.css 5KB
datagrid.css 4KB
calendar.css 3KB
calendar.css 3KB
calendar.css 3KB
calendar.css 3KB
calendar.css 3KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
共 849 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
y_keven
- 粉丝: 720
- 资源: 82
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页