基于mybatis-puls省市区三级列表后台教程(百度网盘附带相关表)

文末有省市区表的sql放到了百度网盘里有需要自取。

1、所需依赖

<!--     mybatis-puls-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.2</version>
        </dependency>
<!--          mysql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
<!--           jdbc-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
<!--            druid-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.2.11</version>
        </dependency>
<!--         swagger3-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

2、将sql语句执行

3、打开idea用打开数据库面板用mybatisx插件的mybatisx-generator功能生成表的三层的代码和xml,如下图

一直点击next生成下列目录

//======================================省==============================


import com.ccut.dachuang.model.pojo.BaseProvince;
import com.ccut.dachuang.service.BaseProvinceService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(tags = "省份信息")
@Controller
@RequestMapping("/province")
public class ProvinceController {

    @Autowired
    private BaseProvinceService provinceService;

    /**
     * 获取所有的省份信息
     * @return
     */
    @ApiOperation(value = "获取所有的省份信息")
    @GetMapping("/getProvince")
    @ResponseBody
    public List<BaseProvince> getProvince(){
        List<BaseProvince> list = provinceService.list();
        return list;
    }



}





//==================================城市=================================

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ccut.dachuang.model.pojo.BaseCity;
import com.ccut.dachuang.service.BaseCityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(tags = "城市信息")
@RestController
@RequestMapping("/city")
public class CityController {

    @Autowired
    private BaseCityService cityService;

    /**
     * 根据省份id获取城市信息
     * @param provincecode
     * @return
     */
    @ApiOperation(value = "根据省份id获取城市信息")
    @ApiImplicitParam(name = "provincecode",value = "传入的省份id",required =true,paramType = "path",dataType = "String",defaultValue = "360000")
    @GetMapping("/getCity/{provincecode}")
    public List<BaseCity> getCity(@PathVariable String provincecode){
        List<BaseCity> list = cityService.list(new QueryWrapper<BaseCity>().eq("provincecode", provincecode));
        return list;
    }
}




//===================================区=====================================


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ccut.dachuang.model.pojo.BaseArea;
import com.ccut.dachuang.service.BaseAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "县区信息")
@RestController
@RequestMapping("/area")
public class AreaController {

    @Autowired
    private BaseAreaService areaService;

    /**
     * 根据城市id获取县区信息
     * @param citycode
     * @return
     */
    @ApiOperation(value = "根据城市id获取县区信息")
    @ApiImplicitParam(name = "citycode",value = "传入的城市id",required = true,paramType = "path",dataType = "String",defaultValue = "360700")
    @GetMapping("/getArea/{citycode}")
    public List<BaseArea> getArea(@PathVariable String citycode){
        List<BaseArea> list = areaService.list(new QueryWrapper<BaseArea>().eq("citycode", citycode));
        return list;
    }

}

3、测试本文使用swagger生成的文档测试 如果对swagger不熟悉 可以用springboot自带的http请求测试,或者自行选择测试。 使用swagger还需要对swagger测试本文就不再列出,有需要可以自行搜索。

省直接发get请求返回所有的省

 城市的测试需要输入省的 code 

城市的测试需要输入省的 code 

下图是省的测试

网盘链接

链接:https://pan.baidu.com/s/168jgmUKi8HLSmxwyM8iRHA 
提取码:ouae

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值