`
z_xiaofei168
  • 浏览: 197829 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

B2C电子商务网站:三大框架、ajax、jquery和json整合开发的商品类型的自连接操作(即无限级别分类)

阅读更多

B2C电子商务网站:三大框架、ajax、jquery和json整合开发的商品类型的自连接操作(即无限级别分类)

 

        最近一直在做B2C电子商务网站,前天在写商品类型的自连接操作(即无限级别分类),以前写过一个用servlet+jsp写的。但是现在我们要用三大框架整合开发。开始还没思路,后来经过反复的思考,慢慢的琢磨出来了,今天就和大家分享一下,或许大家以后能用的到。
        详细代码如下:

 

list.jsp

<s:a href="types/insert.jsp">添加</s:a>


insert.jsp

<tr>
	<td class="gridViewHeader">
		类别所属分类
	</td>
	<td class="gridViewItem" id="parents">
			
	</td>
</tr>

 

  Types.java

 

package cn.z_xiaofei168.domain;

import java.util.HashSet;
import java.util.Set;

public class Types implements java.io.Serializable {

	/**
	 * @author z_xiaofei168
	 */
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String name;
	private String description;
	/** 自关联 */
	private Types parents;// 父节点
	private Set<Types> childrens;// 子节点
	private Set<Goods> goodses = new HashSet<Goods>(0);

                省略所有的set和get方法
}

 

  Types.hbm.xml

 

  

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false"
	package="cn.z_xiaofei168.domain">
	<class name="Types" table="types">
		<id name="id" type="java.lang.Integer">
			<column name="id" />
			<generator class="identity" />
		</id>
		<property generated="never" lazy="false" name="name"
			type="java.lang.String">
			<column length="50" name="name" not-null="true" />
		</property>
		<property generated="never" lazy="false" name="description"
			type="java.lang.String">
			<column length="100" name="description" />
		</property>
		<many-to-one name="parents" class="Types" column="types_id"
			lazy="false" />

		<set name="childrens" inverse="true" cascade="save-update">
			<key column="types_id" />
			<one-to-many class="Types" />
		</set>
		<set inverse="true" lazy="false" name="goodses" sort="unsorted">
			<key>
				<column name="type_id" not-null="true" />
			</key>
			<one-to-many class="Goods" />
		</set>
	</class>
</hibernate-mapping>

 

  

<script type="text/javascript"
			src="${pageContext.request.contextPath}/js/jquery-1.6.js">
</script>
<script type="text/javascript">

window.onload = function(){

	alert("test1");
	fun();	
}

function fun(){
	$.ajax({	
			type : "post",
			url : "csdn/types_findTypes.action",
			dataType : "json",
			success : function(data) {
				$("#parents").empty();
				var sel = $("<select>").attr("name", "parents.id");
				var opt = $("<option>").attr("value", 0).text("--根目录--");
				sel.append(opt);
				$.each(data.entities, function(i, entity) {
					var opts = $("<option>").attr("value", entity.id);
					opts.text(entity.name);
					sel.append(opts);
				});
				sel.appendTo($("#parents"));
			}
		});
}
	
</script> 

 

  TypesAction.java

 

   TypesServiceImpl.java

 

  

package cn.z_xiaofei168.action;

import java.util.List;
import cn.z_xiaofei168.dao.Pagination;
import cn.z_xiaofei168.domain.Types;
import cn.z_xiaofei168.service.TypesServiceImpl;
import com.opensymphony.xwork2.ActionSupport;

public class TypesAction extends ActionSupport {

	/**
	 * @author z_xiaofei168
	 */
	private static final long serialVersionUID = 1L;

	/** 业务层对象 */
	private TypesServiceImpl typesServiceImpl;
	private Types entity;
	private List<Types> entities;
	private Types parents;

	//省略所有属性的set和get方法
	
	/** 添加的操作 */
	public String add() throws Exception {
		/** 设置其父节点 */
		if (parents.getId() == null||parents.getId()<=0) {
			entity.setParents(null);
		} else {
			parents = typesServiceImpl.findById(parents.getId());
			entity.setParents(parents);
		}
		typesServiceImpl.add(entity);
		return "add";
	}
	
	public String findTypes() throws Exception {
		entities = typesServiceImpl.findAll();
		return SUCCESS;
	}

}

 

  TypesServiceImpl.java

 

 

package cn.z_xiaofei168.service;

import java.util.List;
import cn.z_xiaofei168.dao.TypesDaoImpl;
import cn.z_xiaofei168.domain.Types;

public class TypesServiceImpl implements TypesService {

	private TypesDaoImpl typesDaoImpl;

	public void setTypesDaoImpl(TypesDaoImpl typesDaoImpl) {
		this.typesDaoImpl = typesDaoImpl;
	}

	public void add(Types entity) throws Exception {
		typesDaoImpl.add(entity);
	}

	public List<Types> findAll() throws Exception {
		return typesDaoImpl.findAll();
	}
	
	public Types findById(Integer id) throws Exception {
		return typesDaoImpl.findById(id);
	}

}

 

 

  TypesDaoImpl.java

 

 

package cn.z_xiaofei168.dao;

import java.util.List;
import java.util.Set;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import cn.z_xiaofei168.domain.Goods;
import cn.z_xiaofei168.domain.Messages;
import cn.z_xiaofei168.domain.Orderdetails;
import cn.z_xiaofei168.domain.Types;

public class TypesDaoImpl extends HibernateDaoSupport implements TypesDao {

	public void add(Types entity) throws Exception {
		this.getHibernateTemplate().save(entity);
	}

	@SuppressWarnings("unchecked")
	public List<Types> findAll() throws Exception {
		return this.getHibernateTemplate().find("from Types");
	}
}

 

  struts.xml

 

 

<!-- TypesAction的bean -->
<action name="types_*" class="typesAction" method="{1}">
	<result name="add" type="chain">types_list</result>
	<result name="success" type="json">
		<param name="includeProperties">
			entities\[\d+\]\.id,
			entities\[\d+\]\.name
		</param>
	</result>
</action 

 

    备注:struts.xml   返回的数据是<package name="goods" extends="json-default" namespace="/xiaofei">

 

     以上是大部分代码,像一些接口之类的我就没有往上面贴。相信大家都明白。若想看最后显示的结果,可以到我的相册看图片:  jaj3.bmp

 

 

9
9
分享到:
评论

相关推荐

    b2c电子商务网站

    b2c电子商务网站源码

    B2C电子商务网站系统源码

    一个Asp.net版的B2C电子商务网站,后台有商品种类管理、商品管理、公司管理、用户管理、图片管理 购物车设计、订单管理、产品搜索、在线帮助等管理模块

    B2C电子商务网站设计详解

    详细介绍了开发电子商务网站从功能模块分析到数据库设计流程 是一部值得看的文章

    b2c电子商务网站源代码

    vc2005+sql的b2c电子商务网站

    B2C电子商务网站开发

    相当详细的电子商务网站开发教程,希望能给您带来帮助,谢谢

    (Java毕业设计)基于J2EE的B2C电子商务系统开发

    (Java毕业设计)基于J2EE的B2C电子商务系统开发(Java毕业设计)基于J2EE的B2C电子商务系统开发(Java毕业设计)基于J2EE的B2C电子商务系统开发(Java毕业设计)基于J2EE的B2C电子商务系统开发(Java毕业设计)基于J2EE的B2C...

    国内B2C电子商务网站退货管理研究

    国内B2C电子商务网站退货管理研究、国内B2C电子商务网站退货管理研究

    B2C电子商务介绍

    B2C电子商务系统:B2C(Business To Customer)是电子商务按交易对象分类中的一种(企业对个人),即表示商业机构对消费者的电子商务。这种形式的电子商务一般以网络零售业为主,主要借助于Internet开展在线销售活动,...

    B2C电子商务网站

    对比传统的商城销售,B2C电子商务网站可以将商品详细分类,使用户的选择更方便;通过前台商品的展示,可以使顾客更好地了解商城内的商品;网络购物车的实现,使顾客真正实现了足不出户、网上购物的目的。 本系统...

    B2C电子商务网站源码

    B2C电子商务网站源码.及网站发部使用说明.

    B2c电子商务网站系统分析报告

    B2c电子商务网站系统分析报告 ——电子商务

    B2C电子商务系统源码

    对于典型的数据库管理系统,尤其是B2C电子商务网站这样数据流量比较大的网络管理系统,必须要满足使用方便、操作灵活等设计需求。本系统在设计时满足以下几个目标: 界面设计美观友好,信息查询灵活、方便、快捷、...

    基于J2EE的B2C电子商务系统开发.zip

    基于J2EE的B2C电子商务系统开发.zip基于J2EE的B2C电子商务系统开发.zip基于J2EE的B2C电子商务系统开发.zip基于J2EE的B2C电子商务系统开发.zip基于J2EE的B2C电子商务系统开发.zip基于J2EE的B2C电子商务系统开发.zip...

    B2C电子商务交易系统-论文正文

    B2C电子商务交易系统-论文正文B2C电子商务交易系统-论文正文B2C电子商务交易系统-论文正文B2C电子商务交易系统-论文正文B2C电子商务交易系统-论文正文B2C电子商务交易系统-论文正文

    明日B2C电子商务系统源码

    对于典型的数据库管理系统,尤其是B2C电子商务网站这样数据流量比较大的网络管理系统,必须要满足使用方便、操作灵活等设计需求。 本系统在设计时满足以下几个目标: 界面设计美观友好,信息查询灵活、方便、快捷...

Global site tag (gtag.js) - Google Analytics