1.面包屑导航
$scope.grade=1;//默认为1级
//设置级别
$scope.setGrade=function(value){
$scope.grade=value;
}
//读取列表
$scope.selectList=function(p_entity){
if($scope.grade==1){//如果为1级
$scope.entity_1=null;
$scope.entity_2=null;
}
if($scope.grade==2){//如果为2级
$scope.entity_1=p_entity;
$scope.entity_2=null;
}
if($scope.grade==3){//如果为3级
$scope.entity_2=p_entity;
}
$scope.findByParentId(p_entity.id); //查询此级下级列表
}
<ol class="breadcrumb">
<li>
<a href="#" ng-click="grade=1;selectList({id:'0'})" >顶级分类列表</a>
</li>
<!--ng-if="grade!=1"-->
<li >
<a href="#" ng-click="grade=2;selectList(entity_1)">{{entity_1.name}}</a>
</li>
<li ng-if="grade==3">
<a href="#" ng-click="grade=3;selectList(entity_2)">{{entity_2.name}}</a>
</ol>
<span ng-if="grade!=3">
<button type="button" class="btn bg-olive btn-xs" ng- click="setGrade(grade+1);selectList(entity)">查询下级</button>
</span>
2.select2单选实现
<td>
<input select2 ng-model="entity.typeId" config="typeTemplateList" placeholder="商品类型模板" class="form-control" type="text"/>
</td>
$scope.typeTemplateList={data:[]};
//selete2
$scope.selectOptionList=function () {
typeTemplateService.findTypeTemplateList().success(
function (response) {
$scope.typeTemplateList.data=response;
}
)
}
//查询实体
$scope.findOne=function(id){
itemCatService.findOne(id).success(
function(response){
$scope.entity= response;
}
);
}
//保存
$scope.save=function(){
var serviceObject;//服务层对象
if($scope.entity.id!=null){//如果有ID
serviceObject=itemCatService.update( $scope.entity ); //修改
}else{
serviceObject=itemCatService.add( $scope.entity );//增加
$scope.entity.parentId=$scope.parentId;
}
serviceObject.success(
function(response){
if(response.success){
//重新查询
$scope.findByParentId($scope.parentId);
}else{
alert(response.message);
}
}
);
}
3.自关联表三级分类删除SQL
省市区三级联动 电商三级分类…
数据在一张表中,通过自关联建立关系
需求: 在删除某一分类时,其下面的子分类也要一起删除
思路:
- 通过传入的id查到一级分类 ( 省 )
- 将id作为parent_id 查到二级分类 ( 市 )
- 将id作为parent_id查到二级分类 形成一张临时表 , 然后查询临时表的id作为parent_id查到三级分类( 区/县 )
SELECT *
FROM tb_item_cat
WHERE id IN (1222)
OR parent_id IN (1222)
OR parent_id IN (SELECT id FROM
(SELECT * FROM tb_item_cat WHERE parent_id IN (1222)) temp)
DELETE
FROM tb_item_cat
WHERE id IN (1222)
OR parent_id IN (1222)
OR parent_id IN (SELECT id FROM
(SELECT * FROM tb_item_cat WHERE parent_id IN (1222)) temp)
mybatis写法
public interface ItemCatMapper {
List<TbItemCat> selectByIds(@Param("list") List<Long> list);
void deleteByIds(@Param("list") List<Long> list);
}
@Test
public void selectByIds() throws Exception {
//List<Long> list = Arrays.asList();
List<Long> list = Arrays.asList(new Long(1247));
List<TbItemCat> tbItemCats = itemCatMapper.selectByIds(list);
for (TbItemCat tbItemCat : tbItemCats) {
System.out.println(tbItemCat);
}
}
@Test
public void deleteByIds() throws Exception {
List<Long> list = Arrays.asList(new Long(1241));
itemCatMapper.deleteByIds(list);
}
<sql id="foreach">
<foreach collection="list" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</sql>
<select id="selectByIds" resultType="TbItemCat" parameterType="java.util.List">
select *
from tb_item_cat
<where>
<if test="list==null or list.size()==0">
and id=-1
</if>
<if test="list!=null and list.size()>0">
and id in
<include refid="foreach"/>
or parent_id in
<include refid="foreach"/>
or parent_id in
(select id from (select id from tb_item_cat where parent_id in
<include refid="foreach"/>
) temp)
</if>
</where>
</select>
<delete id="deleteByIds" parameterType="java.util.List">
delete
from tb_item_cat
<where>
<if test="list==null or list.size()==0">
and id=-1
</if>
<if test="list!=null and list.size()>0">
and id in
<include refid="foreach"/>
or parent_id in
<include refid="foreach"/>
or parent_id in
(select id from (select id from tb_item_cat where parent_id in
<include refid="foreach"/>
) temp)
</if>
</where>
</delete>
4.SPU SKU
SPU = Standard Product Unit (标准产品单位)
SPU是商品信息聚合的最小单位,是一组可复用、易检索的标准化信息的集合,该集合描述了一个产品的特性。
通俗点讲,属性值、特性相同的商品就可以称为一个SPU。例如:
iphone7就是一个SPU,与商家,与颜色、款式、套餐都无关。SKU=stock keeping unit(库存量单位)
SKU即库存进出计量的单位, 可以是以件、盒、托盘等为单位。
SKU是物理上不可分割的最小存货单元。在使用时要根据不同业态,不同管理模式来处理。在服装、鞋类商品中使用最多最普遍。例如:
纺织品中一个SKU通常表示:规格、颜色、款式。iphone7 128G 黑色 移动4G 10台
iphone7 128G 土豪金 移动4G 0台
iphone7 256G 黑色 移动4G 100台