当前位置:网站首页>Provincial and urban three-level linkage (simple and perfect)
Provincial and urban three-level linkage (simple and perfect)
2022-07-29 05:34:00 【Xiao Hong is working hard】
First of all, we need the information of provinces and cities all over the country , Specifically, use your hands :
link :https://pan.baidu.com/s/1ofVkyJgGNG0QNSCDJan3AA
Extraction code :call
At the same time, I would like to thank the eldest brother on the station for providing information about provinces and cities , I don't know the year of the above , If you need, please visit brother's Library , Links are as follows :
Three level linkage data source : You can download the sorted administrative division data of cities, provinces, districts, counties and towns in my library + Coordinate vector boundary geofencing (sql、geojson、shp), This library will be maintained for a long time , Multi level linkage 、echarts Test example : https://xiangyuecn.gitee.io/areacity-jsspider-statsgov/
Specifically
One : establish jsp file :
1. We create a jsp file , Call china.jsp Well :

In this way, there is a simple style !
Two : Request data for provinces

jQuery The bag takes its own point :( Remember to introduce )
link :https://pan.baidu.com/s/1rYWsx653xIHX1r_r9NBEuw
Extraction code :call
3、 ... and : Provincial and urban pojo class
establish pojo class :Province,City,Area.( It is used to encapsulate data , Everybody knows. )

( The picture is not cut completely , use IDEA Self contained getter and setter Make it up by yourself , This is not nanny teaching )
Four :JDBC Connect to database
JDBC Connected tool class
( Remember to change the database name and password )
import java.sql.*;
public class JDBCUtil {
private final static String URL = "jdbc:mysql://localhost:3306/china?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC";
private final static String USER = "root";
private final static String PASSWORD = "root";
private JDBCUtil() {
}
// The load driver
static {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException {
Connection connection = DriverManager.getConnection(URL,USER,PASSWORD);
return connection;
}
public static void close(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet){
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if (preparedStatement != null) {
try {
preparedStatement.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
}
JDBC Request province data :
Database query : Create a ChinaServlet class
import com.fasterxml.jackson.databind.ObjectMapper;
import com.situ.web.pojo.Province;
import com.situ.web.util.JDBCUtil;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@WebServlet("/china")
public class ChinaServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// obtain url Data spliced in method
String method = req.getParameter("method");
switch (method){
case "selectProvince":
selectProvince(req,resp);
break;
default:
System.out.println(" Wula ");
break;
}
}
private void selectProvince(HttpServletRequest req, HttpServletResponse resp) throws IOException {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
List<Province> list = new ArrayList<>();
try {
connection = JDBCUtil.getConnection();
String sql = "select id,province from tm_province";
preparedStatement = connection.prepareStatement(sql);
System.out.println(preparedStatement);
resultSet = preparedStatement.executeQuery();
while(resultSet.next()){
int id = resultSet.getInt("id");
String provinceName = resultSet.getString("province");
Province province = new Province(id,provinceName);
list.add(province);
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}finally {
JDBCUtil.close(connection,preparedStatement,resultSet);
}
resp.setContentType("text/html;charset=utf-8");
ObjectMapper objectMapper = new ObjectMapper();
//json Format return to browser
objectMapper.writeValue(resp.getWriter(),list);
}
}
After that, you can see our data :
The next step is to traverse and extract ( Modify our callback function , Just printing data , Now it's time to iterate and splice the tags ):

After that, it will be effective !!
5、 ... and : Provincial and municipal linkage
to province Of select Tag binding change event ( Change triggers )
The first step, of course, is to write a request :
Then write our City Inquire about :
Query statement :

After that, there will be data again :
Then it is to improve the callback function , Splice labels :
Finally, show the effect :
Zone linked bloggers are too lazy to move , Do it yourself , Be your homework .
边栏推荐
- 指针
- Clickhouse learning (VIII) materialized view
- ClickHouse学习(二)ClickHouse单机安装
- 哈夫曼树以及哈夫曼编码在文件压缩上的应用
- Playwright实战案例之爬取js加密数据
- AR虚拟增强与现实
- 365 day challenge leetcode 1000 questions - day 040 design jump table + avoid flooding + find the latest grouping with size M + color ball with reduced sales value
- The road to success in R & D efficiency of 1000 person Internet companies
- 利用Poi-tl在word模板表格单元格内一次插入多张图片和多行单元格相同数据自动合并的功能组件
- Selenium实战案例之爬取js加密数据
猜你喜欢

一维数组练习

About local variables

365 day challenge leetcode1000 question - distance between bus stops on day 038 + time-based key value storage + array closest to the target value after transforming the array and + maximum value at t

Alibaba cloud Zhang Xintao: heterogeneous computing provides surging power for the digital economy

Clickhouse learning (IV) SQL operation

无重复字符的最长字串

365 day challenge leetcode 1000 questions - day 039 full binary tree inserter + find peak II + snapshot array

Clickhouse learning (VII) table query optimization
![[event preview] cloud digital factory and digital transformation and innovation forum for small and medium-sized enterprises](/img/6f/f7c5d605ea9b7b9e7c49ac716492ef.jpg)
[event preview] cloud digital factory and digital transformation and innovation forum for small and medium-sized enterprises

抢先预约 | 阿里云无影云应用线上发布会预约开启
随机推荐
ClickHouse学习(四)SQL操作
科班同学真的了解未来的职业规划吗?
ClickHouse学习(七)表查询优化
【C语言系列】— 一道递归小题目
Database operation day 6
ANSI C type qualifier
【剑指offer】— 详解库函数atoi以及模拟实现atoi函数
AR虚拟增强与现实
用threejs 技术做游戏跑酷
365 day challenge leetcode1000 question - distance between bus stops on day 038 + time-based key value storage + array closest to the target value after transforming the array and + maximum value at t
省市区三级联动(简单又完美)
Complete ecological map of R & D Efficiency & selection of Devops tools
Storage category
Day 2
关于局部变量
ClickHouse学习(八)物化视图
C语言文件操作
阿里云张新涛:异构计算为数字经济提供澎湃动力
Basic principle of recursion
Summary of the first week