项目架构
配置文件
根据数据库做出相应的更改
实体类
省份
城市
区域
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页面
效果图