Springboot+HTML+Mybatis 简单三级联动

项目架构

 

配置文件

根据数据库做出相应的更改

 

实体类

 省份

城市

 

 区域

 DAO层

 

//    查询所有省份
    @Select("select * from t_address_province")
    List<Province> ProvinceAll();

//    根据省份ID 查询城市
    @Select("select *,b.name as name1,b.code as code1 from t_address_city b,t_address_province a where a.code=b.provincecode and b.provincecode=#{pid}")
    List<City> CityAll(Integer id);

//    根据城市ID查询区域
    @Select("select *,a.name as name1 from t_address_town a,t_address_city b where a.citycode=b.code and a.citycode=#{id}")
    List<Towm> TownAll(Integer id);

Controller层

注意@RequestMapping里的路径与HTML之间路径跳转对应 

@Controller
public class ProController {
    @Autowired
    private ProvinceDao provinceDao;

    @RequestMapping("Pro")
    @ResponseBody
    public List<Province> psellct(){
        List<Province> provinces = provinceDao.ProvinceAll();
         return provinces;
    }
    @RequestMapping("City")
    @ResponseBody
    public List all1(@RequestParam("pid") Integer pid){
        List<City> cities = provinceDao.CityAll(pid);
        return cities;
    }

    @RequestMapping("Town")
    @ResponseBody
    public List Tselect(@RequestParam("id") Integer id){
        List<Towm> towms = provinceDao.TownAll(id);
        return towms;
    }
@RequestMapping("aa.html")
    public String aa(){
        return "list";
}
}

HTML页面

 效果图

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值