Spring-SpringMVC-Mybatis框架下的 省市区 三级联动 第二版

一年前写过一篇关于省市区三级联动的,当时的那篇  省  市  区 分为了三张表,但现实工作中,往往是单张表 ,然后自己查自己.

现在我以这样的情况重写写一篇.

先看看表结构

这里我们关注主键Id,名称以及父级Id

在这里我们能看到,我们表中 将 省 市 区/县   都写在了一张表内,通过父级Id建立连接.

实体类根据Mybatis逆向工程来生成,除了表中属性外  添加一个额外的属性  List childrenList;

public class ShoppingArea {
	//主键Id
    private Long id;
    private Date addtime;
    private Boolean deletestatus;
    private String areaname;
    private Integer level;
    private Integer sequence;
    //父级Id
    private Long parentId;
    private Boolean common;

    //子级列表   非表属性
    private List<ShoppingArea> childrenList;
    //getter
    //setter
}

在逆向工程生成的Dao层接口mapper.java如下:

public interface ShoppingAreaMapper {
    int deleteByPrimaryKey(Long id);

    int insert(ShoppingArea record);

    int insertSelective(ShoppingArea record);

    ShoppingArea selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(ShoppingArea record);

    int updateByPrimaryKey(ShoppingArea record);
    
    //根据父级id找子级
    List<ShoppingArea> selectByParentId(Long parentId);
    
    //查询所有
    List<ShoppingArea> selectAll();
    
}

mapper.xml如下:

<mapper namespace="com.test.dao.ShoppingAreaMapper" >

	<resultMap id="BaseResultMap" type="com.test.entity.ShoppingArea" >
	    <id column="id" property="id" jdbcType="BIGINT" />
	    <result column="addTime" property="addtime" jdbcType="TIMESTAMP" />
	    <result column="deleteStatus" property="deletestatus&
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值