{"id":117940,"date":"2026-10-25T23:24:54","date_gmt":"2026-10-25T15:24:54","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/117940.html"},"modified":"2026-10-25T23:24:54","modified_gmt":"2026-10-25T15:24:54","slug":"spring-mvc%e5%b0%8f%e6%a1%88%e4%be%8b%ef%bc%881%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/117940.html","title":{"rendered":"Spring MVC\u5c0f\u6848\u4f8b\uff081\uff09"},"content":{"rendered":"<h2>\u4e00&#xff0c;\u52a0\u6cd5\u8ba1\u7b97\u5668<\/h2>\n<p><span style=\"color:#fe2c24\">\u8ba1\u7b97\u5668\u7684\u524d\u7aef\u9759\u6001\u9875\u9762\u4ee3\u7801&#xff1a;<\/span><\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html lang&#061;&#034;en&#034;&gt;<br \/>\n&lt;head&gt;<br \/>\n    &lt;meta charset&#061;&#034;UTF-8&#034;&gt;<br \/>\n    &lt;meta name&#061;&#034;viewport&#034; content&#061;&#034;width&#061;device-width, initial-scale&#061;1.0&#034;&gt;<br \/>\n    &lt;title&gt;Document&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n     &lt;form action&#061;&#034;calc\/sum&#034; method&#061;&#034;post&#034;&gt;<br \/>\n        &lt;h1&gt;\u8ba1\u7b97\u5668&lt;\/h1&gt;<br \/>\n        \u6570\u5b571&#xff1a;&lt;input name&#061;&#034;num1&#034; type&#061;&#034;text&#034;&gt;&lt;br&gt;<br \/>\n        \u6570\u5b572&#xff1a;&lt;input name&#061;&#034;num2&#034; type&#061;&#034;text&#034;&gt;&lt;br&gt;<br \/>\n        &lt;input type&#061;&#034;submit&#034; value&#061;&#034; \u70b9\u51fb\u76f8\u52a0 &#034;&gt;<br \/>\n    &lt;\/form&gt;<br \/>\n&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p>&#064;RestController<br \/>\npublic class CalcController {<br \/>\n    &#064;RequestMapping(&#034;\/calc\/sum&#034;)<br \/>\n    public String sum(&#064;RequestParam Integer num1, &#064;RequestParam Integer num2){<br \/>\n        int sum&#061;num1&#043;num2;<br \/>\n        return &#034;\u76f8\u52a0\u7684\u7ed3\u679c\u4e3a&#xff1a;&#034;&#043;sum;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u4ee3\u7801\u89e3\u91ca\u4ee5\u53ca\u6ce8\u610f\u4e8b\u9879&#xff1a;\u524d\u7aef\u4ee3\u7801\u4e2d\u7684name&#061;num1\u4ee5\u53caname&#061;num2\u5c31\u8ddf\u540e\u7aef\u4ee3\u7801\u4e2d\u7684num1\u548cnum2\u76f8\u5bf9\u5e94&#xff0c;\u4e5f\u5c31\u662f\u8bf4\u540e\u7aef\u662f\u53bb\u6536\u5230\u524d\u7aef\u4f20\u6765\u7684\u540d\u4e3anum1\u548cnum2\u7684\u53c2\u6570\u8fdb\u884c\u76f8\u52a0\u8fd4\u56de\u7ed3\u679c\u7684&#xff0c;\u5982\u679c\u4f60\u540e\u7aef\u4e0d\u60f3\u53eb\u8fd9\u4e2a\u540d\u5b57\u7684\u8bdd\u4e5f\u53ef\u4ee5\u901a\u8fc7&#064;RequestParam\u6ce8\u89e3\u6765\u8fdb\u884c\u540e\u7aef\u4ee3\u7801\u4e2d\u7684\u53c2\u6570\u7684\u6539\u540d&#xff0c;\u6211\u8fd9\u91cc\u6ca1\u6709\u5199&#xff0c;\u6211\u8fd9\u4e2a\u662f\u7528\u5230\u4e86\u8fd9\u4e2a\u6ce8\u89e3\u53e6\u4e00\u4e2a\u7279\u6027&#xff0c;\u5c31\u662f\u53c2\u6570\u4e0d\u80fd\u4e3a\u7a7a&#xff0c;\u7136\u540e\u524d\u7aef\u4ee3\u7801\u7684\u5f00\u5934\u662f\u5c06\u7528\u6237\u8f93\u5165\u7684\u83b7\u53d6\u5230\u5e76\u4e14\u4f20\u7ed9calc\/sum\u8fd9\u4e2a\u65b9\u6cd5&#xff0c;\u7136\u540e\u5c31\u662f\u5b8c\u6210\u4e86\u524d\u540e\u7aef\u7684\u4e00\u4e2a\u4ea4\u4e92\u4e86<\/p>\n<p>\u90a3\u53ef\u80fd\u4f1a\u6709\u4e00\u4e2a\u7591\u95ee\u8bf4\u4e3a\u4ec0\u4e48\u4f1a\u8df3\u8f6c\u5230\u53e6\u4e00\u4e2a\u7f51\u9875&#xff0c;\u8fd9\u4e2a\u662f\u90a3\u4e2a\u673a\u5236\u6216\u8005\u4ee3\u7801\u5b9e\u73b0\u7684\u5462&#xff1a;\u5173\u952e\u5c31\u5728\u524d\u7aef\u4ee3\u7801body\u4e2d\u5f00\u5934\u7684\u4e00\u884c&#xff0c;\u8fd9\u662fHTML\u8868\u5355\u7684\u9ed8\u8ba4\u63d0\u4ea4\u884c\u4e3a&#xff0c;\u5177\u4f53\u7684\u884c\u4e3a\u5982\u4e0b&#xff1a;<\/p>\n<p><span style=\"color:#1c7331\">\u5f53\u4f60\u70b9\u51fb\u300c\u70b9\u51fb\u76f8\u52a0\u300d\u6309\u94ae\u65f6&#xff0c;\u6d4f\u89c8\u5668\u9ed8\u8ba4\u4f1a\u505a\u4e09\u4ef6\u4e8b&#xff1a;<\/span><\/p>\n<li>\n<p><span style=\"color:#1c7331\">\u6536\u96c6\u8868\u5355\u4e2d\u7684 num1\u3001num2 \u4e24\u4e2a\u53c2\u6570\u3002<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color:#1c7331\">\u5411 action \u6307\u5b9a\u7684 \/calc\/sum \u63a5\u53e3\u53d1\u9001 POST \u8bf7\u6c42\u3002<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"color:#1c7331\">\u7528\u670d\u52a1\u5668\u8fd4\u56de\u7684\u54cd\u5e94\u66ff\u6362\u5f53\u524d\u6807\u7b7e\u9875\u663e\u793a\u7684\u5185\u5bb9\u3002<\/span><\/p>\n<\/li>\n<p><span style=\"color:#1c7331\">\u6240\u4ee5&#xff0c;\u4f60\u770b\u5230\u7684\u6548\u679c\u5c31\u662f&#xff1a;\u539f\u6765\u7684\u8ba1\u7b97\u5668\u9875\u9762\u4e0d\u89c1\u4e86&#xff0c;\u6d4f\u89c8\u5668\u5730\u5740\u53d8\u6210\u63a5\u53e3\u5730\u5740&#xff0c;\u9875\u9762\u663e\u793a\u8ba1\u7b97\u7ed3\u679c\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"623\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152448-6ade1f4069777.png\" width=\"1304\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"404\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152449-6ade1f41025b5.png\" width=\"637\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"390\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152449-6ade1f41195f9.png\" width=\"912\" \/><\/p>\n<h2>\u4e8c&#xff0c;\u7528\u6237\u767b\u5f55<\/h2>\n<p>\u6211\u4eec\u8981\u5b9e\u73b0\u4e00\u4e2a\u9875\u9762&#xff0c;\u5f53\u7528\u6237\u8f93\u5165\u7528\u6237\u548c\u5bc6\u7801\u9519\u8bef\u7684\u65f6\u5019&#xff0c;\u4f1a\u6709\u4e2a\u9519\u8bef\u7684\u5f39\u7a97\u63d0\u793a&#xff0c;\u5f53\u6b63\u786e\u7684\u65f6\u5019&#xff0c;\u6211\u4eec\u4f1a\u8df3\u8f6c\u5230\u4e00\u4e2a\u663e\u793a\u7740\u767b\u9646\u4eba&#xff1a;&#xff08;\u6b63\u786e\u7684\u767b\u5f55\u540d\u5b57&#xff09;\u8fd9\u6837\u7684\u9875\u9762<\/p>\n<p>\u90a3\u6211\u4eec\u9996\u5148\u9700\u8981\u7b2c\u4e00\u6b65\u5c31\u662f\u521b\u5efa\u4e00\u4e2a\u767b\u5f55\u7684\u63a5\u53e3&#xff0c;\u6839\u636e\u4f20\u5165\u7684\u540d\u5b57\u4ee5\u53ca\u5bc6\u7801\u6765\u5224\u65ad\u662f\u6b63\u786e\u8fd8\u662f\u9519\u8bef\u6765\u8fdb\u884c\u8fd4\u56de&#xff0c;\u8fd9\u91cc\u6211\u4eec\u9700\u8981\u6ce8\u610f\u7684\u662f\u7531\u4e8e\u6211\u4eec\u9700\u8981\u8fd4\u56de\u7684\u9875\u9762\u8981\u663e\u793a\u540d\u5b57&#xff0c;\u4f46\u662f\u6211\u4eechttp\u662f\u65e0\u8bb0\u5fc6\u7684&#xff0c;\u6240\u4ee5\u6211\u4eec\u9700\u8981\u7528\u5230session\u6765\u4fdd\u5b58\u6b63\u786e\u7684\u7528\u6237\u540d<\/p>\n<h3 style=\"background-color:transparent\">\u540e\u7aef\u767b\u5f55\u63a5\u53e3\u548c\u83b7\u53d6session\u4ee3\u7801<\/h3>\n<p>package com.example.demo;<br \/>\nimport jakarta.servlet.http.HttpSession;<br \/>\nimport org.springframework.util.StringUtils;<br \/>\nimport org.springframework.web.bind.annotation.RequestMapping;<br \/>\nimport org.springframework.web.bind.annotation.RestController;<br \/>\n&#064;RestController<br \/>\n&#064;RequestMapping(&#034;\/user&#034;)<br \/>\npublic class Userlogin {<br \/>\n    &#064;RequestMapping(&#034;\/login&#034;)<br \/>\n    public Boolean login(String userName, String password, HttpSession session){<br \/>\n        \/\/\u5148\u9a8c\u8bc1\u6570\u636e\u662f\u5426\u6709\u6548<br \/>\n        if (!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)){<br \/>\n            return false;<br \/>\n        }<br \/>\n        \/\/\u5224\u65ad\u6570\u636e\u662f\u5426\u5339\u914d&#xff0c;\u56e0\u4e3a\u6211\u4eec\u8fd8\u6ca1\u6709\u5b66\u4e60\u5230\u6570\u636e\u5e93\u8ddf\u8fd9\u4e2a\u7ed3\u5408\u7684\u5185\u5bb9&#xff0c;\u6240\u4ee5\u6211\u4eec\u5148\u4f7f\u7528\u56fa\u5b9a\u7684\u7528\u6237\u540d\u4ee5\u53ca\u5bc6\u7801<br \/>\n        if (&#034;admin&#034;.equals(userName)&amp;&amp;&#034;admin&#034;.equals(password)){<br \/>\n            \/\/\u56e0\u4e3ahttp\u6ca1\u6709\u8bb0\u5fc6&#xff0c;\u6240\u4ee5\u5f97\u7528\u4e0asession<br \/>\n            session.setAttribute(&#034;userName&#034;,userName);<br \/>\n            return true;<br \/>\n        }<br \/>\n        return false;<br \/>\n    }<br \/>\n    &#064;RequestMapping(&#034;\/getUsername&#034;)<br \/>\n    public String getUsername(HttpSession session){<br \/>\n        String userName &#061;(String) session.getAttribute(&#034;userName&#034;);<br \/>\n        return userName&#061;&#061;null?&#034;\u8d26\u53f7\u6216\u5bc6\u7801\u9519\u8bef&#034;:userName;<br \/>\n    }<\/p>\n<p>}<\/p>\n<p><span style=\"color:#fe2c24\">\u63a5\u4e0b\u6765\u662f\u5bf9\u4e8e\u63a5\u53e3\u7684\u6d4b\u8bd5<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"607\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152449-6ade1f413adef.png\" width=\"1309\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"595\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152449-6ade1f4180802.png\" width=\"1307\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"635\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152449-6ade1f41c4c58.png\" width=\"1320\" \/><\/p>\n<p>\u7b2c\u4e8c\u6b65\u5c31\u662f\u5f00\u59cb\u7f16\u8f91\u6211\u4eec\u7684\u9875\u9762&#xff0c;\u5728\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528ajax\u7684\u65b9\u5f0f\u6765\u7f16\u5199&#xff0c;\u5728\u5199\u4e4b\u524d&#xff0c;\u6211\u4eec\u9700\u8981\u5f15\u5165\u4e00\u4e2ajQuery&#xff0c;\u8fd9\u6837\u53ef\u4ee5\u8ba9\u6211\u4eec\u7684\u4ee3\u7801\u5199\u8d77\u6765\u66f4\u52a0\u7684\u65b9\u4fbf&#xff0c;\u6211\u4eec\u901a\u8fc7\u4e0b\u9762\u8fd9\u4e2a\u94fe\u63a5\u8fdb\u53bb\u53f3\u952e\u4e0b\u8f7d\u5230\u684c\u9762&#xff0c;\u7136\u540e\u5c06jQuery\u5f15\u5165\u8fdb\u6765<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"744\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152450-6ade1f4219b7d.png\" width=\"697\" \/><\/p>\n<p><span style=\"color:#fe2c24\">https:\/\/cdn.bootcdn.net\/ajax\/libs\/jquery\/3.6.4\/jquery.min.js<\/span><\/p>\n<h3 style=\"background-color:transparent\">ajax<\/h3>\n<p>ajax\u7684\u4ecb\u7ecd&#xff1a;<\/p>\n<p>\u7b80\u5355\u6765\u8bf4&#xff0c;AJAX \u662f\u4e00\u79cd\u8ba9\u6d4f\u89c8\u5668\u80fd\u591f\u5728\u4e0d\u91cd\u65b0\u52a0\u8f7d\u6574\u4e2a\u7f51\u9875\u7684\u60c5\u51b5\u4e0b&#xff0c;\u5411\u540e\u7aef\u53d1\u9001\u8bf7\u6c42\u5e76\u63a5\u6536\u54cd\u5e94\u7684\u6280\u672f&#xff08;\u8fd9\u6837\u5982\u679c\u6211\u4eec\u5728\u767b\u5f55\u4e00\u4e2a\u7f51\u7ad9\u7684\u65f6\u5019&#xff0c;\u5982\u679c\u8f93\u5165\u9519\u8bef\u4fe1\u606f&#xff0c;\u5c31\u4e0d\u4f1a\u5c06\u7f51\u9875\u5b8c\u5168\u7684\u91cd\u65b0\u52a0\u8f7d\u4e00\u904d&#xff0c;\u5bfc\u81f4\u8d26\u53f7\u5bc6\u7801\u9700\u8981\u5b8c\u5168\u91cd\u65b0\u8f93\u5165&#xff0c;\u800c\u662f\u53ef\u80fd\u76f4\u63a5\u8df3\u51fa\u4e00\u4e2a\u63d0\u793a\u4e4b\u7c7b\u7684&#xff09;<\/p>\n<p>ajax\u7684\u7279\u70b9&#xff1a;<\/p>\n<p>\u5f02\u6b65\u901a\u4fe1&#xff1a;\u53d1\u9001\u8bf7\u6c42\u540e&#xff0c;\u9875\u9762\u4e0d\u5fc5\u4e00\u76f4\u7b49\u5f85\u54cd\u5e94&#xff0c;\u53ef\u4ee5\u7ee7\u7eed\u6267\u884c\u5176\u4ed6\u64cd\u4f5c<\/p>\n<p>\u5c40\u90e8\u66f4\u65b0&#xff1a;\u53ea\u66f4\u65b0\u7f51\u9875\u4e2d\u9700\u8981\u53d8\u5316\u7684\u90e8\u5206&#xff0c;\u4e0d\u5fc5\u91cd\u65b0\u52a0\u8f7d\u6574\u4e2a\u9875\u9762<\/p>\n<p>\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u6570\u636e\u4f20\u8f93&#xff1a;\u53ef\u4ee5\u53ea\u8bf7\u6c42\u5f53\u524d\u9700\u8981\u7684\u6570\u636e&#xff0c;\u800c\u4e0d\u5fc5\u91cd\u65b0\u83b7\u53d6\u6574\u4e2a\u9875\u9762<\/p>\n<p>\u524d\u540e\u7aef\u4ea4\u4e92&#xff1a;\u53ef\u4ee5\u5411\u540e\u7aef\u63a5\u53e3\u53d1\u9001\u8bf7\u6c42&#xff0c;\u63a5\u6536 JSON\u3001\u6587\u672c\u7b49\u683c\u5f0f\u7684\u6570\u636e<\/p>\n<p>ajax\u7684\u57fa\u7840\u8bed\u6cd5&#xff1a;<\/p>\n<p>$(\u9009\u62e9\u5668).\u64cd\u4f5c();<\/p>\n<p>\u5e38\u89c1\u5199\u6cd5\u4e3e\u4e2a\u4f8b\u5b50&#xff1a;q<\/p>\n<p>$.ajax({<br \/>\n    url: &#034;\/user&#034;,<br \/>\n    type: &#034;GET&#034;,<br \/>\n    data: { id: 1 },<br \/>\n    dataType: &#034;json&#034;,<\/p>\n<p>    success: function(res) {<br \/>\n        console.log(res);<br \/>\n    },<\/p>\n<p>    error: function() {<br \/>\n        console.log(&#034;\u8bf7\u6c42\u5931\u8d25&#034;);<br \/>\n    }<br \/>\n});<\/p>\n<h3 style=\"background-color:transparent\">\u524d\u7aef\u7528\u6237\u767b\u5f55\u7684HTML\u4ee3\u7801&#xff08;\u767b\u5f55\u9875\u9762&#xff09;<\/h3>\n<p>\u89e3\u6790\u4e00\u4e0b\u8fd9\u91cc\u7684\u4ee3\u7801&#xff1a;<\/p>\n<p>\u6211\u4eec\u901a\u8fc7\u8868\u5355\u586b\u5199\u7684\u7528\u6237\u540d\u4ee5\u53ca\u5bc6\u7801&#xff0c;\u5728\u6211\u4eec\u7684ajax\u4e2d\u8fdb\u884c\u83b7\u53d6&#xff0c;\u5c31\u662fdata\u90a3\u4e00\u90e8\u5206&#xff0c;\u524d\u9762\u662f\u8bf7\u6c42\u65b9\u5f0f\u4ee5\u53ca\u8981\u4ea4\u7ed9\u7684\u54ea\u4e00\u4e2a\u65b9\u6cd5&#xff0c;\u5c31\u662f\u524d\u9762\u7684\u63a5\u53e3\u7684\u8def\u5f84&#xff08;\u8fd9\u91cc\u4e5f\u4f53\u73b0\u4e86ajax\u7684\u4e00\u4e2a\u5f02\u6b65\u7684\u7279\u70b9&#xff0c;\u5c31\u662f\u4e0d\u662f\u81ea\u5df1\u7b2c\u4e00\u65f6\u95f4\u5c31\u8fd4\u56de\u54cd\u5e94&#xff0c;\u800c\u662f\u7b49\u5f85\u6211\u4eec\u63a5\u53e3\u7684\u8fd4\u56de\u518d\u8fdb\u884c\u64cd\u4f5c&#xff09;&#xff0c;\u63a5\u4e0b\u6765\u5c31\u662f\u6210\u529f\u4e86&#xff08;\u4e5f\u5c31\u662f\u6b63\u5e38\u8fd4\u56de\u4e86http\u54cd\u5e94&#xff0c;\u800c\u4e0d\u662f\u8bf4\u8d26\u53f7\u5bc6\u7801\u6b63\u786e&#xff09;&#xff0c;\u8fd9\u91cc\u7684result\u5c31\u662f\u524d\u9762\u4f20\u5165\u7684\u65b9\u6cd5\u4e2d\u8fd4\u56de\u7684\u53c2\u6570&#xff0c;\u6211\u4eec\u7684\u53c2\u6570\u4e2d\u4e0d\u662f\u5b9a\u4e49\u4e86\u6b63\u786e\u8fd4\u56detrue&#xff0c;\u9519\u8bef\u8fd4\u56defalse&#xff0c;\u5982\u679c\u662ftrue&#xff0c;\u5c31\u8fdb\u884c\u8df3\u8f6c\u5176\u4e2dlocation.href\u5c31\u662f\u8df3\u8f6c\u7684\u4e00\u79cd\u65b9\u5f0f&#xff0c;\u9519\u8bef\u5c31\u8fdb\u884c\u5f39\u7a97&#xff08;alter&#xff09;<\/p>\n<p>&lt;h1&gt;\u7528\u6237\u767b\u5f55&lt;\/h1&gt;<br \/>\n\u7528\u6237\u540d&#xff1a;&lt;input name&#061;&#034;userName&#034; type&#061;&#034;text&#034; id&#061;&#034;userName&#034;&gt;&lt;br&gt;<br \/>\n\u5bc6\u7801&#xff1a;&lt;input name&#061;&#034;password&#034; type&#061;&#034;password&#034; id&#061;&#034;password&#034;&gt;&lt;br&gt;<br \/>\n&lt;input type&#061;&#034;button&#034; value&#061;&#034;\u767b\u5f55&#034; onclick&#061;&#034;login()&#034;&gt;<br \/>\n&lt;script src&#061;&#034;jquery.min.js&#034;&gt;&lt;\/script&gt;<br \/>\n&lt;script&gt;<br \/>\n    function login() {<br \/>\n    $.ajax({<br \/>\n      type:&#034;post&#034;,<br \/>\n      url:&#034;\/user\/login&#034;,<br \/>\n      data:{<br \/>\n        userName:$(&#034;#userName&#034;).val(),<br \/>\n        password:$(&#034;#password&#034;).val()<br \/>\n      },<br \/>\n      success:function(result){<br \/>\n        if(result){<br \/>\n          \/\/\u8d26\u53f7\u5bc6\u7801\u6b63\u786e\u5c31\u8df3\u8f6c<br \/>\n          location.href&#061;&#034;\/index.html&#034;;<br \/>\n        }else{<br \/>\n          \/\/\u9519\u8bef\u7684\u8bdd\u5c31\u8fdb\u884c\u5f39\u7a97<br \/>\n          alert(&#034;\u8d26\u53f7\u5bc6\u7801\u9519\u8bef&#034;);<br \/>\n        }<br \/>\n      }<br \/>\n    })<br \/>\n    }<br \/>\n  &lt;\/script&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"690\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152450-6ade1f42393ff.png\" width=\"1759\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"639\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152450-6ade1f42a9ad9.png\" width=\"1362\" \/><\/p>\n<p>\u6b63\u786e\u7684\u8bdd\u5c31\u8fdb\u884c\u8df3\u8f6c\u9875\u9762&#xff0c;\u4f46\u662f\u8fd9\u4e2a\u9875\u9762\u7684\u4ee3\u7801\u6211\u4eec\u8fd8\u6ca1\u6709\u5199<\/p>\n<h3>\u524d\u7aef\u663e\u793a\u7528\u6237\u540d\u7684HTML\u4ee3\u7801&#xff08;\u8df3\u8f6c\u9875\u9762&#xff09;<\/h3>\n<p>&lt;!doctype html&gt;<br \/>\n&lt;html lang&#061;&#034;en&#034;&gt;<br \/>\n&lt;head&gt;<br \/>\n    &lt;meta charset&#061;&#034;UTF-8&#034;&gt;<br \/>\n    &lt;meta name&#061;&#034;viewport&#034;<br \/>\n          content&#061;&#034;width&#061;device-width, user-scalable&#061;no, initial-scale&#061;1.0, maximum-scale&#061;1.0, minimum-scale&#061;1.0&#034;&gt;<br \/>\n    &lt;meta http-equiv&#061;&#034;X-UA-Compatible&#034; content&#061;&#034;ie&#061;edge&#034;&gt;<br \/>\n    &lt;title&gt;\u7528\u6237\u767b\u5f55\u9996\u9875&lt;\/title&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body&gt;<br \/>\n\u767b\u5f55\u4eba: &lt;span id&#061;&#034;loginUser&#034;&gt;&lt;\/span&gt;<br \/>\n&lt;script src&#061;&#034;jquery.min.js&#034;&gt;&lt;\/script&gt;<br \/>\n&lt;script&gt;<br \/>\n    $.ajax({<br \/>\n        type:&#034;get&#034;,<br \/>\n        url:&#034;user\/getUsername&#034;,<br \/>\n        success:function(Username){<br \/>\n            $(&#034;#loginUser&#034;).text(Username)<br \/>\n        }<br \/>\n    })<br \/>\n&lt;\/script&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"572\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152450-6ade1f42eefd1.png\" width=\"1260\" \/><\/p>\n<p>\u5199\u5230\u8fd9\u91cc\u6211\u8bb2\u4e00\u4e0b\u6211\u4e4b\u524d\u7684\u4e00\u4e2a\u7591\u60d1&#xff08;\u5173\u4e8esession\u662f\u600e\u4e48\u5b58\u50a8\u7684&#xff09;&#xff1a;<\/p>\n<p>\u6211\u4eec\u7ed3\u5408\u6211\u7684\u4ee3\u7801\u6765\u7406\u89e3\u5c31\u662f\u5f53\u6211\u4eec\u8f93\u5165\u9519\u8bef\u7684\u65f6\u5019&#xff0c;\u6211\u4eecsession\u4e2d\u5c31\u4e0d\u4f1a\u4fdd\u5b58name\u8fd9\u4e2a\u5c5e\u6027&#xff0c;\u5f53\u6211\u4eec\u6b63\u786e\u7684\u65f6\u5019\u624d\u4f1a\u4fdd\u5b58&#xff0c;\u6211\u4eec\u540e\u7aef\u8fd4\u56de\u7684\u9875\u9762\u8ddfsession\u4fe1\u606f\u5173\u7cfb\u5bc6\u5207&#xff0c;\u6211\u4eec\u4f1a\u6839\u636e\u5ba2\u6237\u7aef\u6240\u5e26\u7684cookie\u4e2d\u7684sessionid\u6765\u786e\u8ba4&#xff0c;\u5982\u679c\u662f\u9519\u8bef\u7684\u8bdd&#xff0c;\u6211\u4eec\u540e\u7aef\u62ff\u5230\u7684session\u91cc\u9762\u5c31\u538b\u6839\u6ca1\u6709\u5b58\u4efb\u4f55\u4e1c\u897f&#xff0c;\u6240\u4ee5\u8fd4\u56de\u7684\u7528\u6237\u540d\u4e5f\u5c31\u662f\u5565\u90fd\u6ca1\u6709\u7684&#xff0c;\u4f46\u662f\u6b63\u786e\u65f6\u5019\u62ff\u5230\u7684sessionid\u5f97\u5230\u7684session\u5c31\u662f\u6709\u6b63\u786e\u7684name\u7684&#xff0c;\u90a3\u6211\u4eec\u4f1a\u60f3&#xff1a;\u8fd9\u4e2asession\u7684\u4f7f\u7528\u5bff\u547d\u6216\u8005\u8303\u56f4\u662f\u600e\u4e48\u6765\u89c4\u5b9a\u7684\u5462&#xff0c;\u54ea\u79cd\u60c5\u51b5\u4f1a\u521b\u5efa\u65b0\u7684session<\/p>\n<table>\n<tbody>\n<tr>\n<p>\u573a\u666f<\/p>\n<p>\u901a\u5e38\u4f1a\u53d1\u751f\u4ec0\u4e48<\/p>\n<\/tr>\n<tr>\n<td>\n<p>\u540c\u4e00\u6d4f\u89c8\u5668\u8fde\u7eed\u53d1\u9001\u591a\u4e2a\u8bf7\u6c42<\/p>\n<\/td>\n<td>\n<p>\u627e\u5230\u540c\u4e00\u4e2a Session<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u540c\u4e00\u6d4f\u89c8\u5668\u5148\u767b\u5f55\u5931\u8d25&#xff0c;\u518d\u767b\u5f55\u6210\u529f<\/p>\n<\/td>\n<td>\n<p>\u539f Session \u4ecd\u6709\u6548\u65f6&#xff0c;\u901a\u5e38\u590d\u7528\u539f Session<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u540c\u4e00\u4e2a admin \u6362\u53e6\u4e00\u53f0\u7535\u8111\u767b\u5f55<\/p>\n<\/td>\n<td>\n<p>\u901a\u5e38\u521b\u5efa\u6216\u4f7f\u7528\u53e6\u4e00\u4e2a Session<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Session \u8d85\u65f6\u6216\u88ab\u9500\u6bc1\u540e\u518d\u6b21\u8bbf\u95ee<\/p>\n<\/td>\n<td>\n<p>\u901a\u5e38\u521b\u5efa\u65b0\u7684 Session<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>\u4e24\u4e2a\u4eba\u5171\u7528\u540c\u4e00\u4e2a\u6d4f\u89c8\u5668\u548c\u6709\u6548\u4f1a\u8bdd<\/p>\n<\/td>\n<td>\n<p>\u53ef\u80fd\u8bbf\u95ee\u540c\u4e00\u4e2a Session&#xff0c;\u4e0d\u80fd\u4ec5\u51ed Session \u533a\u5206\u5b9e\u9645\u64cd\u4f5c\u8005<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>session\u662f\u5426\u4f1a\u91cd\u65b0\u521b\u5efa\u5c31\u662f\u4e0a\u9762\u8fd9\u5f20\u8868\u6240\u8bf4\u7684&#xff0c;\u6240\u4ee5\u6211\u4eec\u5199\u7684\u4ee3\u7801\u7684\u60c5\u51b5&#xff0c;session\u5e76\u4e0d\u4f1a\u66f4\u65b0&#xff0c;\u9664\u975e\u4f60\u7b49\u5f88\u957f\u65f6\u95f4\u6216\u8005\u6362\u4e00\u4e2a\u6d4f\u89c8\u5668&#xff0c;\u8981\u4e0d\u77ed\u65f6\u95f4\u5728\u540c\u4e00\u4e2a\u6d4f\u89c8\u5668\u4e2dsession\u662f\u53ef\u80fd\u51fa\u73b0\u95ee\u9898\u7684&#xff0c;\u4e5f\u5c31\u662f\u8bf4\u8fd9\u4e2asession\u5e76\u4e0d\u80fd\u771f\u6b63\u7684\u786e\u8ba4\u7528\u6237\u662f\u4e0d\u662f\u6b63\u786e\u7684&#xff0c;\u56e0\u4e3a\u9519\u8bef\u7684\u8bdd\u662f\u4e0d\u5199&#xff0c;\u6b63\u786e\u7684\u8bdd\u662f\u5199\u8fdb\u53bb&#xff0c;\u4e5f\u5c31\u4ee3\u8868\u4e86\u6211\u4eec\u5199\u5b8c\u6b63\u786e\u7684\u4e4b\u540e&#xff0c;\u518d\u5199\u4e00\u4e2a\u9519\u8bef\u7684&#xff0c;session\u91cc\u9762\u8fd8\u662f\u5b58\u7684\u6b63\u786e\u65f6\u5019\u7684name&#xff0c;\u4f46\u662f\u597d\u5728\u6211\u4eec\u5f39\u7a97\u7684\u5224\u65ad\u662f\u76f4\u63a5\u6839\u636e\u8f93\u5165\u7684\u662f\u5426\u6b63\u786e&#xff0c;\u800c\u4e0d\u662f\u770bsession&#xff0c;\u6240\u4ee5\u4e0d\u4f1a\u51fa\u73b0\u6211\u4e0a\u4e00\u6b21\u662f\u6b63\u786e\u7684\u7136\u540e\u8df3\u8f6c&#xff0c;\u4e0b\u4e00\u6b21\u6211\u662f\u9519\u8bef\u7684\u4e5f\u8df3\u8f6c\u8fd9\u79cd\u60c5\u51b5&#xff0c;\u4f46\u662fsession\u4e0d\u505a\u5176\u4ed6\u5904\u7406\u7684\u8bdd\u662f\u201c\u9519\u8bef\u7684\u201d<\/p>\n<h2>\u4e09&#xff0c;\u7559\u8a00\u677f<\/h2>\n<p>\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u7559\u8a00\u677f&#xff0c;\u91cc\u9762\u5305\u542b\u4ece\u54ea\u91cc\u6765&#xff0c;\u5bf9\u8c01\u8bf4\u4ee5\u53ca\u8bf4\u4ec0\u4e48<\/p>\n<p>\u9996\u5148\u6211\u4eec\u5148\u521b\u5efa\u540e\u7aef\u63a5\u53e3&#xff0c;\u5148\u662f\u5b9a\u4e49\u4e00\u4e2a\u5bf9\u8c61&#xff0c;\u91cc\u9762\u5305\u542b\u6211\u4eec\u8981\u4f20\u8f93\u7684\u6570\u636e&#xff0c;\u5e76\u4e14\u5199\u51faget\u548cset\u65b9\u6cd5&#xff0c;\u8fd9\u4e9bget\u548cset\u65b9\u6cd5\u6bcf\u4e00\u6b21\u90fd\u5199\u4f1a\u5f88\u9ebb\u70e6&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5f15\u5165\u4e00\u4e2a\u4f9d\u8d56\u6765\u7b80\u5316\u6211\u4eec\u7684\u4ee3\u7801\u4e66\u5199<\/p>\n<h3>lombok<\/h3>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u6211\u4eec\u7b80\u5316\u4e00\u4e9b\u4e1c\u897f&#xff0c;\u6bd4\u5982get&#xff0c;set\u65b9\u6cd5&#xff0c;\u91cd\u5199\u7b49\u65b9\u6cd5&#xff0c;\u90a3\u5982\u4f55\u8fdb\u884c\u5f15\u5165\u5462<\/p>\n<p>\u65b9\u6cd5\u4e00&#xff1a;\u5728\u521b\u5efaspring\u9879\u76ee\u7684\u65f6\u5019\u52fe\u9009\u4e0alombok\u9009\u9879<\/p>\n<p>\u65b9\u6cd5\u4e8c&#xff1a;\u4e0b\u8f7d\u63d2\u4ef6&#xff1a;EditStarters<\/p>\n<p>\u65b9\u6cd5\u4e09&#xff1a;\u5728pom\u6587\u4ef6\u91cc\u6dfb\u52a0lombok\u76f8\u5173\u4f9d\u8d56\u4ee3\u7801<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u9009\u62e9\u5728\u7b2c\u4e09\u79cd\u65b9\u5f0f\u6765\u6dfb\u52a0<\/p>\n<p>&lt;dependency&gt;<br \/>\n&lt;groupId&gt;org.projectlombok&lt;\/groupId&gt;<br \/>\n&lt;artifactId&gt;lombok&lt;\/artifactId&gt;<br \/>\n&lt;optional&gt;true&lt;\/optional&gt;<br \/>\n&lt;\/dependency&gt;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"669\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152451-6ade1f43400ba.png\" width=\"1073\" \/><\/p>\n<p>\u600e\u4e48\u7528&#xff1a;<\/p>\n<p>&#xff08;\u76f4\u63a5\u5f15\u5165\u540e\u52a0\u6ce8\u89e3\u5c31\u53ef\u4ee5\u4e86&#xff09;<\/p>\n<table>\n<tbody>\n<tr>\n<p>\u6ce8\u89e3<\/p>\n<p>\u4f5c\u7528<\/p>\n<\/tr>\n<tr>\n<td>\n<p>&#064;Getter<\/p>\n<\/td>\n<td>\n<p>\u81ea\u52a8\u751f\u6210 Getter \u65b9\u6cd5&#xff0c;\u7528\u4e8e\u83b7\u53d6\u5c5e\u6027\u503c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>&#064;Setter<\/p>\n<\/td>\n<td>\n<p>\u81ea\u52a8\u751f\u6210 Setter \u65b9\u6cd5&#xff0c;\u7528\u4e8e\u4fee\u6539\u5c5e\u6027\u503c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>&#064;ToString<\/p>\n<\/td>\n<td>\n<p>\u81ea\u52a8\u751f\u6210 toString() \u65b9\u6cd5&#xff0c;\u65b9\u4fbf\u6253\u5370\u5bf9\u8c61\u4fe1\u606f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>&#064;EqualsAndHashCode<\/p>\n<\/td>\n<td>\n<p>\u81ea\u52a8\u751f\u6210 equals() \u548c hashCode() \u65b9\u6cd5<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>&#064;Data<\/p>\n<\/td>\n<td>\n<p>\u7efc\u5408\u6ce8\u89e3&#xff0c;\u5305\u542b Getter\u3001Setter\u3001ToString\u3001EqualsAndHashCode \u548c RequiredArgsConstructor \u7b49\u529f\u80fd<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u540e\u7aef\u7559\u8a00\u4ee5\u53ca\u62ff\u53d6\u7559\u8a00\u4ee3\u7801<\/h3>\n<p>\u6211\u4eec\u4e3a\u4e86\u5b58\u50a8\u6570\u636e&#xff0c;\u4e00\u822c\u662f\u5185\u5b58\u5b58\u50a8\u548c\u5916\u5b58&#xff08;\u786c\u76d8&#xff09;&#xff0c;\u8fd9\u91cc\u6211\u4eec\u9009\u62e9\u5185\u5b58&#xff0c;\u6211\u4eec\u9009\u62e9\u7684\u662f\u5c06\u6570\u636e\u5b58\u5728list\u5f53\u4e2d<\/p>\n<p>package com.example.demo;<br \/>\nimport org.springframework.util.StringUtils;<br \/>\nimport org.springframework.web.bind.annotation.RequestBody;<br \/>\nimport org.springframework.web.bind.annotation.RequestMapping;<br \/>\nimport org.springframework.web.bind.annotation.RestController;<br \/>\nimport java.util.ArrayList;<br \/>\nimport java.util.List;<br \/>\n&#064;RestController<br \/>\n&#064;RequestMapping(&#034;\/MessageController&#034;)<br \/>\npublic class MessageController {<br \/>\n    \/\/\u6211\u4eec\u5c06\u6570\u636e\u5b58\u653e\u5728\u5185\u5b58\u4e2d&#xff0c;\u4e5f\u5c31\u662f\u5148\u5199\u4e00\u4e2alist\u5b58\u5728\u91cc\u9762<br \/>\n    List&lt;MessageInfo&gt;list&#061;new ArrayList&lt;&gt;();<br \/>\n    \/\/\u53d1\u5e03\u7684\u63a5\u53e3<br \/>\n    &#064;RequestMapping(&#034;\/publish&#034;)<br \/>\n    public Boolean publish(&#064;RequestBody  MessageInfo messageInfo ){<br \/>\n        if (!StringUtils.hasLength(messageInfo.getFrom())||<br \/>\n                !StringUtils.hasLength(messageInfo.getTo())||<br \/>\n                !StringUtils.hasLength(messageInfo.getMes())){<br \/>\n            return false;<br \/>\n        }else {<br \/>\n            list.add(messageInfo);<br \/>\n            return true;<br \/>\n        }<br \/>\n    }<br \/>\n    \/\/\u52a0\u8f7d\u6570\u636e\u7684\u63a5\u53e3<br \/>\n    &#064;RequestMapping(&#034;\/getmes&#034;)<br \/>\n    public List&lt;MessageInfo&gt; getmes(){<br \/>\n        return list;<br \/>\n    }<br \/>\n}<\/p>\n<p>&#064;RequestBody\u7528\u6765\u544a\u8bc9 Spring MVC&#xff1a;\u4ece HTTP \u8bf7\u6c42\u4f53\u4e2d\u8bfb\u53d6\u6570\u636e&#xff0c;\u5e76\u5c1d\u8bd5\u5c06\u5176\u8f6c\u6362\u6210 Java \u5bf9\u8c61<\/p>\n<p>package com.example.demo;<br \/>\nimport lombok.Data;<br \/>\n&#064;Data<br \/>\npublic class MessageInfo {<br \/>\n    private String from;<br \/>\n    private String to;<br \/>\n    private String mes;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"609\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152451-6ade1f438ee40.png\" width=\"1295\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"553\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152451-6ade1f43e14c9.png\" width=\"1304\" \/><\/p>\n<h3 style=\"background-color:transparent\">\u524d\u7aef\u7559\u8a00\u677f\u4ee3\u7801<\/h3>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html lang&#061;&#034;en&#034;&gt;<\/p>\n<p>&lt;head&gt;<br \/>\n  &lt;meta charset&#061;&#034;UTF-8&#034;&gt;<br \/>\n  &lt;meta name&#061;&#034;viewport&#034; content&#061;&#034;width&#061;device-width, initial-scale&#061;1.0&#034;&gt;<br \/>\n  &lt;title&gt;\u7559\u8a00\u677f&lt;\/title&gt;<br \/>\n  &lt;style&gt;<br \/>\n        .container {<br \/>\n            width: 400px;<br \/>\n            height: 300px;<br \/>\n            margin: 0 auto;<br \/>\n            \/* border: 1px black solid; *\/<br \/>\n            text-align: center;<br \/>\n        }<\/p>\n<p>        .grey {<br \/>\n            color: grey;<br \/>\n        }<\/p>\n<p>        .container .row {<br \/>\n            width: 350px;<br \/>\n            height: 40px;<\/p>\n<p>            display: flex;<br \/>\n            justify-content: space-between;<br \/>\n            align-items: center;<br \/>\n        }<\/p>\n<p>        .container .row input {<br \/>\n            width: 260px;<br \/>\n            height: 30px;<br \/>\n        }<\/p>\n<p>        #submit {<br \/>\n            width: 350px;<br \/>\n            height: 40px;<br \/>\n            background-color: orange;<br \/>\n            color: white;<br \/>\n            border: none;<br \/>\n            margin: 10px;<br \/>\n            border-radius: 5px;<br \/>\n            font-size: 20px;<br \/>\n        }<br \/>\n    &lt;\/style&gt;<br \/>\n&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<br \/>\n&lt;div class&#061;&#034;container&#034;&gt;<br \/>\n  &lt;h1&gt;\u7559\u8a00\u677f&lt;\/h1&gt;<br \/>\n  &lt;p class&#061;&#034;grey&#034;&gt;\u8f93\u5165\u540e\u70b9\u51fb\u63d0\u4ea4, \u4f1a\u5c06\u4fe1\u606f\u663e\u793a\u4e0b\u65b9\u7a7a\u767d\u5904&lt;\/p&gt;<br \/>\n  &lt;div class&#061;&#034;row&#034;&gt;<br \/>\n    &lt;span&gt;\u8c01:&lt;\/span&gt; &lt;input type&#061;&#034;text&#034; name&#061;&#034;&#034; id&#061;&#034;from&#034;&gt;<br \/>\n  &lt;\/div&gt;<br \/>\n  &lt;div class&#061;&#034;row&#034;&gt;<br \/>\n    &lt;span&gt;\u5bf9\u8c01:&lt;\/span&gt; &lt;input type&#061;&#034;text&#034; name&#061;&#034;&#034; id&#061;&#034;to&#034;&gt;<br \/>\n  &lt;\/div&gt;<br \/>\n  &lt;div class&#061;&#034;row&#034;&gt;<br \/>\n    &lt;span&gt;\u8bf4\u4ec0\u4e48:&lt;\/span&gt; &lt;input type&#061;&#034;text&#034; name&#061;&#034;&#034; id&#061;&#034;say&#034;&gt;<br \/>\n  &lt;\/div&gt;<br \/>\n  &lt;input type&#061;&#034;button&#034; value&#061;&#034;\u63d0\u4ea4&#034; id&#061;&#034;submit&#034; onclick&#061;&#034;submit()&#034;&gt;<br \/>\n  &lt;!&#8211; &lt;div&gt;A \u5bf9 B \u8bf4: hello&lt;\/div&gt; &#8211;&gt;<br \/>\n&lt;\/div&gt;<\/p>\n<p>&lt;script src&#061;&#034;jquery.min.js&#034;&gt;&lt;\/script&gt;<br \/>\n&lt;script&gt;<br \/>\n        getmes();<br \/>\n        function getmes(){<br \/>\n            $.ajax({<br \/>\n                type:&#034;get&#034;,<br \/>\n                url:&#034;MessageController\/getmes&#034;,<br \/>\n                success:function(list){<br \/>\n                    \/\/\u6210\u529f\u5c31\u5c06\u5217\u8868\u904d\u5386\u5b8c\u5199\u5728\u4e0b\u9762<br \/>\n                    for(let messageInfo of list){<br \/>\n                        \/\/2. \u6784\u9020\u8282\u70b9<br \/>\n                        let divE &#061; &#034;&lt;div&gt;&#034;&#043;messageInfo.from &#043;&#034;\u5bf9&#034; &#043; messageInfo.to &#043; &#034;\u8bf4:&#034; &#043; messageInfo.mes&#043;&#034;&lt;\/div&gt;&#034;;<br \/>\n                        \/\/3. \u628a\u8282\u70b9\u6dfb\u52a0\u5230\u9875\u9762\u4e0a<br \/>\n                        $(&#034;.container&#034;).append(divE);<br \/>\n                    }<br \/>\n                }<br \/>\n            })<br \/>\n        }<br \/>\n        function submit(){<br \/>\n            \/\/1. \u83b7\u53d6\u7559\u8a00\u7684\u5185\u5bb9<br \/>\n            var from &#061; $(&#039;#from&#039;).val();<br \/>\n            var to &#061; $(&#039;#to&#039;).val();<br \/>\n            var say &#061; $(&#039;#say&#039;).val();<br \/>\n            if (from&#061;&#061; &#039;&#039; || to &#061;&#061; &#039;&#039; || say &#061;&#061; &#039;&#039;) {<br \/>\n                return;<br \/>\n            }<br \/>\n            \/\/\u63d0\u4ea4\u8bf7\u6c42<br \/>\n            $.ajax({<br \/>\n                type:&#034;post&#034;,<br \/>\n                url:&#034;MessageController\/publish&#034;,<br \/>\n                contentType:&#034;application\/json&#034;,<br \/>\n                data:JSON.stringify({<br \/>\n                    from:from,<br \/>\n                    to:to,<br \/>\n                    mes:say<br \/>\n                }),<br \/>\n                success:function(result){<br \/>\n                    if(result){<br \/>\n                        \/\/2. \u6784\u9020\u8282\u70b9<br \/>\n                        var divE &#061; &#034;&lt;div&gt;&#034;&#043;from &#043;&#034;\u5bf9&#034; &#043; to &#043; &#034;\u8bf4:&#034; &#043; say&#043;&#034;&lt;\/div&gt;&#034;;<br \/>\n                        \/\/3. \u628a\u8282\u70b9\u6dfb\u52a0\u5230\u9875\u9762\u4e0a<br \/>\n                        $(&#034;.container&#034;).append(divE);<br \/>\n                        \/\/4. \u6e05\u7a7a\u8f93\u5165\u6846\u7684\u503c<br \/>\n                        $(&#039;#from&#039;).val(&#034;&#034;);<br \/>\n                        $(&#039;#to&#039;).val(&#034;&#034;);<br \/>\n                        $(&#039;#say&#039;).val(&#034;&#034;);<br \/>\n                    }else{<br \/>\n                        alert(&#034;\u53d1\u8868\u7559\u8a00\u5931\u8d25&#034;);<br \/>\n                    }<br \/>\n                }<br \/>\n            })<br \/>\n        }<\/p>\n<p>    &lt;\/script&gt;<br \/>\n&lt;\/body&gt;<\/p>\n<p>&lt;\/html&gt;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"160\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152452-6ade1f443eb01.png\" width=\"343\" \/><\/p>\n<p>\u4ee3\u7801\u4e2d\u8fd9\u91cc\u524d\u9762\u7684from&#xff0c;to&#xff0c;mes\u662f\u6211\u4eec\u540e\u7aef\u7684\u6570\u636e\u7684\u547d\u540d&#xff0c;\u540e\u9762\u7684\u90a3\u4e2a\u662f\u6211\u4eec\u524d\u7aef\u8868\u683c\u4e2d\u83b7\u53d6\u7684\u6570\u636e\u7684\u540d\u79f0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"141\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152452-6ade1f4455673.png\" width=\"416\" \/><\/p>\n<p>\u8fd9\u91cc\u7684list\u662f\u6211\u4eec\u81ea\u5df1\u5b9a\u4e49\u7684\u4e00\u4e2a\u53d8\u91cf\u540d&#xff0c;\u63a5\u6536ajax\u6210\u529f\u8fd4\u56de\u7684\u6570\u636e&#xff0c;\u90a3\u4e48\u8fd9\u4e2a\u8fd4\u56de\u7684\u4e5f\u5c31\u662f\u7531\u6240\u6709\u7559\u8a00\u7ec4\u6210\u7684\u4e00\u4e2a\u6570\u7ec4&#xff0c;\u6bcf\u4e00\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u6574\u6761\u7684\u7559\u8a00&#xff0c;\u4e0b\u9762\u8fd9\u4e2amessageInfo\u4e5f\u662f\u6211\u4eec\u81ea\u5df1\u5b9a\u4e49\u7684&#xff0c;\u8868\u793a\u62ff\u5230\u7684\u662f\u4e00\u6574\u6761\u7684\u7559\u8a00&#xff0c;\u518d\u4e0b\u4e00\u884c\u4e2d\u5c31\u662f\u62ff\u5230\u6211\u4eec\u6bcf\u4e00\u884c\u7559\u8a00\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6570\u636e\u4e86&#xff0c;from&#xff0c;to&#xff0c;mes\u4e0d\u662f\u968f\u4fbf\u5b9a\u4e49\u7684&#xff0c;\u8fd9\u4e2a\u662f\u770b\u6211\u4eec\u540e\u7aef\u600e\u4e48\u547d\u540d\u7684<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1370\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152452-6ade1f44859f8.png\" width=\"2546\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00&#xff0c;\u52a0\u6cd5\u8ba1\u7b97\u5668\u8ba1\u7b97\u5668\u7684\u524d\u7aef\u9759\u6001\u9875\u9762\u4ee3\u7801&#xff1a;<\/p>\n<p><title>Document<\/title><\/p>\n<h1>\u8ba1\u7b97\u5668<\/p>\n","protected":false},"author":2,"featured_media":117924,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11820,99,1423,101,292],"topic":[],"class_list":["post-117940","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-atomgit","tag-java","tag-mvc","tag-spring","tag-292"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring MVC\u5c0f\u6848\u4f8b\uff081\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/117940.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring MVC\u5c0f\u6848\u4f8b\uff081\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00&#xff0c;\u52a0\u6cd5\u8ba1\u7b97\u5668\u8ba1\u7b97\u5668\u7684\u524d\u7aef\u9759\u6001\u9875\u9762\u4ee3\u7801&#xff1a; Document \u8ba1\u7b97\u5668\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/117940.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-25T15:24:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152448-6ade1f4069777.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117940.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/117940.html\",\"name\":\"Spring MVC\u5c0f\u6848\u4f8b\uff081\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-25T15:24:54+00:00\",\"dateModified\":\"2026-10-25T15:24:54+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/117940.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/117940.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117940.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring MVC\u5c0f\u6848\u4f8b\uff081\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring MVC\u5c0f\u6848\u4f8b\uff081\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/117940.html","og_locale":"zh_CN","og_type":"article","og_title":"Spring MVC\u5c0f\u6848\u4f8b\uff081\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00&#xff0c;\u52a0\u6cd5\u8ba1\u7b97\u5668\u8ba1\u7b97\u5668\u7684\u524d\u7aef\u9759\u6001\u9875\u9762\u4ee3\u7801&#xff1a; Document \u8ba1\u7b97\u5668","og_url":"https:\/\/www.wsisp.com\/helps\/117940.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-25T15:24:54+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261025152448-6ade1f4069777.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/117940.html","url":"https:\/\/www.wsisp.com\/helps\/117940.html","name":"Spring MVC\u5c0f\u6848\u4f8b\uff081\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-25T15:24:54+00:00","dateModified":"2026-10-25T15:24:54+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/117940.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/117940.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/117940.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Spring MVC\u5c0f\u6848\u4f8b\uff081\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=117940"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117940\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/117924"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=117940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=117940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=117940"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=117940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}