Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
dj
/
rpc-dj-pe-analysis
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 1520874d
authored
Dec 15, 2025
by
张富康
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
省份枚举
1 parent
2e587ead
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
rpc-dj-pe-analysis-api/src/main/java/cn/com/glsx/dj/peanalysis/enums/ProvinceEnum.java
rpc-dj-pe-analysis-api/src/main/java/cn/com/glsx/dj/peanalysis/enums/ProvinceEnum.java
View file @
1520874
...
@@ -68,6 +68,34 @@ public enum ProvinceEnum {
...
@@ -68,6 +68,34 @@ public enum ProvinceEnum {
throw
new
IllegalArgumentException
(
"未知的省份名称: "
+
name
);
throw
new
IllegalArgumentException
(
"未知的省份名称: "
+
name
);
}
}
/**
* 根据行政区划代码获取省份名称
* @param code 6位数字编码(如:110000)
* @return 省份名称,若未找到返回 null
*/
public
static
String
getProvinceName
(
String
code
)
{
try
{
ProvinceEnum
province
=
ProvinceEnum
.
fromCode
(
code
);
return
province
.
getName
();
}
catch
(
IllegalArgumentException
e
)
{
return
null
;
// 或者抛出异常或返回默认值
}
}
/**
* 安全地获取省份名称(不抛异常)
* @param code 行政区划代码
* @return 省份名称,不存在则返回空字符串
*/
public
static
String
getProvinceNameSafe
(
String
code
)
{
try
{
ProvinceEnum
province
=
ProvinceEnum
.
fromCode
(
code
);
return
province
.
getName
();
}
catch
(
Exception
e
)
{
return
""
;
}
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
name
+
" ("
+
code
+
")"
;
return
name
+
" ("
+
code
+
")"
;
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment