{"id":10008233,"date":"2023-09-06T09:42:39","date_gmt":"2023-09-06T01:42:39","guid":{"rendered":"https:\/\/blog.itmax.cn\/?p=10008233"},"modified":"2023-09-06T09:42:39","modified_gmt":"2023-09-06T01:42:39","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8java-react%e8%ae%a1%e7%ae%97%e4%b8%aa%e4%ba%ba%e6%89%80%e5%be%97%e7%a8%8e%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008233","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Java + React\u8ba1\u7b97\u4e2a\u4eba\u6240\u5f97\u7a0e\uff1f"},"content":{"rendered":"<p><strong>\u524d\u8a00<\/strong><\/p>\n<p>\u5728\u62a5\u8868\u6570\u636e\u5904\u7406\u4e2d\uff0cExcel\u516c\u5f0f\u62e5\u6709\u5f3a\u5927\u800c\u591a\u6837\u7684\u529f\u80fd\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u4e2a\u4e1a\u52a1\u9886\u57df\u3002\u65e0\u8bba\u662f\u6295\u8d44\u6536\u76ca\u8ba1\u7b97\u3001\u8d22\u52a1\u62a5\u8868\u7f16\u5236\u8fd8\u662f\u4fdd\u9669\u6536\u76ca\u4f30\u7b97\uff0cExcel\u516c\u5f0f\u90fd\u626e\u6f14\u7740\u4e0d\u53ef\u6216\u7f3a\u7684\u89d2\u8272\u3002\u4f20\u7edf\u7684\u505a\u6cd5\u662f\u76f4\u63a5\u4f9d\u8d56Excel\u6765\u5b9e\u73b0\u590d\u6742\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u5e76\u751f\u6210\u76f8\u5e94\u7684Excel\u6587\u4ef6\u3002\u56e0\u6b64\u53ea\u9700\u5728\u9884\u8bbe\u4f4d\u7f6e\u8f93\u5165\u76f8\u5e94\u53c2\u6570\uff0cExcel\u516c\u5f0f\u5373\u53ef\u88ab\u6fc0\u6d3b\uff0c\u8fc5\u901f\u8ba1\u7b97\u5e76\u5448\u73b0\u7ed3\u679c\u3002\u6b63\u56e0\u5982\u6b64\uff0c\u5728\u8fd9\u7c7b\u573a\u666f\u4e2d\uff0c\u4f01\u4e1a\u79ef\u7d2f\u4e86\u5927\u91cf\u7528\u4e8e\u8ba1\u7b97\u7684Excel\u6587\u4ef6\uff0c\u5b83\u4eec\u5df2\u7ecf\u6210\u4e3a\u4e86\u65e0\u4ef7\u7684\u8d22\u5bcc\u3002<\/p>\n<p>\u7136\u800c\uff0c\u4f20\u7edf\u7684Excel\u6587\u4ef6\u65b9\u5f0f\u5b58\u5728\u96be\u4ee5\u7ba1\u7406\u548c\u6570\u636e\u4e0d\u5b89\u5168\u7684\u7f3a\u70b9\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff0c\u53ef\u4ee5\u91c7\u7528B\/S\u67b6\u6784+Excel\u7ec4\u4ef6\u5e93\u7684\u65b9\u5f0f\u3002<\/p>\n<p>\u672c\u6587\u5c06\u4ee5\u4e2a\u4eba\u6240\u5f97\u7a0e\u7684\u8ba1\u7b97\u4e3a\u4f8b\uff0c\u4f7f\u7528React+Spring Boot+GcExcel\u6765\u5b9e\u73b0\u3002\u9996\u5148\u51c6\u5907\u597dExcel\u6587\u4ef6\uff0c\u6309\u7167\u56fd\u5bb6\u7a0e\u52a1\u603b\u5c40\u63d0\u4f9b\u7684\u4e2a\u7a0e\u8ba1\u7b97\u9875\u9762\u8fdb\u884c\u521b\u5efa\u3002<\/p>\n<p>\u4e2a\u4eba\u6240\u5f97\u7a0e\u7684\u6536\u5165\u7c7b\u578b\u67098\u79cd\uff1a<\/p>\n<ul>\n<li>\u5de5\u8d44\u85aa\u91d1\u6240\u5f97<\/li>\n<li>\u5e74\u7ec8\u5956\u6240\u5f97<\/li>\n<li>\u52b3\u52a1\u62a5\u916c\u6240\u5f97<\/li>\n<li>\u4e2a\u4f53\u5de5\u5546\u6237\u3001\u751f\u4ea7\u7ecf\u8425\u6240\u5f97<\/li>\n<li>\u916c\u52b3\u6240\u5f97<\/li>\n<li>\u5076\u7136\u6240\u5f97<\/li>\n<li>\u5229\u606f\u3001\u80a1\u606f\u3001\u7ea2\u5229\u6240\u5f97<\/li>\n<li>\u8d22\u4ea7\u8f6c\u8ba9\u6240\u5f97<\/li>\n<\/ul>\n<p>\u5176\u4e2d\uff0c\u5de5\u8d44\u85aa\u91d1\u6240\u5f97\u6700\u4e3a\u590d\u6742\uff0c\u5305\u62ec\u793e\u4f1a\u4fdd\u9669\u548c\u4e13\u9879\u6263\u9664\u3002\u6bcf\u79cd\u7c7b\u578b\u7684\u8ba1\u7a0e\u65b9\u5f0f\u90fd\u4e0d\u540c\uff0c\u4e3a\u4e86\u4fbf\u4e8e\u7406\u89e3\uff0c\u6211\u4eec\u4e3a\u6bcf\u4e2a\u7c7b\u578b\u521b\u5efa\u4e86\u4e00\u4e2a\u5de5\u4f5c\u8868\u8fdb\u884c\u8ba1\u7b97\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u51c6\u5907\u597d\u7684Excel\u6587\u4ef6\uff0c\u5176\u4e2d\u84dd\u8272\u90e8\u5206\u4e3a\u9700\u8981\u8f93\u5165\u53c2\u6570\u7684\u5355\u5143\u683c\uff0c\u5176\u4ed6\u5355\u5143\u683c\u5c06\u81ea\u52a8\u8ba1\u7b97\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044185836\" alt=\"\" title=\"\"><\/p>\n<p>\u5b8c\u6210\u51c6\u5907\u5de5\u4f5c\u540e\uff0c\u4e0b\u9762\u5f00\u59cb\u524d\u540e\u7aef\u5de5\u7a0b\u7684\u642d\u5efa\u3002<\/p>\n<p><strong>\u5b9e\u8df5<\/strong><\/p>\n<p><strong>\u524d\u7aef React<\/strong><\/p>\n<p><strong>\u521b\u5efaReact\u5de5\u7a0b<\/strong><\/p>\n<p>\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u5982TaxCalculator\uff0c\u8fdb\u5165\u6587\u4ef6\u5939\uff0c\u5728\u8d44\u6e90\u7ba1\u7406\u5668\u7684\u5730\u5740\u680f\u91cc\u8f93\u5165cmd\uff0c\u7136\u540e\u56de\u8f66\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\u3002\u4f7f\u7528\u4e0b\u9762\u7684\u4ee3\u7801\u521b\u5efa\u540d\u4e3aclient-app\u7684react app\u3002<\/p>\n<pre><code class=\"Bash\">npx create-react-app salary-client<\/code><\/pre>\n<p>\u8fdb\u5165\u521a\u521b\u5efa\u7684salary-client\u6587\u4ef6\u5939\uff0c\u4f7f\u7528IDE\uff0c\u6bd4\u5982VisualStudio Code\u6253\u5f00\u6587\u4ef6\u5939\u3002<\/p>\n<p><strong>\u754c\u9762\u90e8\u5206<\/strong><\/p>\n<p>\u4e2a\u4eba\u6240\u5f97\u7a0e\u6d89\u53ca\u7684\u6536\u5165\u7c7b\u578b\u4e00\u5171\u67098\u79cd\uff0c\u5176\u4e2d\uff08\u201c\u916c\u52b3\u6240\u5f97\u201d\uff0c\u201c\u5076\u7136\u6240\u5f97\u201d\uff0c\u201c\u5229\u606f\u3001\u80a1\u606f\u3001\u7ea2\u5229\u6240\u5f97\u201d\uff0c\u201c\u8d22\u4ea7\u8f6c\u8ba9\u6240\u5f97\u201d\uff09\u56db\u79cd\u7684\u8ba1\u7b97\u65b9\u5f0f\u63a5\u8fd1\uff0cUI\u5e03\u5c40\u76f8\u4f3c\uff0c\u501f\u52a9React\u7684component\u7279\u6027\uff0c\u6700\u7ec8\u9700\u8981\u63d0\u4f9b5\u79cd\u8868\u5355\u754c\u9762\u3002<\/p>\n<p>\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044185837\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e3a\u4e86\u8ba9UI\u770b\u8d77\u6765\u66f4\u597d\u770b\u4e00\u4e9b\uff0c\u53ef\u4ee5\u5148\u5f15\u5165\u4e00\u4e2aUI\u6846\u67b6\uff0c\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u4e86MUI\u3002<\/p>\n<pre><code class=\"Bash\">npm install @mui\/material @emotion\/react @emotion\/styled<\/code><\/pre>\n<p>\u9996\u5148\uff0c\u66f4\u65b0Src\/App.js\u7684\u4ee3\u7801\uff0c\u5176\u4e2d\u6dfb\u52a0\u4e86DarkMode\u7684Theme, \u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"JavaScript\">import '.\/App.css';\nimport { ThemeProvider } from '@emotion\/react';\nimport { createTheme } from '@mui\/material';\nimport { FormContainer } from '.\/Component\/FormContainer';\n\nconst darkTheme = createTheme({\n  palette: {\n    mode: 'dark',\n  },\n});\n\nfunction App() {\n  return (\n    &lt;ThemeProvider theme={darkTheme}&gt;\n      &lt;div className=&quot;App-header&quot;&gt;\n        &lt;h2&gt;\u4e2a\u4eba\u6240\u5f97\u7a0e\u8ba1\u7b97\u5668&lt;\/h2&gt;\n        &lt;FormContainer&gt;&lt;\/FormContainer&gt;\n      &lt;\/div&gt;\n    &lt;\/ThemeProvider&gt;\n  );\n}\n\nexport default App;<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0cApp.js\u4e2d\u5f15\u7528\u4e86FormContainer\uff0c\u4e0b\u6765\u6dfb\u52a0 .\/Component\/FormContainer.js\u3002<\/p>\n<p>FormContainer\u4e3b\u8981\u662f\u63d0\u4f9b\u4e00\u4e2aSelector\uff0c\u8ba9\u7528\u6237\u9009\u62e9\u6536\u5165\u7c7b\u578b\uff0c\u6839\u636e\u9009\u62e9\u7684\u7c7b\u578b\u6e32\u67d3\u4e0d\u540c\u7684\u7ec4\u4ef6\u3002<\/p>\n<pre><code class=\"JavaScript\">import React, { useState } from 'react';\nimport { SalaryIncome } from &quot;.\/SalaryIncome&quot;\nimport { NativeSelect, FormControl } from '@mui\/material';\nimport { BounsIncome } from '.\/BounsIncome';\nimport { CommercialIncome } from '.\/CommercialIncome';\nimport { LaborIncome } from '.\/LaborIncome';\nimport { OtherIncome } from '.\/OtherIncome';\n\nexport const FormContainer = () =&gt; {\n    const [calcType, setCalcType] = useState(&quot;\u5de5\u8d44\u85aa\u91d1\u6240\u5f97&quot;);\n\n    const GetIncomeControl = () =&gt; {\n        switch (calcType) {\n            case &quot;\u5de5\u8d44\u85aa\u91d1\u6240\u5f97&quot;:\n                return &lt;SalaryIncome calcType={calcType}&gt;&lt;\/SalaryIncome&gt;;\n            case &quot;\u5e74\u7ec8\u5956\u6240\u5f97&quot;:\n                return &lt;BounsIncome calcType={calcType}&gt;&lt;\/BounsIncome&gt;;\n            case &quot;\u52b3\u52a1\u62a5\u916c\u6240\u5f97&quot;:\n                return &lt;LaborIncome calcType={calcType}&gt;&lt;\/LaborIncome&gt;;\n            case &quot;\u4e2a\u4f53\u5de5\u5546\u6237\u3001\u751f\u4ea7\u7ecf\u8425\u6240\u5f97&quot;:\n                return &lt;CommercialIncome calcType={calcType}&gt;&lt;\/CommercialIncome&gt;;\n            default:\n                return &lt;OtherIncome calcType={calcType}&gt;&lt;\/OtherIncome&gt;;\n        }\n    }\n\n    return (\n        &lt;div style={{ width: &quot;60vw&quot;, marginTop: &quot;5vh&quot; }}&gt;\n            &lt;FormControl fullWidth sx={{ marginBottom: 2 }}&gt;\n                &lt;NativeSelect labelId=&quot;demo-simple-select-label&quot; id=&quot;demo-simple-select&quot;\n                    value={calcType} label=&quot;\u7c7b\u578b&quot; onChange={e =&gt; setCalcType(e.target.value)}                    &gt;\n                    &lt;option value=&quot;\u5de5\u8d44\u85aa\u91d1\u6240\u5f97&quot;&gt;\u5de5\u8d44\u85aa\u91d1\u6240\u5f97&lt;\/option&gt;\n                    &lt;option value=&quot;\u5e74\u7ec8\u5956\u6240\u5f97&quot;&gt;\u5e74\u7ec8\u5956\u6240\u5f97&lt;\/option&gt;\n                    &lt;option Item value=&quot;\u52b3\u52a1\u62a5\u916c\u6240\u5f97&quot;&gt;\u52b3\u52a1\u62a5\u916c\u6240\u5f97&lt;\/option&gt;\n                    &lt;option value=&quot;\u4e2a\u4f53\u5de5\u5546\u6237\u3001\u751f\u4ea7\u7ecf\u8425\u6240\u5f97&quot;&gt;\u4e2a\u4f53\u5de5\u5546\u6237\u3001\u751f\u4ea7\u7ecf\u8425\u6240\u5f97&lt;\/option&gt;\n                    &lt;option value=&quot;\u916c\u52b3\u6240\u5f97&quot;&gt;\u916c\u52b3\u6240\u5f97&lt;\/option&gt;\n                    &lt;option value=&quot;\u5076\u7136\u6240\u5f97&quot;&gt;\u5076\u7136\u6240\u5f97&lt;\/option&gt;\n                    &lt;option value=&quot;\u5229\u606f\u3001\u80a1\u606f\u3001\u7ea2\u5229\u6240\u5f97&quot;&gt;\u5229\u606f\u3001\u80a1\u606f\u3001\u7ea2\u5229\u6240\u5f97&lt;\/option&gt;\n                &lt;\/NativeSelect&gt;\n            &lt;\/FormControl&gt;\n            {GetIncomeControl()}\n        &lt;\/div&gt;);\n}<\/code><\/pre>\n<p>\u4f8b\u5982\uff1a\/&lt;SalaryIncome calcType={calcType}\/&gt;\/&lt;\/SalaryIncome\/&gt;; \u540c\u65f6\u4f1a\u5c06calcType\u4f20\u9012\u8fdb\u53bb\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u5206\u522b\u521b\u5efa\u51e0\u4e2axxxIncome\u7ec4\u4ef6\u3002<\/p>\n<p>1.\u5de5\u8d44\u85aa\u91d1\u6240\u5f97 SalaryIncome.js<\/p>\n<pre><code class=\"JavaScript\">import React, { useState } from 'react';\nimport { TextField, Button, Stack } from '@mui\/material';\nimport axios from 'axios';\n\nexport const SalaryIncome = (props) =&gt; {\n    const [income, setIncome] = useState(&quot;&quot;);\n    const [insurance, setInsurance] = useState(&quot;&quot;);\n    const [childEdu, setChildEdu] = useState(&quot;&quot;);\n    const [selfEdu, setSelfEdu] = useState(&quot;&quot;);\n    const [treatment, setTreatment] = useState(&quot;&quot;);\n    const [loans, setLoans] = useState(&quot;&quot;);\n    const [rent, setRent] = useState(&quot;&quot;);\n    const [elder, setElder] = useState(&quot;&quot;);\n\n    const [taxableIncome, setTaxableIncome] = useState(&quot;&quot;);\n    const [taxRate, setTaxRate] = useState(&quot;&quot;);\n    const [deduction, setDeduction] = useState(&quot;&quot;);\n    const [tax, setTax] = useState(&quot;&quot;);\n    const [takeHomeSalary, setTakeHomeSalary] = useState(&quot;&quot;);\n\n    async function calculateTax(event) {\n        event.preventDefault();\n        let res = await axios.post(&quot;api\/calcPersonTax&quot;, {\n            calcType: props.calcType,\n            income: income,\n            insurance: insurance,\n            childEdu: childEdu,\n            selfEdu: selfEdu,\n            treatment: treatment,\n            loans: loans,\n            rent: rent,\n            elder: elder,\n        });\n        if (res != null) {\n            let data = res.data;\n            setTaxableIncome(data.taxableIncome);\n            setTaxRate(data.taxRate);\n            setDeduction(data.deduction);\n            setTax(data.tax);\n            setTakeHomeSalary(data.takeHomeSalary);\n        }\n    }\n    function reset(event) {\n        event.preventDefault();\n        setIncome(&quot;&quot;);\n        setInsurance(&quot;&quot;);\n        setChildEdu(&quot;&quot;);\n        setSelfEdu(&quot;&quot;);\n        setTreatment(&quot;&quot;);\n        setLoans(&quot;&quot;);\n        setRent(&quot;&quot;);\n        setElder(&quot;&quot;);\n        setTaxableIncome(&quot;&quot;);\n        setTaxRate(&quot;&quot;);\n        setDeduction(&quot;&quot;);\n        setTax(&quot;&quot;);\n        setTakeHomeSalary(&quot;&quot;);\n    }\n\n    return (\n        &lt;div&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='primary'\n                    label=&quot;\u7a0e\u524d\u5de5\u8d44&quot; onChange={e =&gt; setIncome(e.target.value)}\n                    value={income} fullWidth required size=&quot;small&quot;\/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u793e\u4f1a\u4fdd\u9669\/\u516c\u79ef\u91d1&quot; onChange={e =&gt; setInsurance(e.target.value)}\n                    value={insurance} fullWidth size=&quot;small&quot;\/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u5b50\u5973\u6559\u80b2\u4e13\u9879\u6263\u9664&quot; onChange={e =&gt; setChildEdu(e.target.value)}\n                    value={childEdu} fullWidth size=&quot;small&quot;\/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u7ee7\u7eed\u6559\u80b2\u4e13\u9879\u6263\u9664&quot; onChange={e =&gt; setSelfEdu(e.target.value)}\n                    value={selfEdu} fullWidth size=&quot;small&quot;\/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u5927\u75c5\u533b\u7597\u4e13\u9879\u6263\u9664&quot; onChange={e =&gt; setTreatment(e.target.value)}\n                    value={treatment} fullWidth size=&quot;small&quot;\/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u4f4f\u623f\u8d37\u6b3e\u5229\u606f\u4e13\u9879\u6263\u9664&quot; onChange={e =&gt; setLoans(e.target.value)}\n                    value={loans} fullWidth size=&quot;small&quot;\/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u4f4f\u623f\u79df\u91d1\u4e13\u9879\u6263\u9664&quot; onChange={e =&gt; setRent(e.target.value)}\n                    value={rent} fullWidth size=&quot;small&quot;\/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u8d61\u517b\u8001\u4eba\u4e13\u9879\u6263\u9664&quot; onChange={e =&gt; setElder(e.target.value)}\n                    value={elder} fullWidth size=&quot;small&quot;\/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u8d77\u5f81\u70b9&quot; value=&quot;5000 \u5143\/\u6708&quot; fullWidth disabled size=&quot;small&quot;\/&gt;\n            &lt;\/Stack&gt;\n            &lt;hr&gt;&lt;\/hr&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;Button variant=&quot;outlined&quot; color=&quot;primary&quot; onClick={calculateTax} fullWidth size=&quot;large&quot;&gt;\u8ba1\u7b97&lt;\/Button&gt;\n                &lt;Button variant=&quot;outlined&quot; color=&quot;secondary&quot; onClick={reset} fullWidth size=&quot;large&quot;&gt;\u91cd\u7f6e&lt;\/Button&gt;\n            &lt;\/Stack&gt;\n            &lt;hr&gt;&lt;\/hr&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u5e94\u7eb3\u7a0e\u6240\u5f97\u989d&quot; value={taxableIncome} fullWidth disabled size=&quot;small&quot;\/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u7a0e\u7387&quot; value={taxRate} fullWidth disabled size=&quot;small&quot;\/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u901f\u7b97\u6263\u9664\u6570&quot; value={deduction} fullWidth disabled size=&quot;small&quot;\/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u5e94\u7eb3\u7a0e\u989d&quot; value={tax} fullWidth disabled size=&quot;small&quot;\/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary'\n                    label=&quot;\u7a0e\u540e\u5de5\u8d44&quot; value={takeHomeSalary} fullWidth disabled size=&quot;small&quot;\/&gt;\n            &lt;\/Stack&gt;\n\n        &lt;\/div&gt;\n    )\n}<\/code><\/pre>\n<p>2.\u5e74\u7ec8\u5956\u91d1\u6240\u5f97 BounsIncome.js<\/p>\n<pre><code class=\"JavaScript\">import React, { useState } from 'react';\nimport { TextField, Button, Stack } from '@mui\/material';\nimport axios from 'axios';\n\nexport const BounsIncome = (props) =&gt; {\n    const [income, setIncome] = useState(&quot;&quot;);\n\n    const [taxableIncome, setTaxableIncome] = useState(&quot;&quot;);\n    const [taxRate, setTaxRate] = useState(&quot;&quot;);\n    const [deduction, setDeduction] = useState(&quot;&quot;);\n    const [monthlyWage, setMonthlyWage] = useState(&quot;&quot;);\n    const [tax, setTax] = useState(&quot;&quot;);\n    const [takeHomeSalary, setTakeHomeSalary] = useState(&quot;&quot;);\n\n    async function calculateTax(event) {\n        event.preventDefault();\n        let res = await axios.post(&quot;api\/calcPersonTax&quot;, {\n            calcType: props.calcType,\n            income: income,\n        });\n        if (res != null) {\n            let data = res.data;\n            setTaxableIncome(data.taxableIncome);\n            setTaxRate(data.taxRate);\n            setDeduction(data.deduction);\n            setMonthlyWage(data.monthlyWage);\n            setTax(data.tax);\n            setTakeHomeSalary(data.takeHomeSalary);\n        }\n    }\n    function reset(event) {\n        event.preventDefault();\n        setIncome(&quot;&quot;);\n        setTaxableIncome(&quot;&quot;);\n        setTaxRate(&quot;&quot;);\n        setDeduction(&quot;&quot;);\n        setMonthlyWage(&quot;&quot;);\n        setTax(&quot;&quot;);\n        setTakeHomeSalary(&quot;&quot;);\n    }\n\n    return (\n        &lt;div&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='primary' size=&quot;small&quot;\n                    label=&quot;\u7a0e\u524d\u5de5\u8d44&quot; onChange={e =&gt; setIncome(e.target.value)}\n                    value={income} fullWidth required \/&gt;\n            &lt;\/Stack&gt;\n            &lt;hr&gt;&lt;\/hr&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;Button variant=&quot;outlined&quot; color=&quot;primary&quot; onClick={calculateTax} fullWidth size=&quot;large&quot;&gt;\u8ba1\u7b97&lt;\/Button&gt;\n                &lt;Button variant=&quot;outlined&quot; color=&quot;secondary&quot; onClick={reset} fullWidth size=&quot;large&quot;&gt;\u91cd\u7f6e&lt;\/Button&gt;\n            &lt;\/Stack&gt;\n            &lt;hr&gt;&lt;\/hr&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u5e94\u7eb3\u7a0e\u6240\u5f97\u989d&quot; value={taxableIncome} fullWidth disabled \/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u7a0e\u7387&quot; value={taxRate} fullWidth disabled \/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u901f\u7b97\u6263\u9664\u6570&quot; value={deduction} fullWidth disabled \/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u5e73\u5747\u6bcf\u6708\u5de5\u8d44&quot; value={monthlyWage} fullWidth disabled \/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u5e94\u7eb3\u7a0e\u989d&quot; value={tax} fullWidth disabled \/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u7a0e\u540e\u5de5\u8d44&quot; value={takeHomeSalary} fullWidth disabled \/&gt;\n            &lt;\/Stack&gt;\n\n        &lt;\/div&gt;\n    )\n}<\/code><\/pre>\n<p>3.\u52b3\u52a1\u62a5\u916c\u6240\u5f97 LaborIncome.js<\/p>\n<pre><code class=\"JavaScript\">import React, { useState } from 'react';\nimport { TextField, Button, Stack } from '@mui\/material';\nimport axios from 'axios';\n\nexport const LaborIncome = (props) =&gt; {\n    const [income, setIncome] = useState(&quot;&quot;);\n\n    const [taxableIncome, setTaxableIncome] = useState(&quot;&quot;);\n    const [taxRate, setTaxRate] = useState(&quot;&quot;);\n    const [deduction, setDeduction] = useState(&quot;&quot;);\n    const [nonTaxablePart, setNonTaxablePart] = useState(&quot;&quot;);\n    const [tax, setTax] = useState(&quot;&quot;);\n    const [takeHomeSalary, setTakeHomeSalary] = useState(&quot;&quot;);\n\n    async function calculateTax(event) {\n        event.preventDefault();\n        let res = await axios.post(&quot;api\/calcPersonTax&quot;, {\n            calcType: props.calcType,\n            income: income,\n        });\n        if (res != null) {\n            let data = res.data;\n            setTaxableIncome(data.taxableIncome);\n            setTaxRate(data.taxRate);\n            setDeduction(data.deduction);\n            setNonTaxablePart(data.nonTaxablePart);\n            setTax(data.tax);\n            setTakeHomeSalary(data.takeHomeSalary);\n        }\n    }\n    function reset(event) {\n        event.preventDefault();\n        setIncome(&quot;&quot;);\n        setTaxableIncome(&quot;&quot;);\n        setTaxRate(&quot;&quot;);\n        setDeduction(&quot;&quot;);\n        setNonTaxablePart(&quot;&quot;);\n        setTax(&quot;&quot;);\n        setTakeHomeSalary(&quot;&quot;);\n    }\n\n    return (\n        &lt;div&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='primary' size=&quot;small&quot;\n                    label=&quot;\u7a0e\u524d\u5de5\u8d44&quot; onChange={e =&gt; setIncome(e.target.value)}\n                    value={income} fullWidth required \/&gt;\n            &lt;\/Stack&gt;\n            &lt;hr&gt;&lt;\/hr&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;Button variant=&quot;outlined&quot; color=&quot;primary&quot; onClick={calculateTax} fullWidth size=&quot;large&quot;&gt;\u8ba1\u7b97&lt;\/Button&gt;\n                &lt;Button variant=&quot;outlined&quot; color=&quot;secondary&quot; onClick={reset} fullWidth size=&quot;large&quot;&gt;\u91cd\u7f6e&lt;\/Button&gt;\n            &lt;\/Stack&gt;\n            &lt;hr&gt;&lt;\/hr&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u5e94\u7eb3\u7a0e\u6240\u5f97\u989d&quot; value={taxableIncome} fullWidth disabled \/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u7a0e\u7387&quot; value={taxRate} fullWidth disabled \/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u901f\u7b97\u6263\u9664\u6570&quot; value={deduction} fullWidth disabled \/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u51cf\u9664\u8d39\u7528&quot; value={nonTaxablePart} fullWidth disabled \/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u5e94\u7eb3\u7a0e\u989d&quot; value={tax} fullWidth disabled \/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u7a0e\u540e\u5de5\u8d44&quot; value={takeHomeSalary} fullWidth disabled \/&gt;\n            &lt;\/Stack&gt;\n\n        &lt;\/div&gt;\n    )\n}<\/code><\/pre>\n<p>4.\u4e2a\u4f53\u5de5\u5546\u6237\u3001\u751f\u4ea7\u7ecf\u8425\u6240\u5f97 CommercialIncome.js<\/p>\n<pre><code class=\"JavaScript\">import React, { useState } from 'react';\nimport { TextField, Button, Stack } from '@mui\/material';\nimport axios from 'axios';\n\nexport const CommercialIncome = (props) =&gt; {\n    const [income, setIncome] = useState(&quot;&quot;);\n\n    const [taxableIncome, setTaxableIncome] = useState(&quot;&quot;);\n    const [taxRate, setTaxRate] = useState(&quot;&quot;);\n    const [deduction, setDeduction] = useState(&quot;&quot;);\n    const [tax, setTax] = useState(&quot;&quot;);\n    const [takeHomeSalary, setTakeHomeSalary] = useState(&quot;&quot;);\n\n    async function calculateTax(event) {\n        event.preventDefault();\n        let res = await axios.post(&quot;api\/calcPersonTax&quot;, {\n            calcType: props.calcType,\n            income: income,\n        });\n        if (res != null) {\n            let data = res.data;\n            setTaxableIncome(data.taxableIncome);\n            setTaxRate(data.taxRate);\n            setDeduction(data.deduction);\n            setTax(data.tax);\n            setTakeHomeSalary(data.takeHomeSalary);\n        }\n    }\n    function reset(event) {\n        event.preventDefault();\n        setIncome(&quot;&quot;);\n        setTaxableIncome(&quot;&quot;);\n        setTaxRate(&quot;&quot;);\n        setDeduction(&quot;&quot;);\n        setTax(&quot;&quot;);\n        setTakeHomeSalary(&quot;&quot;);\n    }\n\n    return (\n        &lt;div&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='primary' size=&quot;small&quot;\n                    label=&quot;\u7a0e\u524d\u5de5\u8d44&quot; onChange={e =&gt; setIncome(e.target.value)}\n                    value={income} fullWidth required \/&gt;\n            &lt;\/Stack&gt;\n            &lt;hr&gt;&lt;\/hr&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;Button variant=&quot;outlined&quot; color=&quot;primary&quot; onClick={calculateTax} fullWidth size=&quot;large&quot;&gt;\u8ba1\u7b97&lt;\/Button&gt;\n                &lt;Button variant=&quot;outlined&quot; color=&quot;secondary&quot; onClick={reset} fullWidth size=&quot;large&quot;&gt;\u91cd\u7f6e&lt;\/Button&gt;\n            &lt;\/Stack&gt;\n            &lt;hr&gt;&lt;\/hr&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u5e94\u7eb3\u7a0e\u6240\u5f97\u989d&quot; value={taxableIncome} fullWidth disabled \/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u7a0e\u7387&quot; value={taxRate} fullWidth disabled \/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u901f\u7b97\u6263\u9664\u6570&quot; value={deduction} fullWidth disabled \/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u5e94\u7eb3\u7a0e\u989d&quot; value={tax} fullWidth disabled \/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u7a0e\u540e\u5de5\u8d44&quot; value={takeHomeSalary} fullWidth disabled \/&gt;\n            &lt;\/Stack&gt;\n\n        &lt;\/div&gt;\n    )\n}<\/code><\/pre>\n<p>5.\u4f59\u4e0b\u56db\u79cd\u7c7b\u578b OtherIncome.js<\/p>\n<pre><code class=\"JavaScript\">import React, { useState } from 'react';\nimport { TextField, Button, Stack } from '@mui\/material';\nimport axios from 'axios';\n\nexport const OtherIncome = (props) =&gt; {\n    const [income, setIncome] = useState(&quot;&quot;);\n\n    const [taxableIncome, setTaxableIncome] = useState(&quot;&quot;);\n    const [taxRate, setTaxRate] = useState(&quot;&quot;);\n    const [tax, setTax] = useState(&quot;&quot;);\n    const [takeHomeSalary, setTakeHomeSalary] = useState(&quot;&quot;);\n\n    async function calculateTax(event) {\n        event.preventDefault();\n        let res = await axios.post(&quot;api\/calcPersonTax&quot;, {\n            calcType: props.calcType,\n            income: income,\n        });\n        if (res != null) {\n            let data = res.data;\n            setTaxableIncome(data.taxableIncome);\n            setTaxRate(data.taxRate);\n            setTax(data.tax);\n            setTakeHomeSalary(data.takeHomeSalary);\n        }\n    }\n    function reset(event) {\n        event.preventDefault();\n        setIncome(&quot;&quot;);\n        setTaxableIncome(&quot;&quot;);\n        setTaxRate(&quot;&quot;);\n        setTax(&quot;&quot;);\n        setTakeHomeSalary(&quot;&quot;);\n    }\n\n    return (\n        &lt;div&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='primary' size=&quot;small&quot;\n                    label={props.calcType} onChange={e =&gt; setIncome(e.target.value)}\n                    value={income} fullWidth required \/&gt;\n            &lt;\/Stack&gt;\n            &lt;hr&gt;&lt;\/hr&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;Button variant=&quot;outlined&quot; color=&quot;primary&quot; onClick={calculateTax} fullWidth size=&quot;large&quot;&gt;\u8ba1\u7b97&lt;\/Button&gt;\n                &lt;Button variant=&quot;outlined&quot; color=&quot;secondary&quot; onClick={reset} fullWidth size=&quot;large&quot;&gt;\u91cd\u7f6e&lt;\/Button&gt;\n            &lt;\/Stack&gt;\n            &lt;hr&gt;&lt;\/hr&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u5e94\u7eb3\u7a0e\u6240\u5f97\u989d&quot; value={taxableIncome} fullWidth disabled \/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u7a0e\u7387&quot; value={taxRate} fullWidth disabled \/&gt;\n            &lt;\/Stack&gt;\n            &lt;Stack spacing={2} direction=&quot;row&quot; sx={{ marginBottom: 2 }}&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u5e94\u7eb3\u7a0e\u989d&quot; value={tax} fullWidth disabled \/&gt;\n                &lt;TextField type=&quot;text&quot; variant='outlined' color='secondary' size=&quot;small&quot;\n                    label=&quot;\u7a0e\u540e\u5de5\u8d44&quot; value={takeHomeSalary} fullWidth disabled \/&gt;\n            &lt;\/Stack&gt;\n        &lt;\/div&gt;\n    )\n}<\/code><\/pre>\n<p>\u6b64\u65f6\uff0c\u5b8c\u6210UI\u90e8\u5206\u540e\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u8fd0\u884c\u8d77\u6765\uff0c\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"Bash\">\/\/\u901a\u8fc7\u4ee3\u7801\u8fd0\u884cReact app\nnpm start<\/code><\/pre>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044185839\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u53ef\u4ee5\u8bd5\u7740\u586b\u4e00\u4e9b\u6570\u636e\uff0c\u4f46\u662f\u5f53\u6211\u4eec\u70b9\u51fb\u8ba1\u7b97\u65f6\u4f1a\u62a5\u9519\uff0c\u8fd9\u662f\u56e0\u4e3a\u670d\u52a1\u7aef\u8fd8\u6ca1\u6709\u51c6\u5907\u597d\u3002<\/p>\n<p><strong>\u524d\u7aef\u8bf7\u6c42\u90e8\u5206<\/strong><\/p>\n<p>\u719f\u6089Axios\u7684\u540c\u5b66\u53ef\u4ee5\u8df3\u8fc7\u8fd9\u90e8\u5206\uff0c\u524d\u9762\u7684\u4ee3\u7801\u91cc\uff0c\u5df2\u7ecf\u7ed9\u51fa\u4e86Axois\u53d1\u9001\u8bf7\u6c42\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u65e0\u8bba\u662f\u54ea\u4e00\u79cd\u7c7b\u578b\u7684\u7ec4\u4ef6\uff0c\u8bf7\u6c42\u90fd\u53d1\u9001\u5230\u4e86\u76f8\u540c\u7684url\uff08&#8221;api\/calcPersonTax&#8221;\uff09\uff0c\u4ee5SalaryIncome\u4e3a\u4f8b\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"JavaScript\">async function calculateTax(event) {\n        event.preventDefault();\n        let res = await axios.post(&quot;api\/calcPersonTax&quot;, {\n            calcType: props.calcType,\n            income: income,\n            insurance: insurance,\n            childEdu: childEdu,\n            selfEdu: selfEdu,\n            treatment: treatment,\n            loans: loans,\n            rent: rent,\n            elder: elder,\n        });\n        if (res != null) {\n            let data = res.data;\n            setTaxableIncome(data.taxableIncome);\n            setTaxRate(data.taxRate);\n            setDeduction(data.deduction);\n            setTax(data.tax);\n            setTakeHomeSalary(data.takeHomeSalary);\n        }\n    }<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u6574\u4e2a\u8bf7\u6c42\u53d8\u5f97\u975e\u5e38\u7b80\u5355\uff0c\u4e3b\u8981\u662f\u628astate\u7684\u503c\u53d6\u51fa\u6765\uff0c\u901a\u8fc7post\u8bf7\u6c42\u53d1\u9001\u5230\u670d\u52a1\u7aef\uff0c\u7136\u540e\u6839\u636e\u8fd4\u56de\u503c\uff0c\u628a\u6570\u636e\u91cd\u65b0\u8bbe\u7ed9state\uff0c\u8fd9\u6837\u5c31\u5b8c\u6210UI\u6570\u636e\u7684\u66f4\u65b0\u4e86\u3002<\/p>\n<p><strong>\u914d\u7f6e\u8bf7\u6c42\u8f6c\u53d1\u4e2d\u95f4\u4ef6<\/strong><\/p>\n<p>\u6211\u4eec\u5728\u8bf7\u6c42\u65f6\u8bbf\u95ee\u7684\u662f\u76f8\u5bf9\u5730\u5740\uff0cReact\u672c\u8eab\u6709\u4e00\u4e2anodeJS\uff0c\u9ed8\u8ba4\u7684\u7aef\u53e3\u662f3000\uff0c\u800cSpring Boot\u7684\u9ed8\u8ba4\u7aef\u53e3\u662f8080\u3002\u524d\u7aef\u76f4\u63a5\u8bbf\u95ee\u4f1a\u6709\u8de8\u57df\u7684\u95ee\u9898\uff0c\u56e0\u6b64\u6211\u4eec\u8981\u505a\u4e00\u4e2a\u4ee3\u7406\u7684\u914d\u7f6e\u3002<\/p>\n<p>\u5728src\u6587\u4ef6\u5939\u4e0b\u9762\u6dfb\u52a0\u6587\u4ef6\uff0c\u540d\u4e3asetupProxy.js\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"JavaScript\">const { createProxyMiddleware } = require('http-proxy-middleware');\n\nmodule.exports = function(app) {\n  app.use(\n    '\/api',\n    createProxyMiddleware({\n      target: 'http:\/\/localhost:8080',\n      changeOrigin: true,\n    })\n  );\n};<\/code><\/pre>\n<p><strong>\u670d\u52a1\u7aef Spring Boot<\/strong><\/p>\n<p><strong>\u521b\u5efa\u5de5\u7a0b\u53ca\u6dfb\u52a0\u4f9d\u8d56<\/strong><\/p>\n<p>\u4f7f\u7528IDEA\u521b\u5efa\u4e00\u4e2aSpring Boot\u5de5\u7a0b\uff0c\u5982\u679c\u4f7f\u7528\u7684\u662f\u793e\u533a\uff08community\uff09\u7248\u672c\uff0c\u4e0d\u80fd\u76f4\u63a5\u521b\u5efaSpring Boot\u9879\u76ee\uff0c\u90a3\u53ef\u4ee5\u5148\u521b\u5efa\u4e00\u4e2a\u7a7a\u9879\u76ee\uff0cidea\u521b\u5efaproject\u7684\u8fc7\u7a0b\uff0c\u5c31\u8df3\u8fc7\u4e86\uff0c\u8fd9\u91cc\u6211\u4eec\u4ee5\u521b\u5efa\u4e86\u4e00\u4e2agradle\u9879\u76ee\u4e3a\u4f8b\u3002<\/p>\n<pre><code class=\"Scheme\">plugins {\n    id 'org.springframework.boot' version '3.0.0'\n    id 'io.spring.dependency-management' version '1.1.0'\n    id 'java'\n    id 'war'\n}\n\ngroup = 'org.example'\nversion = '1.0-SNAPSHOT'\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation 'org.springframework.boot:spring-boot-starter-web'\n    implementation 'com.grapecity.documents:gcexcel:6.2.0'\n    implementation 'javax.json:javax.json-api:1.1.4'\n    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'\n    testImplementation('org.springframework.boot:spring-boot-starter-test')\n}\n\ntest {\n    useJUnitPlatform()\n}<\/code><\/pre>\n<p>\u5728dependencies \u4e2d\uff0c\u6211\u4eec\u9664\u4e86\u4f9d\u8d56Spring Boot\u4e4b\u5916\uff0c\u8fd8\u6dfb\u52a0\u4e86GcExcel\u7684\u4f9d\u8d56\uff0c\u540e\u9762\u5bfc\u51fa\u65f6\u4f1a\u7528\u5230GcExcel\uff0c\u76ee\u524d\u7684\u7248\u672c\u662f6.2.0\u3002<\/p>\n<p><strong>\u6dfb\u52a0API<\/strong><\/p>\n<p>\u5728Application\u7c7b\u4e0a\uff0c\u6dfb\u52a0\u5c5e\u6027 @RequestMapping(&#8220;\/api&#8221;).\uff0c\u5e76\u6dfb\u52a0 calcPersonTax API\u3002<\/p>\n<pre><code class=\"Java\">@Spring BootApplication\n@RestController\n@RequestMapping(&quot;\/api&quot;)\npublic class SalaryTaxCalculator {\n    public static void main(String[] args) {\n        SpringApplication.run(SalaryTaxCalculator.class, args);\n    }\n\n    @PostMapping(&quot;\/calcPersonTax&quot;)\n    public CalcResult calcTax(@RequestBody CalcParameter par) {\n        Workbook workbook = new Workbook();\n        workbook.open(GetResourcePath());\n        return CalcInternal(workbook, par);\n    }\n    \n    private String GetResourcePath(){\n        return Objects.requireNonNull(SalaryTaxCalculator.class.getClassLoader().getResource(&quot;PersonalTaxCalcEngine.xlsx&quot;)).getPath();\n    }\n    \n    private CalcResult CalcInternal(Workbook workbook, CalcParameter par) {\n        \/\/todo\n    }\n}<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\u5728CalcInternal\u65b9\u6cd5\u5185\uff0c\u6211\u4eec\u4f7f\u7528GcExcel\uff0c\u6839\u636ecalcType\u6765\u5224\u65ad\u4f7f\u7528\u54ea\u4e00\u4e2asheet\u6765\u8fdb\u884c\u8ba1\u7b97\u3002\u5bf9\u4e0d\u540cSheet\u53ea\u9700\u8981\u901a\u8fc7GcExcel\u8bbe\u503c\uff0c\u5e76\u4ece\u7279\u5b9a\u7684\u683c\u5b50\u91cc\u53d6\u503c\u5373\u53ef\u3002<\/p>\n<p>\u540c\u65f6\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u521b\u5efa\u4e24\u4e2a\u7c7b\uff0cCalcParameter\u548cCalcResult\u3002CalcParameter\u7528\u4e8e\u4ecerequest\u4e2d\u628apost\u7684data\u89e3\u6790\u51fa\u6765\uff0cCalcResult\u7528\u4e8e\u5728response\u4e2d\u8fd4\u56de\u7684\u6570\u636e\u3002<\/p>\n<p>CalcParameter:<\/p>\n<pre><code class=\"JavaScript\">public class CalcParameter {\n    public String calcType;\n    public double income;\n    public double insurance;\n    public double childEdu;\n    public double selfEdu;\n    public double treatment;\n    public double loans;\n    public double rent;\n    public double elder;\n}<\/code><\/pre>\n<p>CalcResult:<\/p>\n<pre><code class=\"JavaScript\">public class CalcResult {\n    public double taxableIncome;\n    public double taxRate;\n    public double deduction;\n    public double tax;\n    public double takeHomeSalary;\n    public double monthlyWage;\n    public double nonTaxablePart;\n}<\/code><\/pre>\n<p><strong>\u4f7f\u7528GcExcel\u5b8c\u6210\u516c\u5f0f\u8ba1\u7b97<\/strong><\/p>\n<p>\u524d\u9762\u6211\u4eec\u5b9a\u4e49\u4e86 CalcInternal\uff0c\u5728 CalcInternal \u4e2d\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528GcExcel\u6765\u5b8c\u6210\u516c\u5f0f\u8ba1\u7b97\u3002<\/p>\n<p>GcExcel\u7684\u516c\u5f0f\u8ba1\u7b97\u662f\u81ea\u52a8\u5b8c\u6210\u7684\uff0c\u6211\u4eec\u4f7f\u7528workbook\u6253\u5f00Excel\u6587\u4ef6\u540e\uff0c\u53ea\u9700\u8981set\u76f8\u5173\u7684value\u3002\u4e4b\u540e\u5728\u53d6\u503c\u65f6\uff0cGcExcel\u4f1a\u81ea\u52a8\u8ba1\u7b97\u54cd\u5e94\u516c\u5f0f\u7684\u503c\u3002<\/p>\n<pre><code class=\"JavaScript\">private CalcResult CalcInternal(Workbook workbook, CalcParameter par) {\n        var result = new CalcResult();\n        var sheet = workbook.getWorksheets().get(par.calcType);\n        switch (par.calcType) {\n            case &quot;\u5de5\u8d44\u85aa\u91d1\u6240\u5f97&quot; -&gt; {\n                sheet.getRange(&quot;B1&quot;).setValue(par.income);\n                sheet.getRange(&quot;D1&quot;).setValue(par.insurance);\n                sheet.getRange(&quot;B2&quot;).setValue(par.childEdu);\n                sheet.getRange(&quot;D2&quot;).setValue(par.selfEdu);\n                sheet.getRange(&quot;B3&quot;).setValue(par.treatment);\n                sheet.getRange(&quot;D3&quot;).setValue(par.loans);\n                sheet.getRange(&quot;B4&quot;).setValue(par.rent);\n                sheet.getRange(&quot;D4&quot;).setValue(par.elder);\n                result.taxableIncome = (double) sheet.getRange(&quot;B9&quot;).getValue();\n                result.taxRate = (double) sheet.getRange(&quot;D9&quot;).getValue();\n                result.deduction = (double) sheet.getRange(&quot;B10&quot;).getValue();\n                result.tax = (double) sheet.getRange(&quot;D10&quot;).getValue();\n                result.takeHomeSalary = (double) sheet.getRange(&quot;B11&quot;).getValue();\n            }\n            case &quot;\u5e74\u7ec8\u5956\u6240\u5f97&quot; -&gt; {\n                sheet.getRange(&quot;B1&quot;).setValue(par.income);\n                result.taxableIncome = (double) sheet.getRange(&quot;B3&quot;).getValue();\n                result.taxRate = (double) sheet.getRange(&quot;D3&quot;).getValue();\n                result.deduction = (double) sheet.getRange(&quot;B4&quot;).getValue();\n                result.monthlyWage = (double) sheet.getRange(&quot;D4&quot;).getValue();\n                result.tax = (double) sheet.getRange(&quot;B5&quot;).getValue();\n                result.takeHomeSalary = (double) sheet.getRange(&quot;D5&quot;).getValue();\n            }\n            case &quot;\u52b3\u52a1\u62a5\u916c\u6240\u5f97&quot; -&gt; {\n                sheet.getRange(&quot;B1&quot;).setValue(par.income);\n                result.taxableIncome = (double) sheet.getRange(&quot;B3&quot;).getValue();\n                result.taxRate = (double) sheet.getRange(&quot;D3&quot;).getValue();\n                result.deduction = (double) sheet.getRange(&quot;B4&quot;).getValue();\n                result.nonTaxablePart = (double) sheet.getRange(&quot;D4&quot;).getValue();\n                result.tax = (double) sheet.getRange(&quot;B5&quot;).getValue();\n                result.takeHomeSalary = (double) sheet.getRange(&quot;D5&quot;).getValue();\n            }\n            case &quot;\u4e2a\u4f53\u5de5\u5546\u6237\u3001\u751f\u4ea7\u7ecf\u8425\u6240\u5f97&quot; -&gt; {\n                sheet.getRange(&quot;B1&quot;).setValue(par.income);\n                result.taxableIncome = (double) sheet.getRange(&quot;B3&quot;).getValue();\n                result.taxRate = (double) sheet.getRange(&quot;D3&quot;).getValue();\n                result.deduction = (double) sheet.getRange(&quot;B4&quot;).getValue();\n                result.tax = (double) sheet.getRange(&quot;D4&quot;).getValue();\n                result.takeHomeSalary = (double) sheet.getRange(&quot;B5&quot;).getValue();\n            }\n            default -&gt; {\n                sheet.getRange(&quot;B1&quot;).setValue(par.income);\n                result.taxableIncome = (double) sheet.getRange(&quot;B3&quot;).getValue();\n                result.taxRate = (double) sheet.getRange(&quot;D3&quot;).getValue();\n                result.tax = (double) sheet.getRange(&quot;B4&quot;).getValue();\n                result.takeHomeSalary = (double) sheet.getRange(&quot;D4&quot;).getValue();\n            }\n        }\n        return result;\n    }<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86\u670d\u52a1\u7aef\u7684\u4ee3\u7801\u3002<\/p>\n<p><strong>\u6700\u7ec8\u6548\u679c<\/strong><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5de5\u8d44\u85aa\u91d1\u6240\u5f97\u8bd5\u9a8c\u4e00\u4e0b\uff0c\u53ef\u4ee5\u770b\u5230\u6570\u636e\u88ab\u8ba1\u7b97\u51fa\u6765\u4e86\u3002\u56e0\u4e3a\u76ee\u7684\u662f\u4e3a\u4e86\u5206\u4eab\u670d\u52a1\u7aef\u516c\u5f0f\u8ba1\u7b97\u7684\u65b9\u6848\uff0c\u6240\u4ee5\u8ba1\u7b97\u7684\u7ed3\u679c\u662f\u5426\u6b63\u786e\uff0c\u5c31\u4e0d\u505a\u7ec6\u81f4\u8003\u8651\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000044185840\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n<p>\u4e2a\u7a0e\u8ba1\u7b97\u7684\u573a\u666f\u5e76\u4e0d\u590d\u6742\uff0c\u4e3b\u8981\u662f\u901a\u8fc7Excel\u5b8c\u6210\u516c\u5f0f\u8ba1\u7b97\u5373\u53ef\uff0c\u5728\u670d\u52a1\u7aef\u4f7f\u7528GcExcel\u53ef\u4ee5\u5927\u5e45\u5ea6\u964d\u4f4e\u524d\u540e\u7aef\u7684\u5f00\u53d1\u96be\u5ea6\uff0c\u7cfb\u7edf\u7684\u642d\u5efa\u8fc7\u7a0b\u53ef\u4ee5\u5b8c\u5168\u4e0d\u9700\u8981\u8003\u8651\u8ba1\u7b97\u7684\u903b\u8f91\u3002<\/p>\n<p>\u5728\u5b9e\u9645\u7684\u516c\u5f0f\u8ba1\u7b97\u573a\u666f\u4e2d\uff0c\u53ef\u80fd\u5f80\u5f80\u4f1a\u6bd4\u4e2a\u7a0e\u8ba1\u7b97\u7684\u573a\u666f\u590d\u6742\uff0c\u501f\u52a9GcExcel\u8fd9\u6837Excel\u7ec4\u4ef6\u5e93\uff0c\u53ef\u4ee5\u5f88\u5bb9\u6613\u7684\u628a\u5df2\u6709\u7684Excel\u6587\u4ef6\u8fc1\u79fb\u5230\u7ebf\u4e0a\uff0c\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u672c\u6587\u4e2d\u5206\u4eab\u7684\u4ee3\u7801\u5e76\u4e0d\u662f\u6700\u7b26\u5408\u5b9e\u9645\u5de5\u4f5c\u4e2d\u7684\u8981\u6c42\uff0c\u8bfb\u8005\u8fd8\u53ef\u4ee5\u4ece\u4ee5\u4e0b\u89d2\u5ea6\u53bb\u4f18\u5316\u81ea\u5df1\u7684\u4ee3\u7801\u3002<\/p>\n<ol>\n<li>\u6536\u5165\u7c7b\u578b\u53ef\u4ee5\u62bd\u6210\u679a\u4e3e\uff0c\u8fd9\u6837\u7ef4\u62a4\u548c\u4f7f\u7528\u8d77\u6765\u66f4\u5bb9\u6613\u3002<\/li>\n<li>\u76ee\u524d\u6bcf\u4e00\u4e2areact\u7ec4\u4ef6\u91cc\u7684\u5197\u4f59\u5ea6\u8fd8\u4e0d\u4f4e\uff0c\u8fd8\u53ef\u4ee5\u7ee7\u7eed\u62bd\u8c61\u7ec4\u4ef6\uff0c\u907f\u514d\u91cd\u590d\u5199\u4ee3\u7801\u3002<\/li>\n<li>\u5728\u670d\u52a1\u7aef\uff0c\u56e0\u4e3a\u516c\u5f0f\u8ba1\u7b97\u7684\u903b\u8f91\u662f\u4e0d\u4f1a\u53d8\u7684\uff0c\u5728\u5b9e\u9645\u573a\u666f\u4e2d\uff0c\u4e5f\u6709\u53ef\u80fd\u540c\u4e00\u65f6\u95f4\u8981\u52a0\u8f7d\u590d\u6570\u4e2aExcel\u6587\u4ef6\uff0c\u53ef\u4ee5\u8003\u8651\u628aworkbook\u5e38\u9a7b\u5185\u5b58\uff0c\u6765\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ol>\n<p><\/p>\n<p><strong>\u6269\u5c55\u94fe\u63a5\uff1a<\/strong><\/p>\n<p><a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=v%2BYpnLWZdvO2XkUoUYQTPw%3D%3D.tGqfx3OVtH58VP8U0TGAeX%2B%2FfD7rOQJRjqCNMiiquwa7selHQy4nPpChzlZqL16x%2FJLN5QIsFW2g3QEsM2uK8A%3D%3D\" rel=\"noopener noreferrer\"><strong>\u9ad8\u7ea7SQL\u5206\u6790\u51fd\u6570-\u5982\u4f55\u7528\u7a97\u53e3\u51fd\u6570\u8fdb\u884c\u6392\u540d\u8ba1\u7b97<\/strong><\/a><\/p>\n<p><a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=0%2BqBcYCt9dAdWJiOVW%2BOVg%3D%3D.EfeF0x2uZ4TGGm815oLCNhri2vO2cFJZjhRN6yzkM1z%2F1dqHuxhVGja6u7isSyq6GulJDEeJRQQvlRgJBgzVCSLfMw56e2ijmbRcM9t74GXs0NK6UezsRcpqndVDHr9x\" rel=\"noopener noreferrer\"><strong>3D\u6a21\u578b+BI\u5206\u6790\uff0c\u6253\u9020\u5168\u65b0\u7684\u4ea4\u4e92\u5f0f3D\u53ef\u89c6\u5316\u5927\u5c4f\u5f00\u53d1\u65b9\u6848<\/strong><\/a><\/p>\n<p><a target=\"_blank\" href=\"https:\/\/link.segmentfault.com\/?enc=RH1lmUjAxjQavy7sTmH5ZA%3D%3D.k8yLCyBjtH92%2Bq3A0v4eI95WS4ridoPRmJxtXwSnXRNs5YtFaaxRbqsKcd14Jis725077HtlzEkRj9AIzexmlV7HJxrl9F0PHe9HYmovZlun%2BXrM%2FmgMJjNHzaWykCQG\" rel=\"noopener noreferrer\"><strong>React + Springboot + Quartz\uff0c\u4ece0\u5b9e\u73b0Excel\u62a5\u8868\u81ea\u52a8\u5316<\/strong><\/a><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000044185834\">https:\/\/segmentfault.com\/a\/1190000044185834<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u5728\u62a5\u8868\u6570\u636e\u5904\u7406\u4e2d\uff0cExcel\u516c\u5f0f\u62e5\u6709\u5f3a\u5927\u800c\u591a\u6837\u7684\u529f\u80fd\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u4e2a\u4e1a\u52a1\u9886\u57df\u3002\u65e0\u8bba\u662f\u6295\u8d44\u6536\u76ca\u8ba1\u7b97\u3001\u8d22\u52a1\u62a5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008233","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008233"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008233\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}