将这段代码转换为js:private int contentTypeIdentification(String contentType) { if (StringUtils.isEmpty(contentType)) { return 5; } else { final int i = contentType.indexOf('/'); if (i != -1) { contentType = contentType.substring(0, i); } switch (contentType) { case "text" -> { return 1; } case "image" -> { return 2; } case "audio" -> { return 3; } case "video" -> { return 4; } default -> { return 5; } } } }
时间: 2023-06-10 18:02:42 浏览: 102
js中string转int把String类型转化成int类型
function contentTypeIdentification(contentType) {
if (contentType.length == 0 || contentType === null || contentType === undefined) {
return 5;
} else {
const i = contentType.indexOf('/');
if (i != -1) {
contentType = contentType.substring(0, i);
}
switch (contentType) {
case "text":
return 1;
case "image":
return 2;
case "audio":
return 3;
case "video":
return 4;
default:
return 5;
}
}
}
阅读全文