{"id":238,"date":"2020-08-10T22:35:04","date_gmt":"2020-08-10T14:35:04","guid":{"rendered":"http:\/\/moyisuiying.com\/?p=238"},"modified":"2020-12-10T14:24:00","modified_gmt":"2020-12-10T06:24:00","slug":"spring%e4%bd%bf%e7%94%a8%e7%ba%af%e6%b3%a8%e8%a7%a3%e9%85%8d%e7%bd%ae%e4%ba%8b%e5%8a%a1%e7%ae%a1%e7%90%86%e5%b9%b6%e5%ae%9e%e7%8e%b0%e7%ae%80%e5%8d%95%e7%9a%84%e5%a2%9e%e5%88%a0%e6%9f%a5%e6%94%b9","status":"publish","type":"post","link":"http:\/\/moyisuiying.com\/index.php\/javastudy\/238.html","title":{"rendered":"Spring\u4f7f\u7528\u7eaf\u6ce8\u89e3\u914d\u7f6e\u4e8b\u52a1\u7ba1\u7406\u5e76\u5b9e\u73b0\u7b80\u5355\u7684\u589e\u5220\u67e5\u6539\u4ee5\u53ca\u6a21\u62df\u8f6c\u8d26\u529f\u80fd"},"content":{"rendered":"\n<p>\u5728\u4e4b\u524d\u7684\u6587\u7ae0\uff0c\u7b14\u8005\u5df2\u7ecf\u4f7f\u7528XML\u914d\u7f6e\u5b9e\u73b0\u4e86\u5bf9MySQL\u7684\u4e8b\u52a1\u7ba1\u7406<a href=\"http:\/\/moyisuiying.com\/index.php\/javastudy\/233.html\">\u4f7f\u7528Spring\u7684\u4e8b\u52a1\u7ba1\u7406\u5668\u914d\u7f6e\u6570\u636e\u5e93\u7684\u4e8b\u52a1<\/a>\uff0cSpring\u4e5f\u652f\u6301\u4f7f\u7528\u6ce8\u89e3\u8fdb\u884c\u914d\u7f6e\u4ece\u800c\u5b9e\u73b0\u5bf9\u4e8b\u52a1\u7684\u7ba1\u7406\uff0c\u6b64\u6b21\u4fbf\u8be6\u7ec6\u8bf4\u660e\u5982\u4f55\u4f7f\u7528\u6ce8\u89e3\u914d\u7f6e\u5b9e\u73b0Spring\u4e8b\u52a1\u7684\u7ba1\u7406\u3002<br>1.\u9996\u5148\u5efa\u7acb\u5b9e\u9a8c\u6d4b\u8bd5\u73af\u5883<br>1.1\u521b\u5efa\u6570\u636e\u5e93\u4ee5\u53ca\u6570\u636e\u8868Account\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>create database if not exists springdemo;\nuse springdemo;\ncreate table if not exists Account(id int(4) auto_increment primary key,name varchar(16) not null,password varchar(16) not null,age int(3) ,createtime datetime default now(),money int(8));<\/code><\/pre>\n\n\n\n<p>1.2\u5728idea\u4e2d\u5efa\u7acbmaven\u5de5\u7a0b\u3002<br><img   class=\"lazyload\" data-src=\"https:\/\/img-blog.csdnimg.cn\/20200810214834191.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>1.3\u5728pom.xml\u4e2d\u5f15\u5165\u5fc5\u987b\u7684\u4f9d\u8d56\u6587\u4ef6<\/p >\n<noscript><img src=\"https:\/\/img-blog.csdnimg.cn\/20200810214834191.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><br>1.3\u5728pom.xml\u4e2d\u5f15\u5165\u5fc5\u987b\u7684\u4f9d\u8d56\u6587\u4ef6<\/p><\/noscript>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\"\n         xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n         xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\">\n    &lt;modelVersion>4.0.0&lt;\/modelVersion>\n    &lt;groupId>org.example&lt;\/groupId>\n    &lt;artifactId>springdemo_tx_annotaiton&lt;\/artifactId>\n    &lt;version>1.0-SNAPSHOT&lt;\/version>\n    &lt;properties>\n        &lt;project.build.sourceEncoding>UTF-8&lt;\/project.build.sourceEncoding>\n        &lt;maven.compiler.source>1.8&lt;\/maven.compiler.source>\n        &lt;maven.compiler.target>1.8&lt;\/maven.compiler.target>\n        &lt;spring.version>5.2.8.RELEASE&lt;\/spring.version>\n    &lt;\/properties>\n    &lt;dependencies>\n&lt;!--        \u5f15\u5165Spring\u4f9d\u8d56-->\n        &lt;dependency>\n            &lt;groupId>org.springframework&lt;\/groupId>\n            &lt;artifactId>spring-context&lt;\/artifactId>\n            &lt;version>${spring.version}&lt;\/version>\n        &lt;\/dependency>\n        &lt;dependency>\n            &lt;groupId>org.springframework&lt;\/groupId>\n            &lt;artifactId>spring-jdbc&lt;\/artifactId>\n            &lt;version>${spring.version}&lt;\/version>\n        &lt;\/dependency>\n        &lt;dependency>\n            &lt;groupId>org.springframework&lt;\/groupId>\n            &lt;artifactId>spring-tx&lt;\/artifactId>\n            &lt;version>${spring.version}&lt;\/version>\n        &lt;\/dependency>\n        &lt;!-- \u5f15\u5165MySQL\u4f9d\u8d56 -->\n        &lt;dependency>\n            &lt;groupId>mysql&lt;\/groupId>\n            &lt;artifactId>mysql-connector-java&lt;\/artifactId>\n            &lt;version>8.0.21&lt;\/version>\n        &lt;\/dependency>\n        &lt;!-- \u5f15\u5165c3p0\u4f9d\u8d56-->\n        &lt;dependency>\n            &lt;groupId>com.mchange&lt;\/groupId>\n            &lt;artifactId>c3p0&lt;\/artifactId>\n            &lt;version>0.9.5.5&lt;\/version>\n        &lt;\/dependency>\n&lt;!--        \u5f15\u5165\u6d4b\u8bd5\u4f9d\u8d56-->\n        &lt;dependency>\n            &lt;groupId>org.junit.jupiter&lt;\/groupId>\n            &lt;artifactId>junit-jupiter&lt;\/artifactId>\n            &lt;version>RELEASE&lt;\/version>\n            &lt;scope>test&lt;\/scope>\n        &lt;\/dependency>\n\n    &lt;\/dependencies>\n\n&lt;\/project><\/code><\/pre>\n\n\n\n<p>1.4\u521b\u5efa\u6570\u636e\u5e93\u8fde\u63a5\u914d\u7f6e\u6587\u4ef6db.properties<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>jdbc.url=jdbc:mysql:\/\/localhost:3306\/springdemo?serverTimezone=UTC\njdbc.name=root\njdbc.password=root\njdbc.driver=com.mysql.cj.jdbc.Driver<\/code><\/pre>\n\n\n\n<p>2.\u5f00\u59cb\u4e66\u5199dao,entity,service\u5305\u4e0b\u7684\u4ee3\u7801\u3002<br>2.1\u521b\u5efa\u5b9e\u4f53\u7c7b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package entity;\n\nimport org.springframework.context.annotation.Scope;\nimport org.springframework.stereotype.Repository;\n\nimport java.util.Date;\n\n\/**\n * Classname:Account\n *\n * @description:\n * @author: \u964c\u610f\u968f\u5f71\n * @Date: 2020-08-01 17:33\n * @Version: 1.0\n **\/\n@Repository(\"account\")\n@Scope(\"prototype\")\npublic class Account {\n    \/\/\u7528\u6237\u4e3b\u952eID\n    private int id;\n    \/\/\u7528\u6237\u540d\n    private String name;\n    \/\/\u7528\u6237\u5bc6\u7801\n    private String password;\n    \/\/\u7528\u6237\u5e74\u9f84\n    private int age;\n    \/\/\u7528\u6237\u521b\u5efa\u65f6\u95f4\n    private Date createTime ;\n    \/\/\u7528\u6237\u7684\u4f59\u989d\n    private int money;\n\n    public int getMoney() {\n        return money;\n    }\n\n    public void setMoney(int money) {\n        this.money = money;\n    }\n\n    public int getId() {\n        return id;\n    }\n\n    public void setId(int id) {\n        this.id = id;\n    }\n\n    public String getName() {\n        return name;\n    }\n\n    public void setName(String name) {\n        this.name = name;\n    }\n\n    public String getPassword() {\n        return password;\n    }\n\n    public void setPassword(String password) {\n        this.password = password;\n    }\n\n    public int getAge() {\n        return age;\n    }\n\n    public void setAge(int age) {\n        this.age = age;\n    }\n\n    public Date getCreateTime() {\n        return createTime;\n    }\n\n    public void setCreateTime(Date createTime) {\n        this.createTime = createTime;\n    }\n\n    @Override\n    public String toString() {\n        return \"Account{\" +\n                \"id=\" + id +\n                \", name='\" + name + '\\'' +\n                \", password='\" + password + '\\'' +\n                \", age=\" + age +\n                \", createTime=\" + createTime +\n                \", monney=\" + money +\n                '}';\n    }\n}<\/code><\/pre>\n\n\n\n<p>2.2\u521b\u5efa\u7528\u548c\u8bbf\u95ee\u6570\u636e\u5e93\u7684\u6301\u4e45\u5c42\u63a5\u53e3\u4ee5\u53ca\u5176\u5b9e\u73b0\u7c7b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package dao;\n\nimport entity.Account;\n\nimport java.util.List;\n\n\/**\n * Classname:springdemo3\n *\n * @description:{description}\n * @author: \u964c\u610f\u968f\u5f71\n * @Date: 2020-08-01 17:32\n *\/\npublic interface AccountDao {\n    \/**\n     * @Description :\u4fdd\u5b58\u7528\u6237\n     * @Date 11:51 2020\/8\/9 0009\n     * @Param * @param account \uff1a\n     * @return boolean\n     **\/\n    public boolean saveAccount(Account account);\n    \/**\n     * @Description :\u66f4\u65b0\u7528\u6237\n     * @Date 11:51 2020\/8\/9 0009\n     * @Param * @param newAccount \uff1a\n     * @return boolean\n     **\/\n    public boolean updateAccount(Account newAccount);\n    \/**\n     * @Description :\u901a\u8fc7ID\u5220\u9664\u7528\u6237\n     * @Date 11:52 2020\/8\/9 0009\n     * @Param * @param id \uff1a\n     * @return boolean\n     **\/\n    public boolean deleteAccountById(int id);\n    \/**\n     * @Description :\u901a\u8fc7ID\u67e5\u8be2\u7528\u6237\n     * @Date 11:52 2020\/8\/9 0009\n     * @Param * @param id \uff1a\n     * @return entity.Account\n     **\/\n    public Account findAccountById(int id);\n    \/**\n     * @Description :\u67e5\u627e\u6240\u6709\u7528\u6237\n     * @Date 11:52 2020\/8\/9 0009\n     * @Param * @param  \uff1a\n     * @return java.util.List&lt;entity.Account>\n     **\/\n    public List&lt;Account> findAll();\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package dao;\n\nimport entity.Account;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.jdbc.core.BeanPropertyRowMapper;\nimport org.springframework.jdbc.core.JdbcTemplate;\nimport org.springframework.stereotype.Repository;\n\nimport java.util.List;\n\n\/**\n * Classname:AccountDaoImpl\n *\n * @description:AccountDao\u7684\u5b9e\u73b0\u7c7b\n * @author: \u964c\u610f\u968f\u5f71\n * @Date: 2020-08-01 17:32\n * @Version: 1.0\n **\/\n@Repository(\"accountDao\")\npublic class AccountDaoImpl implements AccountDao {\n    \/\/\u7528\u4e8e\u8fdb\u884cMySQL\u589e\u5220\u67e5\u6539,\u81ea\u52a8\u6ce8\u5165\n    @Autowired\n    JdbcTemplate jdbcTemplate = null;\n   \/**\n    * @Description :\u4fdd\u5b58\u7528\u6237\n    * @Date 12:17 2020\/8\/9 0009\n    * @Param * @param newAccount \uff1a\n    * @return boolean\n    **\/\n    public boolean saveAccount(Account newAccount) {\n            return jdbcTemplate.update(\"insert into account(name,password,age,createTIme,money) values(?,?,?,?,?)\",\n                    newAccount.getName(),newAccount.getPassword(),\n                    newAccount.getAge(),newAccount.getCreateTime(),newAccount.getMoney())== 1;\n    }\n  \/**\n   * @Description :\u66f4\u65b0\u7528\u6237\n   * @Date 12:18 2020\/8\/9 0009\n   * @Param * @param newAccount \uff1a\n   * @return boolean\n   **\/\n    public boolean updateAccount(Account newAccount) {\n            return jdbcTemplate.update(\"update account set name=?,password=?,age=?,createTime=?,money=? where id=?\",\n                    newAccount.getName(),newAccount.getPassword(),\n                    newAccount.getAge(),newAccount.getCreateTime(),newAccount.getMoney(),newAccount.getId())==1;\n    }\n  \/**\n   * @Description :\u901a\u8fc7ID\u5220\u9664\u7528\u6237\n   * @Date 12:18 2020\/8\/9 0009\n   * @Param * @param id \uff1a\n   * @return boolean\n   **\/\n    public boolean deleteAccountById(int id) {\n            return jdbcTemplate.update(\"delete from account where id=?\",id) == 1;\n    }\n\/**\n * @Description :\u901a\u8fc7ID\u67e5\u8be2\u7528\u6237\n * @Date 11:02 2020\/8\/9 0009\n * @Param * @param id \uff1a\n * @return entity.Account\n **\/\n    public Account findAccountById(int id) {\n            List&lt;Account> list = jdbcTemplate.query(\"select* from account where id=?\", new BeanPropertyRowMapper&lt;Account>(Account.class), id);\n            if (list.isEmpty()){\n                return  null;\n            }\n            if (list.size()==1){\n                return list.get(0);\n            }\n            return  null;\n\n    }\n\/**\n * @Description :\u67e5\u8be2\u6240\u6709\u54df\u7528\u6237\n * @Date 11:01 2020\/8\/9 0009\n * @Param * @param  \uff1a\n * @return java.util.List&lt;entity.Account>\n **\/\n    public List&lt;Account> findAll() {\n            return jdbcTemplate.query(\"select* from account\",new BeanPropertyRowMapper&lt;Account>(Account.class));\n    }\n\n}<\/code><\/pre>\n\n\n\n<p>\u7528\u4e8e\u8bbf\u95ee\u6570\u636e\u5e93\u7684JdbcTemplate\u9700\u8981\u81ea\u52a8\u6ce8\u5165\uff0c\u7b49\u4f1a\u518d\u5728\u914d\u7f6e\u7c7b\u4e2d\u914d\u7f6e\u8fd9\u4e2aJdbcTemplate\u7528\u4e8e\u6ce8\u5165\u3002<br>2.3\u4e66\u5199\u4e1a\u52a1\u903b\u8f91\u63a5\u53e3\u4ee5\u53ca\u5176\u5b9e\u73b0\u7c7b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package service;\n\nimport entity.Account;\n\nimport java.util.List;\n\n\/**\n * Classname:springdemo3\n *\n * @description:{description}\n * @author: \u964c\u610f\u968f\u5f71\n * @Date: 2020-08-01 17:35\n *\/\npublic interface AccountService {\n        \/**\n         * @Description :\u4fdd\u5b58\u7528\u6237\n         * @Date 11:51 2020\/8\/9 0009\n         * @Param * @param account \uff1a\n         * @return boolean\n         **\/\n        public boolean saveAccount(Account account);\n        \/**\n         * @Description :\u66f4\u65b0\u7528\u6237\n         * @Date 11:51 2020\/8\/9 0009\n         * @Param * @param newAccount \uff1a\n         * @return boolean\n         **\/\n        public boolean updateAccount(Account newAccount);\n        \/**\n         * @Description :\u901a\u8fc7ID\u5220\u9664\u7528\u6237\n         * @Date 11:52 2020\/8\/9 0009\n         * @Param * @param id \uff1a\n         * @return boolean\n         **\/\n        public boolean deleteAccountById(int id);\n        \/**\n         * @Description :\u901a\u8fc7ID\u67e5\u8be2\u7528\u6237\n         * @Date 11:52 2020\/8\/9 0009\n         * @Param * @param id \uff1a\n         * @return entity.Account\n         **\/\n        public Account findAccountById(int id);\n        \/**\n         * @Description :\u67e5\u627e\u6240\u6709\u7528\u6237\n         * @Date 11:52 2020\/8\/9 0009\n         * @Param * @param  \uff1a\n         * @return java.util.List&lt;entity.Account>\n         **\/\n        public List&lt;Account> findAll();\n   \/**\n    * @Description :\u4ece\u7528\u6237ID\u4e3asourceId\u7684\u7528\u6237\u5411\u7528\u6237ID\u4e3atargetId\u7684\u7528\u6237\u8f6c\u8d26money\n    * @Date 11:55 2020\/8\/9 0009\n    * @Param * @param sourceId\n    * @param targetId\n    * @param money \uff1a\n    * @return boolean\n    **\/\n    public boolean tranferMoney(int sourceId,int targetId,int money);\n}<\/code><\/pre>\n\n\n\n<p>java<br>package service;<br>import dao.AccountDao;<br>import entity.Account;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.stereotype.Service;<br>import org.springframework.transaction.annotation.Isolation;<br>import org.springframework.transaction.annotation.Propagation;<br>import org.springframework.transaction.annotation.Transactional;<\/p>\n\n\n\n<p>import java.util.List;<br>\/**<\/p>\n\n\n\n<ul><li>Classname:AccountServiceImpl<\/li><li>@description:<\/li><li>@author: \u964c\u610f\u968f\u5f71<\/li><li>@Date: 2020-08-01 17:35<\/li><li>@Version: 1.0<br>**\/<br>@Service(\"accountService\")<br>@Transactional(propagation= Propagation.SUPPORTS,readOnly=true)<br>public class AccountServiceImpl implements AccountService {<br>\/\/\u7528\u6237\u6570\u636e\u53ef\u8bbf\u95ee\u7684Dao\u63a5\u53e3<br>@Autowired<br>private AccountDao accountDao;<br>@Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,readOnly = false)<br>public boolean saveAccount(Account account) {<br>return accountDao.saveAccount(account);<br>}<br>@Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,readOnly = false)<br>public boolean updateAccount(Account newAccount) { <code>return accountDao.updateAccount(newAccount);<\/code> }<br>@Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,readOnly = false)<br>public boolean deleteAccountById(int id) {<br>return accountDao.deleteAccountById(id);<br>}<br>@Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,readOnly = true)<br>public Account findAccountById(int id) {<br>return accountDao.findAccountById(id);<br>}<br>@Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,readOnly = true)<br>public List findAll() {<br>return accountDao.findAll();<br>}<br>\/**<ul><li>@Description :\u4ece\u7528\u6237ID\u4e3asourceId\u7684\u7528\u6237\u5411\u7528\u6237ID\u4e3atargetId\u7684\u7528\u6237\u8f6c\u8d26money<\/li><li>@Date 11:55 2020\/8\/9 0009<\/li><li>@Param * @param sourceId<\/li><li>@param targetId<\/li><li>@param money \uff1a<\/li><li>@return boolean<br>**\/<br>@Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,readOnly = false)<br>public boolean tranferMoney(int sourceId, int targetId, int money) {<br>\/\/\u83b7\u53d6sourceId\u5bf9\u5e94\u7684\u7528\u6237<br>Account sourceAccount = this.findAccountById(sourceId);<br>\/\/\u83b7\u53d6targetId\u5bf9\u5e94\u7684\u7528\u6237<br>Account targetAccount = this.findAccountById(targetId);<br>\/\/\u8f6c\u8d26\u5931\u8d25<br>if (sourceAccount == null || targetAccount == null) {<br>return false;<br>}<br>\/\/\u8f6c\u8d26\u8005\u6263\u53bb\u8f6c\u8d26\u7684\u91d1\u989d<br>sourceAccount.setMoney(sourceAccount.getMoney() -money);<br>\/\/\u76ee\u6807\u5bf9\u8c61\u52a0\u4e0a\u83b7\u53d6\u7684\u8f6c\u8d26\u91d1\u989d<br>targetAccount.setMoney(targetAccount.getMoney()+money);<br>\/\/\u66f4\u65b0\u8f6c\u8d26\u8005\u7684\u8d26\u6237<br>boolean b = this.updateAccount(sourceAccount);<br>\/\/\u6a21\u62df\u5f02\u5e38<br>int i = 1\/0;<br>\/\/\u66f4\u65b0\u8f6c\u8d26\u76ee\u6807\u8005\u7684\u8d26\u6237<br>boolean b1 = this.updateAccount(targetAccount);<br>return b == true &amp;&amp; b1 == true;<\/li><\/ul>}<br>}<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>AccountDao\u4f1a\u81ea\u52a8\u88ab\u6ce8\u5165\uff0c\u6211\u4eec\u8981\u5b9e\u73b0\u4e8b\u52a1\u7ba1\u7406\u5c31\u662f\u8981\u5728\u4e1a\u52a1\u903b\u8f91\u4e2d\u8fdb\u884c\u4e8b\u52a1\u7ba1\u7406\uff0c\u56e0\u6b64\u9700\u8981\u5728AccountServiceImpl\u4e2d\u6dfb\u52a0@Transactional\u6ce8\u89e3\u3002\n\n**3.@Transactional \u57fa\u4e8e Spring \u7684\u52a8\u6001\u4ee3\u7406\u7684\u673a\u5236**\n\n3.1@Transactional \u5b9e\u73b0\u539f\u7406\uff1a\n\uff081\uff09\u4e8b\u52a1\u5f00\u59cb\u65f6\uff0c\u901a\u8fc7AOP\u673a\u5236\uff0c\u751f\u6210\u4e00\u4e2a\u4ee3\u7406connection\u5bf9\u8c61\uff0c\n   \u5e76\u5c06\u5176\u653e\u5165 DataSource \u5b9e\u4f8b\u7684\u67d0\u4e2a\u4e0e DataSourceTransactionManager \u76f8\u5173\u7684\u67d0\u5904\u5bb9\u5668\u4e2d\u3002   \u5728\u63a5\u4e0b\u6765\u7684\u6574\u4e2a\u4e8b\u52a1\u4e2d\uff0c\u5ba2\u6237\u4ee3\u7801\u90fd\u5e94\u8be5\u4f7f\u7528\u8be5 connection \u8fde\u63a5\u6570\u636e\u5e93\uff0c \u6267\u884c\u6240\u6709\u6570\u636e\u5e93\u547d\u4ee4\u3002  \u5982\u679c\u4e0d\u4f7f\u7528\u8be5 connection \u8fde\u63a5\u6570\u636e\u5e93\u6267\u884c\u7684\u6570\u636e\u5e93\u547d\u4ee4\uff0c\u90a3\u4e48\u5728\u672c\u4e8b\u52a1\u56de\u6eda\u7684\u65f6\u5019\u5f97\u4e0d\u5230\u56de\u6eda\uff0c\u4ece\u800c\u65e0\u6cd5\u5b9e\u73b0\u4e8b\u52a1\u7684\u7ba1\u7406\u3002\u7269\u63a5 connection \u903b\u8f91\u4e0a\u65b0\u5efa\u4e00\u4e2a\u4f1a\u8bddsession\uff0cDataSource \u4e0e TransactionManager \u914d\u7f6e\u76f8\u540c\u7684\u6570\u636e\u6e90.\n\uff082\uff09 \u4e8b\u52a1\u7ed3\u675f\u65f6\uff0c\u56de\u6eda\u5728\u7b2c1\u6b65\u9aa4\u4e2d\u5f97\u5230\u7684\u4ee3\u7406 connection \u5bf9\u8c61\u4e0a\u6267\u884c\u7684\u6570\u636e\u5e93\u547d\u4ee4\uff0c \u7136\u540e\u5173\u95ed\u8be5\u4ee3\u7406 connection \u5bf9\u8c61\u3002\u4e8b\u52a1\u7ed3\u675f\u540e\uff0c\u56de\u6eda\u64cd\u4f5c\u4e0d\u4f1a\u5bf9\u5df2\u6267\u884c\u5b8c\u6bd5\u7684SQL\u64cd\u4f5c\u547d\u4ee4\u8d77\u4f5c\u7528.\n3.2\u4e8b\u52a1\u7684\u4e24\u79cd\u5f00\u542f\u65b9\u5f0f\uff1a\n      (1)\u663e\u793a\u5f00\u542f start transaction | begin\uff0c\u901a\u8fc7 commit | rollback \u7ed3\u675f\u4e8b\u52a1         (2)\u5173\u95ed\u6570\u636e\u5e93\u4e2d\u81ea\u52a8\u63d0\u4ea4 autocommit set autocommit = 0,   MySQL \u9ed8\u8ba4\u5f00\u542f\u81ea\u52a8\u63d0\u4ea4\uff1b\u901a\u8fc7\u624b\u52a8\u63d0\u4ea4\u6216\u6267\u884c\u56de\u6eda\u64cd\u4f5c\u6765\u7ed3\u675f\u4e8b\u52a1.\n\n3.3\u4e8b\u52a1\u7684\u9694\u79bb\u7ea7\u522b\uff1a\u662f\u6307\u82e5\u5e72\u4e2a\u5e76\u53d1\u7684\u4e8b\u52a1\u4e4b\u95f4\u7684\u9694\u79bb\u7a0b\u5ea6      \n3.3.1. @Transactional(isolation = Isolation.READ_UNCOMMITTED)\uff1a\u8bfb\u53d6\u672a\u63d0\u4ea4\u6570\u636e(\u4f1a\u51fa\u73b0\u810f\u8bfb, \u4e0d\u53ef\u91cd\u590d\u8bfb) \u57fa\u672c\u4e0d\u4f7f\u7528.\n3.3.2. @Transactional(isolation = Isolation.READ_COMMITTED)\uff1a\u8bfb\u53d6\u5df2\u63d0\u4ea4\u6570\u636e(\u4f1a\u51fa\u73b0\u4e0d\u53ef\u91cd\u590d\u8bfb\u548c\u5e7b\u8bfb). \n3.3.3. @Transactional(isolation = Isolation.REPEATABLE_READ)\uff1a\u53ef\u91cd\u590d\u8bfb(\u4f1a\u51fa\u73b0\u5e7b\u8bfb).\n3.3.4. @Transactional(isolation = Isolation.SERIALIZABLE)\uff1a\u4e32\u884c\u5316.\n3.4\u4e8b\u52a1\u4f20\u64ad\u884c\u4e3a\uff1a\u5982\u679c\u5728\u5f00\u59cb\u5f53\u524d\u4e8b\u52a1\u4e4b\u524d\uff0c\u4e00\u4e2a\u4e8b\u52a1\u4e0a\u4e0b\u6587\u5df2\u7ecf\u5b58\u5728\uff0c\u6b64\u65f6\u6709\u82e5\u5e72\u9009\u9879\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2a\u4e8b\u52a1\u6027\u65b9\u6cd5\u7684\u6267\u884c\u884c\u4e3a.\n3.4.1. TransactionDefinition.PROPAGATION_REQUIRED\uff1a\n   \u5982\u679c\u5f53\u524d\u5b58\u5728\u4e8b\u52a1\uff0c\u5219\u52a0\u5165\u8be5\u4e8b\u52a1\uff1b\u5982\u679c\u5f53\u524d\u6ca1\u6709\u4e8b\u52a1\uff0c\u5219\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4e8b\u52a1\u3002\u8fd9\u662f\u9ed8\u8ba4\u503c\u3002\n\n3.4.2. TransactionDefinition.PROPAGATION_REQUIRES_NEW\uff1a\n   \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4e8b\u52a1\uff0c\u5982\u679c\u5f53\u524d\u5b58\u5728\u4e8b\u52a1\uff0c\u5219\u628a\u5f53\u524d\u4e8b\u52a1\u6302\u8d77\u3002\n\n3.4.3. TransactionDefinition.PROPAGATION_SUPPORTS\uff1a\n   \u5982\u679c\u5f53\u524d\u5b58\u5728\u4e8b\u52a1\uff0c\u5219\u52a0\u5165\u8be5\u4e8b\u52a1\uff1b\u5982\u679c\u5f53\u524d\u6ca1\u6709\u4e8b\u52a1\uff0c\u5219\u4ee5\u975e\u4e8b\u52a1\u7684\u65b9\u5f0f\u7ee7\u7eed\u8fd0\u884c\u3002\n\n3.4.4. TransactionDefinition.PROPAGATION_NOT_SUPPORTED\uff1a\n   \u4ee5\u975e\u4e8b\u52a1\u65b9\u5f0f\u8fd0\u884c\uff0c\u5982\u679c\u5f53\u524d\u5b58\u5728\u4e8b\u52a1\uff0c\u5219\u628a\u5f53\u524d\u4e8b\u52a1\u6302\u8d77\u3002\n\n3.4.5. TransactionDefinition.PROPAGATION_NEVER\uff1a\n   \u4ee5\u975e\u4e8b\u52a1\u65b9\u5f0f\u8fd0\u884c\uff0c\u5982\u679c\u5f53\u524d\u5b58\u5728\u4e8b\u52a1\uff0c\u5219\u629b\u51fa\u5f02\u5e38\u3002\n\n3.4.6. TransactionDefinition.PROPAGATION_MANDATORY\uff1a\n   \u5982\u679c\u5f53\u524d\u5b58\u5728\u4e8b\u52a1\uff0c\u5219\u52a0\u5165\u8be5\u4e8b\u52a1\uff1b\u5982\u679c\u5f53\u524d\u6ca1\u6709\u4e8b\u52a1\uff0c\u5219\u629b\u51fa\u5f02\u5e38\u3002\n\n3.4.7. TransactionDefinition.PROPAGATION_NESTED\uff1a\n   \u5982\u679c\u5f53\u524d\u5b58\u5728\u4e8b\u52a1\uff0c\u5219\u521b\u5efa\u4e00\u4e2a\u4e8b\u52a1\u4f5c\u4e3a\u5f53\u524d\u4e8b\u52a1\u7684\u5d4c\u5957\u4e8b\u52a1\u6765\u8fd0\u884c\uff1b\n   \u5982\u679c\u5f53\u524d\u6ca1\u6709\u4e8b\u52a1\uff0c\u5219\u8be5\u53d6\u503c\u7b49\u4ef7\u4e8eTransactionDefinition.PROPAGATION_REQUIRED\u3002\n**3.5Transactional\u5c5e\u6027\u914d\u7f6e**\n!&#91;\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0](https:\/\/img-blog.csdnimg.cn\/20200810221245320.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70)\n3.5.1. value \uff1a\u4e3b\u8981\u7528\u6765\u6307\u5b9a\u4e0d\u540c\u7684\u4e8b\u52a1\u7ba1\u7406\u5668\uff1b\n   \u4e3b\u8981\u7528\u6765\u6ee1\u8db3\u5728\u540c\u4e00\u4e2a\u7cfb\u7edf\u4e2d\uff0c\u5b58\u5728\u4e0d\u540c\u7684\u4e8b\u52a1\u7ba1\u7406\u5668\u3002\n   \u6bd4\u5982\u5728Spring\u4e2d\uff0c\u58f0\u660e\u4e86\u4e24\u79cd\u4e8b\u52a1\u7ba1\u7406\u5668txManager1, txManager2.\u7136\u540e\uff0c\n   \u7528\u6237\u53ef\u4ee5\u6839\u636e\u8fd9\u4e2a\u53c2\u6570\u6765\u6839\u636e\u9700\u8981\u6307\u5b9a\u7279\u5b9a\u7684txManager.\n\n3.5.2. value \u9002\u7528\u573a\u666f\uff1a\u5728\u4e00\u4e2a\u7cfb\u7edf\u4e2d\uff0c\u9700\u8981\u8bbf\u95ee\u591a\u4e2a\u6570\u636e\u6e90\u6216\u8005\u591a\u4e2a\u6570\u636e\u5e93\uff0c\n   \u5219\u5fc5\u7136\u4f1a\u914d\u7f6e\u591a\u4e2a\u4e8b\u52a1\u7ba1\u7406\u5668\u7684\n\n3.5.3. REQUIRED_NEW\uff1a\u5185\u90e8\u7684\u4e8b\u52a1\u72ec\u7acb\u8fd0\u884c\uff0c\u5728\u5404\u81ea\u7684\u4f5c\u7528\u57df\u4e2d\uff0c\u53ef\u4ee5\u72ec\u7acb\u7684\u56de\u6eda\u6216\u8005\u63d0\u4ea4\uff1b\n   \u800c\u5916\u90e8\u7684\u4e8b\u52a1\u5c06\u4e0d\u53d7\u5185\u90e8\u4e8b\u52a1\u7684\u56de\u6eda\u72b6\u6001\u5f71\u54cd\u3002\n\n3.5.4. ESTED \u7684\u4e8b\u52a1\uff0c\u57fa\u4e8e\u5355\u4e00\u7684\u4e8b\u52a1\u6765\u7ba1\u7406\uff0c\u63d0\u4f9b\u4e86\u591a\u4e2a\u4fdd\u5b58\u70b9\u3002\n   \u8fd9\u79cd\u591a\u4e2a\u4fdd\u5b58\u70b9\u7684\u673a\u5236\u5141\u8bb8\u5185\u90e8\u4e8b\u52a1\u7684\u53d8\u66f4\u89e6\u53d1\u5916\u90e8\u4e8b\u52a1\u7684\u56de\u6eda\u3002\n   \u800c\u5916\u90e8\u4e8b\u52a1\u5728\u6df7\u6eda\u4e4b\u540e\uff0c\u4ecd\u80fd\u7ee7\u7eed\u8fdb\u884c\u4e8b\u52a1\u5904\u7406\uff0c\u5373\u4f7f\u90e8\u5206\u64cd\u4f5c\u5df2\u7ecf\u88ab\u6df7\u6eda\u3002 \n   \u7531\u4e8e\u8fd9\u4e2a\u8bbe\u7f6e\u57fa\u4e8e JDBC \u7684\u4fdd\u5b58\u70b9\uff0c\u6240\u4ee5\u53ea\u80fd\u5de5\u4f5c\u5728 JDB C\u7684\u673a\u5236\u3002\n\n3.5.5. rollbackFor\uff1a\u8ba9\u53d7\u68c0\u67e5\u5f02\u5e38\u56de\u6eda\uff1b\u5373\u8ba9\u672c\u6765\u4e0d\u5e94\u8be5\u56de\u6eda\u7684\u8fdb\u884c\u56de\u6eda\u64cd\u4f5c\u3002\n\n3.5.6. noRollbackFor\uff1a\u5ffd\u7565\u975e\u68c0\u67e5\u5f02\u5e38\uff1b\u5373\u8ba9\u672c\u6765\u5e94\u8be5\u56de\u6eda\u7684\u4e0d\u8fdb\u884c\u56de\u6eda\u64cd\u4f5c\u3002\n **4.\u4e66\u5199\u914d\u7f6e\u6587\u4ef6\u7c7b**\n !&#91;\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0](https:\/\/img-blog.csdnimg.cn\/20200810221725492.png)<\/code><\/pre>\n\n\n\n<p>java<br>package config;<\/p>\n\n\n\n<p>import org.springframework.context.annotation.*;<br>import org.springframework.transaction.annotation.EnableTransactionManagement;<\/p>\n\n\n\n<p>\/**<\/p>\n\n\n\n<ul><li>Classname:SpringConfig<br>*<\/li><li>@description:<\/li><li>@author: \u964c\u610f\u968f\u5f71<\/li><li>@Date: 2020-08-09 21:50<\/li><li>@Version: 1.0<br>**\/<\/li><\/ul>\n\n\n\n<p>@Configuration \/\/\u58f0\u660e\u662f\u914d\u7f6e\u6587\u4ef6\u7c7b<br>@ComponentScan({\"dao\",\"entity\",\"service\"})\/\/\u6307\u5b9a\u8981\u626b\u63cf\u7684\u5305<br>@EnableTransactionManagement \/\/\u5f00\u542f\u4e8b\u52a1\u7ba1\u7406<br>@PropertySource(\"classpath:db.properties\")\/\/\u5f15\u5165\u6570\u636e\u5e93\u914d\u7f6e\u7684\u8d44\u6e90\u6587\u4ef6<br>@Import({JdbcConfig.class,TransactionConfig.class}) \/\/\u5f15\u5165\u6307\u5b9a\u7684\u914d\u7f6e\u7c7b<br>public class SpringConfig {<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>java<br>package config;<\/p>\n\n\n\n<p>import com.mchange.v2.c3p0.ComboPooledDataSource;<br>import org.springframework.beans.factory.annotation.Value;<br>import org.springframework.context.annotation.Bean;<br>import org.springframework.jdbc.core.JdbcTemplate;<\/p>\n\n\n\n<p>import javax.sql.DataSource;<\/p>\n\n\n\n<p>\/**<\/p>\n\n\n\n<ul><li>Classname:JdbcConfig<br>*<\/li><li>@description:<\/li><li>@author: \u964c\u610f\u968f\u5f71<\/li><li>@Date: 2020-08-09 21:53<\/li><li>@Version: 1.0 <strong>\/ public class JdbcConfig { \/\/\u81ea\u52a8\u4ece\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6db.properties\u4e2d\u83b7\u53d6jdbc.driver\u5bf9\u5e94\u7684\u503c\u6765\u590d\u5236\u7ed9driver @Value(\"${jdbc.driver}\") private String driver; \/\/\u81ea\u52a8\u4ece\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6db.properties\u4e2d\u83b7\u53d6jdbc.name\u5bf9\u5e94\u7684\u503c\u6765\u590d\u5236\u7ed9userName @Value(\"${jdbc.name}\") private String userName; \/\/\u81ea\u52a8\u4ece\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6db.properties\u4e2d\u83b7\u53d6jdbc.password\u5bf9\u5e94\u7684\u503c\u6765\u590d\u5236\u7ed9password @Value(\"${jdbc.password}\") private String password; \/\/\u81ea\u52a8\u4ece\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6db.properties\u4e2d\u83b7\u53d6jdbc.url\u5bf9\u5e94\u7684\u503c\u6765\u590d\u5236\u7ed9url @Value(\"${jdbc.url}\") private String url; \/<\/strong><ul><li>@Description :\u4f7f\u7528Bean\u6ce8\u89e3\u5c06\u521b\u5efa\u7684DataSource\u5b58\u5165\u5230Spring\u5bb9\u5668\u4e2d\u65b9\u4fbf\u4f7f\u7528<\/li><li>@Date 22:22 2020\/8\/10 0010<\/li><li>@Param * @param \uff1a<\/li><li>@return javax.sql.DataSource<br><strong>\/ @Bean(name = \"dataSource\") public DataSource createDataSource(){ \/\/\u521b\u5efa\u4e00\u4e2ac3p0\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u6570\u636e\u6e90 ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource(); try { \/\/\u8bbe\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u9a71\u52a8 comboPooledDataSource.setDriverClass(driver); \/\/\u8bbe\u7f6e\u6570\u636e\u5e93\u7528\u6237\u540d comboPooledDataSource.setUser(userName); \/\/\u8bbe\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u5bc6\u7801 comboPooledDataSource.setPassword(password); \/\/\u8bbe\u7f6e\u6570\u636e\u5e93\u7684\u8fde\u63a5URL comboPooledDataSource.setJdbcUrl(url); return comboPooledDataSource; } catch (Exception e) { throw new RuntimeException(\"\u6570\u636e\u5e93\u914d\u7f6e\u51fa\u9519\uff01\"); } } \/<\/strong><\/li><li>@Description :\u4f7f\u7528Bean\u6ce8\u89e3\u5c06\u521b\u5efa\u7684JdbcTemplate\u5b58\u5165\u5230Spring\u5bb9\u5668\u4e2d\u65b9\u4fbf\u4f7f\u7528<\/li><li>@Date 22:22 2020\/8\/10 0010<\/li><li>@Param * @param DataSource\uff1a<\/li><li>@return javax.sql.DataSource<br>**\/<br>@Bean(name = \"jdbcTemplate\")<br>public JdbcTemplate createJdbcTemplate(DataSource dataSource){<br>return new JdbcTemplate(dataSource) ;<br>}<br>}<\/li><\/ul><\/li><\/ul>\n\n\n\n<p>java<br>package config;<\/p>\n\n\n\n<p>import org.springframework.context.annotation.Bean;<br>import org.springframework.jdbc.datasource.DataSourceTransactionManager;<br>import org.springframework.transaction.PlatformTransactionManager;<\/p>\n\n\n\n<p>import javax.sql.DataSource;<\/p>\n\n\n\n<p>\/**<\/p>\n\n\n\n<ul><li>Classname:TransactionConfig<br>*<\/li><li>@description:<\/li><li>@author: \u964c\u610f\u968f\u5f71<\/li><li>@Date: 2020-08-09 22:11<\/li><li>@Version: 1.0 <strong>\/ public class TransactionConfig { \/<\/strong><ul><li>@Description :\u4eceSpring\u5bb9\u5668\u4e2d\u62ff\u5230\u914d\u7f6e\u597d\u7684DataSource\uff0c\u7136\u8bddu\u6839\u636e\u4f20\u5165\u7684\u6570\u636e\u6e90DataSource\u521b\u5efa\u4e8b\u52a1\u7ba1\u7406\u5bf9\u8c61<\/li><li>PlatformTransactionManager\u5e76\u5b58\u5165Spring\u5bb9\u5668\u4e2d<\/li><li>@Date 22:13 2020\/8\/9 0009<\/li><li>@Param * @param dataSource \uff1a<\/li><li>@return org.springframework.transaction.PlatformTransactionManager<br>**\/<br>@Bean<br>public PlatformTransactionManager createTransactionManager(DataSource dataSource){<br>return new DataSourceTransactionManager(dataSource);<br>}<br>}<\/li><\/ul><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>5.\u521b\u5efa\u6d4b\u8bd5\u7c7b<\/code><\/pre>\n\n\n\n<p>java<br>package test;<\/p>\n\n\n\n<p>import config.SpringConfig;<br>import entity.Account;<br>import org.junit.jupiter.api.AfterEach;<br>import org.junit.jupiter.api.BeforeEach;<br>import org.junit.jupiter.api.Test;<br>import org.springframework.context.ApplicationContext;<br>import org.springframework.context.annotation.AnnotationConfigApplicationContext;<br>import service.AccountService;<br>import java.util.Date;<br>import java.util.List;<\/p>\n\n\n\n<p>\/**<\/p>\n\n\n\n<ul><li>Classname:AccountTest<br>*<\/li><li>@description:<\/li><li>@author: \u964c\u610f\u968f\u5f71<\/li><li>@Date: 2020-08-01 17:39<\/li><li>@Version: 1.0<br>**\/<br>public class AccountTest {<br>private ApplicationContext applicationContext;<br>private AccountService accountService;<br>@BeforeEach<br>public void init(){<br>applicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);<br>}<br>@AfterEach<br>public void destroy(){ }<br>@Test<br>public void testSave(){<br>Account account = applicationContext.getBean(\"account\", Account.class);<br>account.setAge(434);<br>account.setName(\"\u674e\u56db\");<br>account.setPassword(\"\u6253\u4e2a\u5361\u7684\u6492\u8001\u987e\u5ba2\");<br>account.setCreateTime(new Date());<br>account.setMoney(1000);<br>AccountService accountService = applicationContext.getBean(\"accountService\", AccountService.class);<br>boolean fla = accountService.saveAccount(account);<br>System.out.println(\"\u63d2\u5165\u7528\u6237\uff1a\"+fla);<br>}<br>@Test<br>public void testUpdate(){<br>Account account = applicationContext.getBean(\"account\", Account.class);<br>account.setAge(77);<br>account.setName(\"\u7ad9\u5e72\u5565\");<br>account.setPassword(\"54545\");<br>account.setCreateTime(new Date());<br>account.setId(3);<br>AccountService accountService = applicationContext.getBean(\"accountService\", AccountService.class);<br>boolean fla = accountService.updateAccount(account);<br>System.out.println(\"\u66f4\u65b0\u7528\u6237\uff1a\"+fla);<br>}<br>@Test<br>public void testDelete(){<br>Account account = applicationContext.getBean(\"account\", Account.class);<br>account.setId(5);<br>AccountService accountService = applicationContext.getBean(\"accountService\", AccountService.class);<br>boolean fla = accountService.deleteAccountById(account.getId());<br>System.out.println(\"\u5220\u9664\u7528\u6237\uff1a\"+fla);<br>}<br>@Test<br>public void testFindOne(){<br>AccountService accountService = applicationContext.getBean(\"accountService\", AccountService.class);<br>Account account1 = accountService.findAccountById(6);<br>System.out.println(\"\u67e5\u627e\u5355\u4e2a\u7528\u6237\"+account1);<br>}<br>@Test<br>public void testFindAll(){<br>AccountService accountService = applicationContext.getBean(\"accountService\", AccountService.class);<br>List accountList = accountService.findAll();<br>for (Account a :accountList) {<br>System.out.println(a); <code>}<\/code> }<br>@Test<br>public void testTran(){<br>\/\/\u83b7\u53d6\u6ca1\u6709\u7ecf\u8fc7\u4e8b\u52a1\u7ba1\u7406\u7684\u666e\u901aAccountServiceImpl<br>AccountService accountService = applicationContext.getBean(\"accountService\", AccountService.class);<br>accountService.tranferMoney(3,6,100);<br>}<br>}<\/li><\/ul>\n\n\n\n<p>```<br>\u521b\u5efa\u597d\u540e\u5c31\u53ef\u4ee5\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n\n\n\n<p><strong>6.\u672c\u6b21\u5b9e\u9a8c\u4ee3\u7801\u5df2\u7ecf\u4e0a\u4f20\u5230\u4e2a\u4eba\u535a\u5ba2\uff0c\u5982\u6709\u9700\u8981\u8bf7\u81ea\u884c\u79fb\u6b65\u4e0b\u8f7d\uff08\u4e0b\u8f7d\u540e\u89e3\u538b\u5bfc\u5165idea\u7684maven\u5de5\u7a0b\u5373\u53ef\uff09\uff1a<\/strong><a href=\"http:\/\/moyisuiying.com\/wp-content\/uploads\/2020\/08\/springdemo_tx_annotaiton.rar\">http:\/\/moyisuiying.com\/wp-content\/uploads\/2020\/08\/springdemo_tx_annotaiton.rar<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring\u4f7f\u7528\u7eaf\u6ce8\u89e3\u914d\u7f6e\u4e8b\u52a1\u7ba1\u7406\u5e76\u5b9e\u73b0\u7b80\u5355\u7684\u589e\u5220\u67e5\u6539\u4ee5\u53ca\u6a21\u62df\u8f6c\u8d26\u529f\u80fd<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,29],"tags":[43,13,44],"_links":{"self":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/238"}],"collection":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/comments?post=238"}],"version-history":[{"count":2,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/238\/revisions"}],"predecessor-version":[{"id":241,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/238\/revisions\/241"}],"wp:attachment":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/media?parent=238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/categories?post=238"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/tags?post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}