{"id":202206,"date":"2020-10-18T09:15:44","date_gmt":"2020-10-18T01:15:44","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=202206"},"modified":"2020-10-08T16:17:05","modified_gmt":"2020-10-08T08:17:05","slug":"standard-code-writing","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/standard-code-writing.html","title":{"rendered":"\u53cd\u6b63\u4e3e\u4f8b\u6559\u4f60\u89c4\u8303\u5199\u4ee3\u7801"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u672c\u6587\u4ecb\u7ecd\u4e86\u5341\u516d\u9879\u5982\u4f55\u89c4\u8303\u7684\u5199\u51fa\u4ee3\u7801\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u5427\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u4e00\u3001MyBatis \u4e0d\u8981\u4e3a\u4e86\u591a\u4e2a\u67e5\u8be2\u6761\u4ef6\u800c\u5199 1 = 1<\/strong><\/div>\n

\u5f53\u9047\u5230\u591a\u4e2a\u67e5\u8be2\u6761\u4ef6\uff0c\u4f7f\u7528where 1=1 \u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u89e3\u51b3\u6211\u4eec\u7684\u95ee\u9898\uff0c\u4f46\u662f\u8fd9\u6837\u5f88\u53ef\u80fd\u4f1a\u9020\u6210\u975e\u5e38\u5927\u7684\u6027\u80fd\u635f\u5931\uff0c\u56e0\u4e3a\u6dfb\u52a0\u4e86 \u201cwhere 1=1 \u201d\u7684\u8fc7\u6ee4\u6761\u4ef6\u4e4b\u540e\uff0c\u6570\u636e\u5e93\u7cfb\u7edf\u5c31\u65e0\u6cd5\u4f7f\u7528\u7d22\u5f15\u7b49\u67e5\u8be2\u4f18\u5316\u7b56\u7565\uff0c\u6570\u636e\u5e93\u7cfb\u7edf\u5c06\u4f1a\u88ab\u8feb\u5bf9\u6bcf\u884c\u6570\u636e\u8fdb\u884c\u626b\u63cf\uff08\u5373\u5168\u8868\u626b\u63cf\uff09 \u4ee5\u6bd4\u8f83\u6b64\u884c\u662f\u5426\u6ee1\u8db3\u8fc7\u6ee4\u6761\u4ef6\uff0c\u5f53\u8868\u4e2d\u7684\u6570\u636e\u91cf\u8f83\u5927\u65f6\u67e5\u8be2\u901f\u5ea6\u4f1a\u975e\u5e38\u6162\uff1b\u6b64\u5916\uff0c\u8fd8\u4f1a\u5b58\u5728SQL \u6ce8\u5165\u7684\u98ce\u9669\u3002<\/p>\n

\u53cd\u4f8b\uff1a
\n\"\"
\n\u6b63\u4f8b\uff1a
\n\"\"
\nUPDATE \u64cd\u4f5c\u4e5f\u4e00\u6837\uff0c\u53ef\u4ee5\u7528\u6807\u8bb0\u4ee3\u66ff 1=1\u3002<\/p>\n

\u4e8c\u3001\u8fed\u4ee3entrySet() \u83b7\u53d6Map \u7684key \u548cvalue<\/strong><\/div>\n

\u5f53\u5faa\u73af\u4e2d\u53ea\u9700\u8981\u83b7\u53d6Map \u7684\u4e3b\u952ekey\u65f6\uff0c\u8fed\u4ee3keySet() \u662f\u6b63\u786e\u7684\uff1b\u4f46\u662f\uff0c\u5f53\u9700\u8981\u4e3b\u952ekey \u548c\u53d6\u503cvalue \u65f6\uff0c\u8fed\u4ee3entrySet() \u624d\u662f\u66f4\u9ad8\u6548\u7684\u505a\u6cd5\uff0c\u5176\u6bd4\u5148\u8fed\u4ee3keySet() \u540e\u518d\u53bb\u901a\u8fc7get \u53d6\u503c\u6027\u80fd\u66f4\u4f73\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    \/\/Map \u83b7\u53d6value \u53cd\u4f8b:  \r\n    HashMap map = new HashMap<>();  \r\n    for (String key : map.keySet()){  \r\n        String value = map.get(key);  \r\n    } \r\n<\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    \/\/Map \u83b7\u53d6key & value \u6b63\u4f8b:  \r\n    HashMap map = new HashMap<>();  \r\n    for (Map.Entry entry : map.entrySet()){  \r\n     String key = entry.getKey();  \r\n     String value = entry.getValue();  \r\n    } \r\n<\/pre>\n
\u4e09\u3001\u4f7f\u7528Collection.isEmpty() \u68c0\u6d4b\u7a7a<\/strong><\/div>\n

\u4f7f\u7528Collection.size() \u6765\u68c0\u6d4b\u662f\u5426\u4e3a\u7a7a\u5728\u903b\u8f91\u4e0a\u6ca1\u6709\u95ee\u9898\uff0c\u4f46\u662f\u4f7f\u7528Collection.isEmpty() \u4f7f\u5f97\u4ee3\u7801\u66f4\u6613\u8bfb\uff0c\u5e76\u4e14\u53ef\u4ee5\u83b7\u5f97\u66f4\u597d\u7684\u6027\u80fd\uff1b\u9664\u6b64\u4e4b\u5916\uff0c\u4efb\u4f55Collection.isEmpty() \u5b9e\u73b0\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u90fd\u662fO(1) \uff0c\u4e0d\u9700\u8981\u591a\u6b21\u5faa\u73af\u904d\u5386\uff0c\u4f46\u662f\u67d0\u4e9b\u901a\u8fc7Collection.size() \u65b9\u6cd5\u5b9e\u73b0\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u53ef\u80fd\u662fO(n)<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    LinkedList collection = new LinkedList<>();  \r\n    if (collection.size() == 0){  \r\n     System.out.println(\"collection is empty.\");  \r\n    } \r\n<\/object><\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    LinkedList collection = new LinkedList<>();  \r\n    if (collection.isEmpty()){  \r\n        System.out.println(\"collection is empty.\");  \r\n    }  \r\n    \/\/\u68c0\u6d4b\u662f\u5426\u4e3anull \u53ef\u4ee5\u4f7f\u7528CollectionUtils.isEmpty()  \r\n    if (CollectionUtils.isEmpty(collection)){ \r\n         System.out.println(\"collection is null.\");  \r\n    } \r\n<\/object><\/pre>\n
\u56db\u3001\u521d\u59cb\u5316\u96c6\u5408\u65f6\u5c3d\u91cf\u6307\u5b9a\u5176\u5927\u5c0f<\/strong><\/div>\n

\u5c3d\u91cf\u5728\u521d\u59cb\u5316\u65f6\u6307\u5b9a\u96c6\u5408\u7684\u5927\u5c0f\uff0c\u80fd\u6709\u6548\u51cf\u5c11\u96c6\u5408\u7684\u6269\u5bb9\u6b21\u6570\uff0c\u56e0\u4e3a\u96c6\u5408\u6bcf\u6b21\u6269\u5bb9\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5f88\u53ef\u80fd\u65f6O(n)\uff0c\u8017\u8d39\u65f6\u95f4\u548c\u6027\u80fd\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u521d\u59cb\u5316list\uff0c\u5f80list \u4e2d\u6dfb\u52a0\u5143\u7d20\u53cd\u4f8b\uff1a \r\n     \r\n    int[] arr = new int[]{1,2,3,4};  \r\n    List list = new ArrayList<>();  \r\n    for (int i : arr){  \r\n     list.add(i);  \r\n    } \r\n<\/integer><\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u521d\u59cb\u5316list\uff0c\u5f80list \u4e2d\u6dfb\u52a0\u5143\u7d20\u6b63\u4f8b\uff1a  \r\n    int[] arr = new int[]{1,2,3,4};  \r\n    \/\/\u6307\u5b9a\u96c6\u5408list \u7684\u5bb9\u91cf\u5927\u5c0f  \r\n    List list = new ArrayList<>(arr.length);  \r\n    for (int i : arr){  \r\n        list.add(i);  \r\n    } \r\n<\/integer><\/pre>\n
\u4e94\u3001\u4f7f\u7528StringBuilder \u62fc\u63a5\u5b57\u7b26\u4e32<\/strong><\/div>\n

\u4e00\u822c\u7684\u5b57\u7b26\u4e32\u62fc\u63a5\u5728\u7f16\u8bd1\u671fJava \u4f1a\u5bf9\u5176\u8fdb\u884c\u4f18\u5316\uff0c\u4f46\u662f\u5728\u5faa\u73af\u4e2d\u5b57\u7b26\u4e32\u7684\u62fc\u63a5Java \u7f16\u8bd1\u671f\u65e0\u6cd5\u6267\u884c\u4f18\u5316\uff0c\u6240\u4ee5\u9700\u8981\u4f7f\u7528StringBuilder \u8fdb\u884c\u66ff\u6362\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u5728\u5faa\u73af\u4e2d\u62fc\u63a5\u5b57\u7b26\u4e32\u53cd\u4f8b  \r\n    String str = \"\";  \r\n    for (int i = 0; i < 10; i++){  \r\n        \/\/\u5728\u5faa\u73af\u4e2d\u5b57\u7b26\u4e32\u62fc\u63a5Java \u4e0d\u4f1a\u5bf9\u5176\u8fdb\u884c\u4f18\u5316  \r\n        str += i;  \r\n    } \r\n<\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u5728\u5faa\u73af\u4e2d\u62fc\u63a5\u5b57\u7b26\u4e32\u6b63\u4f8b  \r\n    String str1 = \"Love\";  \r\n    String str2 = \"Courage\";  \r\n    String strConcat = str1 + str2;  \/\/Java \u7f16\u8bd1\u5668\u4f1a\u5bf9\u8be5\u666e\u901a\u6a21\u5f0f\u7684\u5b57\u7b26\u4e32\u62fc\u63a5\u8fdb\u884c\u4f18\u5316  \r\n    StringBuilder sb = new StringBuilder();  \r\n    for (int i = 0; i < 10; i++){  \r\n       \/\/\u5728\u5faa\u73af\u4e2d\uff0cJava \u7f16\u8bd1\u5668\u65e0\u6cd5\u8fdb\u884c\u4f18\u5316\uff0c\u6240\u4ee5\u8981\u624b\u52a8\u4f7f\u7528StringBuilder  \r\n        sb.append(i);  \r\n    } \r\n<\/pre>\n
\u516d\u3001\u82e5\u9700\u9891\u7e41\u8c03\u7528Collection.contains \u65b9\u6cd5\u5219\u4f7f\u7528Set<\/strong><\/div>\n

\u5728Java \u96c6\u5408\u7c7b\u5e93\u4e2d\uff0cList\u7684contains \u65b9\u6cd5\u666e\u904d\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n)\uff0c\u82e5\u4ee3\u7801\u4e2d\u9700\u8981\u9891\u7e41\u8c03\u7528contains \u65b9\u6cd5\u67e5\u627e\u6570\u636e\u5219\u5148\u5c06\u96c6\u5408list \u8f6c\u6362\u6210HashSet \u5b9e\u73b0\uff0c\u5c06O(n) \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5c06\u4e3aO(1)\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u9891\u7e41\u8c03\u7528Collection.contains() \u53cd\u4f8b  \r\n    List list = new ArrayList<>();  \r\n    for (int i = 0; i <= Integer.MAX_VALUE; i++){  \r\n        \/\/\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n)  \r\n        if (list.contains(i))  \r\n        System.out.println(\"list contains \"+ i);  \r\n    } \r\n<\/object><\/pre>\n

\u6b63\u4f8b:<\/p>\n

\r\n    \/\/\u9891\u7e41\u8c03\u7528Collection.contains() \u6b63\u4f8b  \r\n    List list = new ArrayList<>();  \r\n    Set set = new HashSet<>();  \r\n    for (int i = 0; i <= Integer.MAX_VALUE; i++){  \r\n        \/\/\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(1)  \r\n        if (set.contains(i)){  \r\n            System.out.println(\"list contains \"+ i);  \r\n        }  \r\n    } \r\n<\/object><\/object><\/pre>\n
\u4e03\u3001\u4f7f\u7528\u9759\u6001\u4ee3\u7801\u5757\u5b9e\u73b0\u8d4b\u503c\u9759\u6001\u6210\u5458\u53d8\u91cf<\/strong><\/div>\n

\u5bf9\u4e8e\u96c6\u5408\u7c7b\u578b\u7684\u9759\u6001\u6210\u5458\u53d8\u91cf\uff0c\u5e94\u8be5\u4f7f\u7528\u9759\u6001\u4ee3\u7801\u5757\u8d4b\u503c\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u96c6\u5408\u5b9e\u73b0\u6765\u8d4b\u503c\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u8d4b\u503c\u9759\u6001\u6210\u5458\u53d8\u91cf\u53cd\u4f8b \r\n     private static Map map = new HashMap(){  \r\n        {  \r\n            map.put(\"Leo\",1);  \r\n            map.put(\"Family-loving\",2);  \r\n            map.put(\"Cold on the out side passionate on the inside\",3);  \r\n        }  \r\n    }; \r\n     private static List list = new ArrayList<>(){  \r\n        {  \r\n            list.add(\"Sagittarius\");  \r\n            list.add(\"Charming\");  \r\n            list.add(\"Perfectionist\");  \r\n        }  \r\n    }; \r\n<\/string><\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u8d4b\u503c\u9759\u6001\u6210\u5458\u53d8\u91cf\u6b63\u4f8b  \r\n    private static Map map = new HashMap();  \r\n    static {  \r\n        map.put(\"Leo\",1);  \r\n        map.put(\"Family-loving\",2);  \r\n        map.put(\"Cold on the out side passionate on the inside\",3);  \r\n    }  \r\n    private static List list = new ArrayList<>(); \r\n     static {  \r\n        list.add(\"Sagittarius\");  \r\n        list.add(\"Charming\");  \r\n        list.add(\"Perfectionist\");  \r\n    } \r\n<\/string><\/pre>\n
\u516b\u3001\u5220\u9664\u672a\u4f7f\u7528\u7684\u5c40\u90e8\u53d8\u91cf\u3001\u65b9\u6cd5\u53c2\u6570\u3001\u79c1\u6709\u65b9\u6cd5\u3001\u5b57\u6bb5\u548c\u591a\u4f59\u7684\u62ec\u53f7\u3002<\/strong><\/div>\n
\u4e5d\u3001\u5de5\u5177\u7c7b\u4e2d\u5c4f\u853d\u6784\u9020\u51fd\u6570<\/strong><\/div>\n

\u5de5\u5177\u7c7b\u662f\u4e00\u5806\u9759\u6001\u5b57\u6bb5\u548c\u51fd\u6570\u7684\u96c6\u5408\uff0c\u5176\u4e0d\u5e94\u8be5\u88ab\u5b9e\u4f8b\u5316\uff1b\u4f46\u662f\uff0cJava \u4e3a\u6bcf\u4e2a\u6ca1\u6709\u660e\u786e\u5b9a\u4e49\u6784\u9020\u51fd\u6570\u7684\u7c7b\u6dfb\u52a0\u4e86\u4e00\u4e2a\u9690\u5f0f\u516c\u6709\u6784\u9020\u51fd\u6570\uff0c\u4e3a\u4e86\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u5b9e\u4f8b\u5316\uff0c\u5e94\u8be5\u663e\u5f0f\u5b9a\u4e49\u79c1\u6709\u6784\u9020\u51fd\u6570\u6765\u5c4f\u853d\u8fd9\u4e2a\u9690\u5f0f\u516c\u6709\u6784\u9020\u51fd\u6570\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    public class PasswordUtils {  \r\n    \/\/\u5de5\u5177\u7c7b\u6784\u9020\u51fd\u6570\u53cd\u4f8b  \r\n    private static final Logger LOG = LoggerFactory.getLogger(PasswordUtils.class);  \r\n    public static final String DEFAULT_CRYPT_ALGO = \"PBEWithMD5AndDES\"; \r\n    public static String encryptPassword(String aPassword) throws IOException {  \r\n        return new PasswordUtils(aPassword).encrypt();  \r\n    } \r\n<\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    public class PasswordUtils {  \r\n    \/\/\u5de5\u5177\u7c7b\u6784\u9020\u51fd\u6570\u6b63\u4f8b  \r\n    private static final Logger LOG = LoggerFactory.getLogger(PasswordUtils.class);  \r\n    \/\/\u5b9a\u4e49\u79c1\u6709\u6784\u9020\u51fd\u6570\u6765\u5c4f\u853d\u8fd9\u4e2a\u9690\u5f0f\u516c\u6709\u6784\u9020\u51fd\u6570  \r\n    private PasswordUtils(){} \r\n    public static final String DEFAULT_CRYPT_ALGO = \"PBEWithMD5AndDES\";  \r\n    public static String encryptPassword(String aPassword) throws IOException {  \r\n        return new PasswordUtils(aPassword).encrypt();  \r\n    } \r\n<\/pre>\n
\u5341\u3001\u5220\u9664\u591a\u4f59\u7684\u5f02\u5e38\u6355\u83b7\u5e76\u8dd1\u51fa<\/strong><\/div>\n

\u7528catch \u8bed\u53e5\u6355\u83b7\u5f02\u5e38\u540e\uff0c\u82e5\u4ec0\u4e48\u4e5f\u4e0d\u8fdb\u884c\u5904\u7406\uff0c\u5c31\u53ea\u662f\u8ba9\u5f02\u5e38\u91cd\u65b0\u629b\u51fa\uff0c\u8fd9\u8ddf\u4e0d\u6355\u83b7\u5f02\u5e38\u7684\u6548\u679c\u4e00\u6837\uff0c\u53ef\u4ee5\u5220\u9664\u8fd9\u5757\u4ee3\u7801\u6216\u6dfb\u52a0\u522b\u7684\u5904\u7406\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u591a\u4f59\u5f02\u5e38\u53cd\u4f8b  \r\n    private static String fileReader(String fileName)throws IOException{  \r\n        try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {  \r\n            String line;  \r\n            StringBuilder builder = new StringBuilder();  \r\n            while ((line = reader.readLine()) != null) {  \r\n                builder.append(line);  \r\n            }  \r\n            return builder.toString();  \r\n        } catch (Exception e) {  \r\n            \/\/\u4ec5\u4ec5\u662f\u91cd\u590d\u629b\u5f02\u5e38 \u672a\u4f5c\u4efb\u4f55\u5904\u7406  \r\n            throw e;  \r\n        }  \r\n    } \r\n<\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u591a\u4f59\u5f02\u5e38\u6b63\u4f8b  \r\n    private static String fileReader(String fileName)throws IOException{  \r\n        try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {  \r\n            String line;  \r\n            StringBuilder builder = new StringBuilder();  \r\n            while ((line = reader.readLine()) != null) {  \r\n                builder.append(line);  \r\n            }  \r\n            return builder.toString();  \r\n            \/\/\u5220\u9664\u591a\u4f59\u7684\u629b\u5f02\u5e38\uff0c\u6216\u589e\u52a0\u5176\u4ed6\u5904\u7406\uff1a  \r\n            \/*catch (Exception e) {  \r\n                return \"fileReader exception\";  \r\n            }*\/  \r\n        }  \r\n    } \r\n<\/pre>\n
\u5341\u4e00\u3001\u5b57\u7b26\u4e32\u8f6c\u5316\u4f7f\u7528String.valueOf(value) \u4ee3\u66ff \" \" + value<\/strong><\/div>\n

\u628a\u5176\u5b83\u5bf9\u8c61\u6216\u7c7b\u578b\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\u65f6\uff0c\u4f7f\u7528String.valueOf(value) \u6bd4 \"\"+value \u7684\u6548\u7387\u66f4\u9ad8\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u628a\u5176\u5b83\u5bf9\u8c61\u6216\u7c7b\u578b\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\u53cd\u4f8b\uff1a  \r\n    int num = 520;  \r\n    \/\/ \"\" + value  \r\n    String strLove = \"\" + num; \r\n<\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u628a\u5176\u5b83\u5bf9\u8c61\u6216\u7c7b\u578b\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\u6b63\u4f8b\uff1a  \r\n    int num = 520;  \r\n    \/\/ String.valueOf() \u6548\u7387\u66f4\u9ad8  \r\n    String strLove = String.valueOf(num); \r\n<\/pre>\n
\u5341\u4e8c\u3001\u907f\u514d\u4f7f\u7528BigDecimal(double)<\/strong><\/div>\n

BigDecimal(double) \u5b58\u5728\u7cbe\u5ea6\u635f\u5931\u98ce\u9669\uff0c\u5728\u7cbe\u786e\u8ba1\u7b97\u6216\u503c\u6bd4\u8f83\u7684\u573a\u666f\u4e2d\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4e1a\u52a1\u903b\u8f91\u5f02\u5e38\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    \/\/ BigDecimal \u53cd\u4f8b      \r\n    BigDecimal bigDecimal = new BigDecimal(0.11D); \r\n<\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    \/\/ BigDecimal \u6b63\u4f8b  \r\n    BigDecimal bigDecimalbigDecimal1 = bigDecimal.valueOf(0.11D); \r\n<\/pre>\n
\u5341\u4e09\u3001\u8fd4\u56de\u7a7a\u6570\u7ec4\u548c\u96c6\u5408\u800c\u975e null<\/strong><\/div>\n

\u82e5\u7a0b\u5e8f\u8fd0\u884c\u8fd4\u56denull\uff0c\u9700\u8981\u8c03\u7528\u65b9\u5f3a\u5236\u68c0\u6d4bnull\uff0c\u5426\u5219\u5c31\u4f1a\u629b\u51fa\u7a7a\u6307\u9488\u5f02\u5e38\uff1b\u8fd4\u56de\u7a7a\u6570\u7ec4\u6216\u7a7a\u96c6\u5408\uff0c\u6709\u6548\u5730\u907f\u514d\u4e86\u8c03\u7528\u65b9\u56e0\u4e3a\u672a\u68c0\u6d4bnull \u800c\u629b\u51fa\u7a7a\u6307\u9488\u5f02\u5e38\u7684\u60c5\u51b5\uff0c\u8fd8\u53ef\u4ee5\u5220\u9664\u8c03\u7528\u65b9\u68c0\u6d4bnull \u7684\u8bed\u53e5\u4f7f\u4ee3\u7801\u66f4\u7b80\u6d01\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u8fd4\u56denull \u53cd\u4f8b  \r\n    public static Result[] getResults() {  \r\n        return null; \r\n     }  \r\n    public static List getResultList() {  \r\n        return null;  \r\n    }  \r\n    public static Map getResultMap() {  \r\n        return null;  \r\n    } \r\n<\/result><\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u8fd4\u56de\u7a7a\u6570\u7ec4\u548c\u7a7a\u96c6\u6b63\u4f8b  \r\n    public static Result[] getResults() {  \r\n        return new Result[0];  \r\n    }  \r\n    public static List getResultList() {  \r\n        return Collections.emptyList();  \r\n    }  \r\n    public static Map getResultMap() {  \r\n        return Collections.emptyMap();  \r\n    } \r\n<\/result><\/pre>\n
\u5341\u56db\u3001\u4f18\u5148\u4f7f\u7528\u5e38\u91cf\u6216\u786e\u5b9a\u503c\u8c03\u7528equals \u65b9\u6cd5<\/strong><\/div>\n

\u5bf9\u8c61\u7684equals \u65b9\u6cd5\u5bb9\u6613\u629b\u7a7a\u6307\u9488\u5f02\u5e38\uff0c\u5e94\u4f7f\u7528\u5e38\u91cf\u6216\u786e\u5b9a\u6709\u503c\u7684\u5bf9\u8c61\u6765\u8c03\u7528equals \u65b9\u6cd5\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u8c03\u7528 equals \u65b9\u6cd5\u53cd\u4f8b  \r\n    private static boolean fileReader(String fileName)throws IOException{  \r\n     \/\/ \u53ef\u80fd\u629b\u7a7a\u6307\u9488\u5f02\u5e38 \r\n      return fileName.equals(\"Charming\");  \r\n    } \r\n<\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    \/\/\u8c03\u7528 equals \u65b9\u6cd5\u6b63\u4f8b  \r\n    private static boolean fileReader(String fileName)throws IOException{  \r\n        \/\/ \u4f7f\u7528\u5e38\u91cf\u6216\u786e\u5b9a\u6709\u503c\u7684\u5bf9\u8c61\u6765\u8c03\u7528 equals \u65b9\u6cd5  \r\n        return \"Charming\".equals(fileName);   \r\n        \/\/\u6216\u4f7f\u7528\uff1ajava.util.Objects.equals() \u65b9\u6cd5  \r\n       return Objects.equals(\"Charming\",fileName);  \r\n    } \r\n<\/pre>\n
\u5341\u4e94\u3001\u679a\u4e3e\u7684\u5c5e\u6027\u5b57\u6bb5\u5fc5\u987b\u662f\u79c1\u6709\u4e14\u4e0d\u53ef\u53d8<\/strong><\/div>\n

\u679a\u4e3e\u901a\u5e38\u88ab\u5f53\u505a\u5e38\u91cf\u4f7f\u7528\uff0c\u5982\u679c\u679a\u4e3e\u4e2d\u5b58\u5728\u516c\u5171\u5c5e\u6027\u5b57\u6bb5\u6216\u8bbe\u7f6e\u5b57\u6bb5\u65b9\u6cd5\uff0c\u90a3\u4e48\u8fd9\u4e9b\u679a\u4e3e\u5e38\u91cf\u7684\u5c5e\u6027\u5f88\u5bb9\u6613\u88ab\u4fee\u6539\uff1b\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u679a\u4e3e\u4e2d\u7684\u5c5e\u6027\u5b57\u6bb5\u662f\u79c1\u6709\u7684\uff0c\u5e76\u5728\u79c1\u6709\u6784\u9020\u51fd\u6570\u4e2d\u8d4b\u503c\uff0c\u6ca1\u6709\u5bf9\u5e94\u7684Setter \u65b9\u6cd5\uff0c\u6700\u597d\u52a0\u4e0afinal \u4fee\u9970\u7b26\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    public enum SwitchStatus {  \r\n        \/\/ \u679a\u4e3e\u7684\u5c5e\u6027\u5b57\u6bb5\u53cd\u4f8b  \r\n        DISABLED(0, \"\u7981\u7528\"),  \r\n        ENABLED(1, \"\u542f\u7528\");  \r\n        public int value;  \r\n        private String description;  \r\n        private SwitchStatus(int value, String description) {  \r\n            this.value = value;  \r\n            this.description = description;  \r\n        }  \r\n        public String getDescription() {  \r\n            return description;  \r\n        }  \r\n        public void setDescription(String description) {  \r\n            this.description = description;  \r\n        }  \r\n    } \r\n<\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    public enum SwitchStatus {  \r\n        \/\/ \u679a\u4e3e\u7684\u5c5e\u6027\u5b57\u6bb5\u6b63\u4f8b  \r\n        DISABLED(0, \"\u7981\u7528\"),  \r\n        ENABLED(1, \"\u542f\u7528\");  \r\n        \/\/ final \u4fee\u9970  \r\n        private final int value;  \r\n        private final String description;  \r\n        private SwitchStatus(int value, String description) {  \r\n            this.value = value;  \r\n            this.description = description;  \r\n        }  \r\n        \/\/ \u6ca1\u6709Setter \u65b9\u6cd5  \r\n        public int getValue() {  \r\n            return value;  \r\n        }  \r\n        public String getDescription() {  \r\n            return description;  \r\n        }  \r\n    } \r\n<\/pre>\n
\u5341\u516d\u3001tring.split(String regex)\u90e8\u5206\u5173\u952e\u5b57\u9700\u8981\u8f6c\u8bd1<\/strong><\/div>\n

\u4f7f\u7528\u5b57\u7b26\u4e32String \u7684plit \u65b9\u6cd5\u65f6\uff0c\u4f20\u5165\u7684\u5206\u9694\u5b57\u7b26\u4e32\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5219\u90e8\u5206\u5173\u952e\u5b57\uff08\u6bd4\u5982 .[]()| \u7b49\uff09\u9700\u8981\u8f6c\u4e49\u3002<\/p>\n

\u53cd\u4f8b\uff1a<\/p>\n

\r\n    \/\/ String.split(String regex) \u53cd\u4f8b  \r\n    String[] split = \"a.ab.abc\".split(\".\");  \r\n    System.out.println(Arrays.toString(split));   \/\/ \u7ed3\u679c\u4e3a[]  \r\n    String[] split1 = \"a|ab|abc\".split(\"|\");  \r\n    System.out.println(Arrays.toString(split1));  \/\/ \u7ed3\u679c\u4e3a[\"a\", \"|\", \"a\", \"b\", \"|\", \"a\", \"b\", \"c\"] \r\n<\/pre>\n

\u6b63\u4f8b\uff1a<\/p>\n

\r\n    \/\/ String.split(String regex) \u6b63\u4f8b  \r\n    \/\/ . \u9700\u8981\u8f6c\u8bd1  \r\n    String[] split2 = \"a.ab.abc\".split(\"\\\\.\");  \r\n    System.out.println(Arrays.toString(split2));  \/\/ \u7ed3\u679c\u4e3a[\"a\", \"ab\", \"abc\"]  \r\n    \/\/ | \u9700\u8981\u8f6c\u8bd1  \r\n    String[] split3 = \"a|ab|abc\".split(\"\\\\|\");  \r\n    System.out.println(Arrays.toString(split3));  \/\/ \u7ed3\u679c\u4e3a[\"a\", \"ab\", \"abc\"]  \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u5f53\u9047\u5230\u591a\u4e2a\u67e5\u8be2\u6761\u4ef6\uff0c\u4f7f\u7528where 1=1 \u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u89e3\u51b3\u6211\u4eec\u7684\u95ee\u9898\uff0c\u4f46\u662f\u8fd9\u6837\u5f88\u53ef\u80fd\u4f1a\u9020\u6210\u975e\u5e38\u5927\u7684\u6027\u80fd\u635f\u5931\uff0c […]<\/p>\n","protected":false},"author":1898,"featured_media":202209,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[606],"class_list":["post-202206","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-606"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/202206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=202206"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/202206\/revisions"}],"predecessor-version":[{"id":202215,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/202206\/revisions\/202215"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/202209"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=202206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=202206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=202206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}