1.后台接口返回的数据肯定要和级联选择器的数据一致,所以我专门弄个model存放返回的值,如下:/** * @Auther: GGDong
* @Date: 2019/4/3 10:30
*/
@Getter
@Setter
public class ServerList{
//值
private String value;
//名称
private String label;
//子级
private Listchildren;
}
2.最主要的就是写sql了,不过幸好有MyBatis有个注解提供给我们使用,方便了许多,如下
@Select("SELECT area_code AS code,area_address AS name FROM hs_region WHERE parent_code = '0'")
@Results({
@Result(column = "code",property = "code"),
@Result(column = "code", property = "sub", many = @Many(select = "findListByPid"))
})
List
@Select("SELECT area_code AS code,area_address AS name FROM hs_region WHERE parent_code = #{area_code}")
List
3.级联选择器样式代码:
:options="regionServerList"
v-model="ruleForm.regionServers"
@change="handleChange">
4.如果涉及到回显的话,返回的值对应的是value才行,如下:
this.ruleForm.regionServers = [data.region, data.server]