diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..f4c3c4cd6c15ea26643fee59ffd723763f466eb8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../../:\java_proj\web-framework-spring\.idea/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/artifacts/web_framework_spring_war.xml b/.idea/artifacts/web_framework_spring_war.xml new file mode 100644 index 0000000000000000000000000000000000000000..60c2a58d8d74d79d14d5038f3a129a7c3d11dc68 --- /dev/null +++ b/.idea/artifacts/web_framework_spring_war.xml @@ -0,0 +1,14 @@ + + + $PROJECT_DIR$/target + + + web-framework-spring + war + + + + + + + \ No newline at end of file diff --git a/.idea/artifacts/web_framework_spring_war_exploded.xml b/.idea/artifacts/web_framework_spring_war_exploded.xml new file mode 100644 index 0000000000000000000000000000000000000000..8f1cf1f16cdfd0eba4146380c87590ef145a28d9 --- /dev/null +++ b/.idea/artifacts/web_framework_spring_war_exploded.xml @@ -0,0 +1,46 @@ + + + $PROJECT_DIR$/target/login3 + + + true + web-framework-spring + war + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000000000000000000000000000000000000..f5887303f341063965a5845d7d4cca8cd9d68092 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000000000000000000000000000000000000..aa00ffab7828f4818589659c804ec2cfd99baed3 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000000000000000000000000000000000000..5a2f139ce25c6f225e0cb5fb199704f51273de00 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__c3p0_c3p0_0_9_1_2.xml b/.idea/libraries/Maven__c3p0_c3p0_0_9_1_2.xml new file mode 100644 index 0000000000000000000000000000000000000000..5604cf2d0613514ef5e891a67c0620a5faf9a1af --- /dev/null +++ b/.idea/libraries/Maven__c3p0_c3p0_0_9_1_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_protobuf_protobuf_java_3_11_4.xml b/.idea/libraries/Maven__com_google_protobuf_protobuf_java_3_11_4.xml new file mode 100644 index 0000000000000000000000000000000000000000..dffec85d519ac75cba07c0c8d53275c5615c7a40 --- /dev/null +++ b/.idea/libraries/Maven__com_google_protobuf_protobuf_java_3_11_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_servlet_javax_servlet_api_3_1_0.xml b/.idea/libraries/Maven__javax_servlet_javax_servlet_api_3_1_0.xml new file mode 100644 index 0000000000000000000000000000000000000000..cfdd0cb278c1007812cbfb80528a572fdf3dafdd --- /dev/null +++ b/.idea/libraries/Maven__javax_servlet_javax_servlet_api_3_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_servlet_jsp_javax_servlet_jsp_api_2_3_1.xml b/.idea/libraries/Maven__javax_servlet_jsp_javax_servlet_jsp_api_2_3_1.xml new file mode 100644 index 0000000000000000000000000000000000000000..77f1538bc2f5d36a6dff5e3c31808137311e6d51 --- /dev/null +++ b/.idea/libraries/Maven__javax_servlet_jsp_javax_servlet_jsp_api_2_3_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_servlet_jsp_jsp_api_2_0.xml b/.idea/libraries/Maven__javax_servlet_jsp_jsp_api_2_0.xml new file mode 100644 index 0000000000000000000000000000000000000000..9e4540eafe8cec838dc6933dd153be4ccdf0246e --- /dev/null +++ b/.idea/libraries/Maven__javax_servlet_jsp_jsp_api_2_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_servlet_jstl_1_2.xml b/.idea/libraries/Maven__javax_servlet_jstl_1_2.xml new file mode 100644 index 0000000000000000000000000000000000000000..b8734468d51addfdc5d94be1279d14ded7477d02 --- /dev/null +++ b/.idea/libraries/Maven__javax_servlet_jstl_1_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_servlet_servlet_api_2_5.xml b/.idea/libraries/Maven__javax_servlet_servlet_api_2_5.xml new file mode 100644 index 0000000000000000000000000000000000000000..a6921a50ee2c57955e319a5a40f5417ca4dd6ed1 --- /dev/null +++ b/.idea/libraries/Maven__javax_servlet_servlet_api_2_5.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 0000000000000000000000000000000000000000..1600967b27158c7077d7ac4b34e8e58a8f747734 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__mysql_mysql_connector_java_8_0_22.xml b/.idea/libraries/Maven__mysql_mysql_connector_java_8_0_22.xml new file mode 100644 index 0000000000000000000000000000000000000000..3b0da397447da6f5d5f90111eda662175e8b1bb9 --- /dev/null +++ b/.idea/libraries/Maven__mysql_mysql_connector_java_8_0_22.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_aspectj_aspectjweaver_1_6_8.xml b/.idea/libraries/Maven__org_aspectj_aspectjweaver_1_6_8.xml new file mode 100644 index 0000000000000000000000000000000000000000..7bf444815c01ca1e86a058302eb6cef20487b8eb --- /dev/null +++ b/.idea/libraries/Maven__org_aspectj_aspectjweaver_1_6_8.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000000000000000000000000000000000000..94336218aee69aba1e238b0c43f8268fdfa2ce7f --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_jdom_jdom_1_1.xml b/.idea/libraries/Maven__org_jdom_jdom_1_1.xml new file mode 100644 index 0000000000000000000000000000000000000000..676ef807526470d966d105884c6d5d54752d2087 --- /dev/null +++ b/.idea/libraries/Maven__org_jdom_jdom_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mybatis_mybatis_3_4_5.xml b/.idea/libraries/Maven__org_mybatis_mybatis_3_4_5.xml new file mode 100644 index 0000000000000000000000000000000000000000..7359b98e7004e99c9e6131f19197d105ec00cd30 --- /dev/null +++ b/.idea/libraries/Maven__org_mybatis_mybatis_3_4_5.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mybatis_mybatis_spring_1_3_0.xml b/.idea/libraries/Maven__org_mybatis_mybatis_spring_1_3_0.xml new file mode 100644 index 0000000000000000000000000000000000000000..b20b38402bac98a00c06ac8ec00de5ca799ae3b1 --- /dev/null +++ b/.idea/libraries/Maven__org_mybatis_mybatis_spring_1_3_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_aop_5_2_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_aop_5_2_5_RELEASE.xml new file mode 100644 index 0000000000000000000000000000000000000000..e21dd7c146b76f246524263fb1e6157743e75098 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_aop_5_2_5_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_beans_5_2_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_beans_5_2_5_RELEASE.xml new file mode 100644 index 0000000000000000000000000000000000000000..c4f8b8b090863f41d7bc67a13fca71f037b33d8d --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_beans_5_2_5_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_context_5_2_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_context_5_2_5_RELEASE.xml new file mode 100644 index 0000000000000000000000000000000000000000..29060c74b83484dabf84c55bcda34526464d4bb5 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_context_5_2_5_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_core_5_2_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_core_5_2_5_RELEASE.xml new file mode 100644 index 0000000000000000000000000000000000000000..9d7e7643f6d8f10f70c854363224aa371d7f7967 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_core_5_2_5_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_expression_5_2_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_expression_5_2_5_RELEASE.xml new file mode 100644 index 0000000000000000000000000000000000000000..29d791e65c4f70ec72028cb163b67b22d7fda5fe --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_expression_5_2_5_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_jcl_5_2_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_jcl_5_2_5_RELEASE.xml new file mode 100644 index 0000000000000000000000000000000000000000..a9989bd118c7920702e506c6e3582d7f59e7bf18 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_jcl_5_2_5_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_jdbc_5_2_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_jdbc_5_2_5_RELEASE.xml new file mode 100644 index 0000000000000000000000000000000000000000..7cc84c0c0812f0b66f253148ec9555260bfc9599 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_jdbc_5_2_5_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_test_5_2_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_test_5_2_5_RELEASE.xml new file mode 100644 index 0000000000000000000000000000000000000000..759c42ebc411b33c346161850a8623cf29467cd6 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_test_5_2_5_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_tx_5_2_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_tx_5_2_5_RELEASE.xml new file mode 100644 index 0000000000000000000000000000000000000000..503c9698be6a8c3c8aca1213c78b1f59c470e45b --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_tx_5_2_5_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_web_5_2_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_web_5_2_5_RELEASE.xml new file mode 100644 index 0000000000000000000000000000000000000000..3f4cbf4a73b165045655661c75e925749d6883f4 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_web_5_2_5_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_webmvc_5_2_5_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_webmvc_5_2_5_RELEASE.xml new file mode 100644 index 0000000000000000000000000000000000000000..db0656c4eab34edf50787b68cecaed538d07ffa2 --- /dev/null +++ b/.idea/libraries/Maven__org_springframework_spring_webmvc_5_2_5_RELEASE.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..6409283ee3db6d8898f6421ebf99d082deab0fac --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..23850ba08e5382c2c2a9450127c1ecdaaa7c2563 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..35eb1ddfbbc029bcab630581847471d7f238ec53 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/web-framework-spring.iml b/.idea/web-framework-spring.iml new file mode 100644 index 0000000000000000000000000000000000000000..48f5c986deb990c86ecf6b1d177ace8286bb19e8 --- /dev/null +++ b/.idea/web-framework-spring.iml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 298b04a776273e1a77aa23ecf9d08c22b18501a8..265e1dee6ffff31d796ebab5557fd21635d2e5e8 100644 --- a/README.md +++ b/README.md @@ -3,35 +3,62 @@ #### 介绍 基于Spring的Web开发 -#### 软件架构 -软件架构说明 +#### 第五次作业: 基于Spring的用户登录验证 +![用户登录](https://images.gitee.com/uploads/images/2021/0320/102304_edd8e3fc_8797178.png "QQ图片20210320102242.png") +![登入成功](https://images.gitee.com/uploads/images/2021/0320/102351_aecec4a8_8797178.jpeg "QQ图片20210320102236.jpg") +![环境准备](https://images.gitee.com/uploads/images/2021/0320/102406_f03c6bd4_8797178.jpeg "QQ图片20210320102230.jpg") -#### 安装教程 +#### 第六次作业: -1. xxxx -2. xxxx -3. xxxx +构造函数注入: +![构造函数注入](https://images.gitee.com/uploads/images/2021/0404/155622_0f52145a_8797178.png "微信图片_20210404155611.png") -#### 使用说明 +属性注入: +![属性注入](https://images.gitee.com/uploads/images/2021/0404/155500_897a764f_8797178.png "微信图片_20210404155443.png") -1. xxxx -2. xxxx -3. xxxx +#### 第七次作业: -#### 参与贡献 +构造函数注入: +![作业七构造函数注入](https://images.gitee.com/uploads/images/2021/0404/160616_ea7de76b_8797178.png "微信图片_20210404160601.png") -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +属性注入: +![作业七属性注入](https://images.gitee.com/uploads/images/2021/0404/160339_840383ce_8797178.png "微信图片_20210404160318.png") +#### 第八次作业: -#### 特技 +初始化容器,包括setter注入和构造注入: +![初始化容器,包括setter注入和构造注入](https://images.gitee.com/uploads/images/2021/0417/213023_280621a1_8797178.jpeg "QQ图片20210417212836.jpg") +构造函数注入: +![构造函数注入](https://images.gitee.com/uploads/images/2021/0417/213157_06c763b9_8797178.jpeg "QQ图片20210417212841.jpg") +setter注入初始化: +![setter注入初始化](https://images.gitee.com/uploads/images/2021/0417/213239_f74488fd_8797178.jpeg "QQ图片20210417212845.jpg") +setter注入测试: +![setter注入测试](https://images.gitee.com/uploads/images/2021/0417/213402_037a2747_8797178.jpeg "QQ图片20210417212859.jpg") +构造方法注入及测试: +![构造方法注入及测试](https://images.gitee.com/uploads/images/2021/0417/213449_6863f9b5_8797178.png "QQ图片20210417212903.png") -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +#### 第九次作业: + +切面: +![切面](https://images.gitee.com/uploads/images/2021/0522/153839_874aa3a9_8797178.png "切面.png") +记录日志: +![记录日志](https://images.gitee.com/uploads/images/2021/0522/153933_706cd3bf_8797178.png "记录日志.png") +aop相关配置: +![aop相关配置](https://images.gitee.com/uploads/images/2021/0522/154019_297e8a1a_8797178.png "aop相关配置.png") +登录,利用aop记录日志,写入数据库: +![登录,aop记录日志写入数据库](https://images.gitee.com/uploads/images/2021/0522/154213_611d4540_8797178.png "登录利用aop记录日志写入数据库.png") +注册,利用aop记录日志,写入数据库: +![注册,利用aop记录日志,写入数据库](https://images.gitee.com/uploads/images/2021/0522/154318_eedff9b2_8797178.png "注册.png") + +#### 第十次作业: +事务代码, @Transactional(rollbackFor = Exception.class),遇到异常回滚: +![事务代码](https://images.gitee.com/uploads/images/2021/0522/154508_ecbe7cb8_8797178.png "事务代码.png") +注册页面: +![注册页面](https://images.gitee.com/uploads/images/2021/0522/154552_2aae6bc6_8797178.png "注册页面.png") +正常情况注册成功,于海源注册成功: +![正常注册情况下](https://images.gitee.com/uploads/images/2021/0522/154632_79728bb7_8797178.png "正常注册情况下.png") + +再次注册于海源,遇到异常事务回滚,没有再次插入于海源数据: +![再次注册于海源](https://images.gitee.com/uploads/images/2021/0522/154726_5f4d2beb_8797178.png "再次注册于海源.png") +![再次注册于海源结果](https://images.gitee.com/uploads/images/2021/0522/154822_abe3fc0a_8797178.png "再次注册于海源结果.png") \ No newline at end of file diff --git a/login2.iml b/login2.iml new file mode 100644 index 0000000000000000000000000000000000000000..4a4ce55406053014eaaca4546111548f263f24ed --- /dev/null +++ b/login2.iml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/login3.iml b/login3.iml new file mode 100644 index 0000000000000000000000000000000000000000..4a4ce55406053014eaaca4546111548f263f24ed --- /dev/null +++ b/login3.iml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..b7ff8d9cbd6e6ed250ce81c1a870a2c20c6242e3 --- /dev/null +++ b/pom.xml @@ -0,0 +1,200 @@ + + + + 4.0.0 + + com + login2 + 1.0-SNAPSHOT + war + + login2 Maven Webapp + + http://www.example.com + + + UTF-8 + 1.8 + 1.8 + + + 5.2.5.RELEASE + 3.4.5 + + + + + + + org.aspectj + aspectjweaver + 1.6.8 + + + + org.springframework + spring-aop + ${spring.version} + + + + org.springframework + spring-context + ${spring.version} + + + + org.springframework + spring-web + ${spring.version} + + + + org.springframework + spring-webmvc + ${spring.version} + + + + org.springframework + spring-test + ${spring.version} + + + + org.springframework + spring-tx + ${spring.version} + + + + org.springframework + spring-jdbc + ${spring.version} + + + + c3p0 + c3p0 + 0.9.1.2 + jar + compile + + + + org.mybatis + mybatis + ${mybatis.version} + + + + org.mybatis + mybatis-spring + 1.3.0 + + + + + + + javax.servlet + servlet-api + 2.5 + provided + + + + javax.servlet.jsp + jsp-api + 2.0 + provided + + + + + + javax.servlet + javax.servlet-api + 3.1.0 + + + + + + javax.servlet.jsp + javax.servlet.jsp-api + 2.3.1 + + + + + + javax.servlet + jstl + 1.2 + + + + + + mysql + mysql-connector-java + 8.0.22 + + + junit + junit + 4.12 + test + + + + + org.jdom + jdom + 1.1 + + + + + + + + + login3 + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-war-plugin + 3.2.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/src/main/java/com/aop/WriteLog.java b/src/main/java/com/aop/WriteLog.java new file mode 100644 index 0000000000000000000000000000000000000000..37aa90b938d1eff9620383542978eb5bda51b741 --- /dev/null +++ b/src/main/java/com/aop/WriteLog.java @@ -0,0 +1,82 @@ +package com.aop; + +import com.domain.MyLogging; +import com.service.MyLoggingService; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.After; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.Method; +import java.sql.SQLException; +import java.util.Date; +import java.util.logging.Logger; + +/** + * @ClassName : WriteLog + * @Description : + * @Author : YUHAIyuan + * @Date: 2021-05-21 14:19 + */ + +@Component +@Aspect +public class WriteLog { + + @Resource + private MyLoggingService myLoggingService; + + + @Pointcut("execution(* com.service.UserService.*(..))") + public void controllerAspect() { + System.out.println("controllerAspect " ); + } + + /** + * before + */ + @Before("controllerAspect()") + public void before(JoinPoint jp) throws SQLException { + System.out.println("before " ); + // 获取session中当前用户 + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + + StringBuffer requestURL = request.getRequestURL(); + System.out.println("requestURL = " + requestURL); + + String remoteHost = request.getRemoteHost(); + System.out.println("remoteHost = " + remoteHost); + + MyLogging myLogging = new MyLogging(); + myLogging.setUrl(requestURL.toString()); + + String desc = "无"; + if (requestURL.toString().contains("login")){ + desc = "登录操作"; + }else if(requestURL.toString().contains("register")){ + desc = "注册操作"; + } + + myLogging.setDescription(desc); + myLogging.setHost(remoteHost); + myLoggingService.save(myLogging); + } + + /** + * after inform + */ + @After("controllerAspect()") + public void after(JoinPoint joinPoint) { + System.out.println("after " ); + + } +} diff --git a/src/main/java/com/controller/UserController.java b/src/main/java/com/controller/UserController.java new file mode 100644 index 0000000000000000000000000000000000000000..6be552d40e0cc5419b8a2e5ac34ed6b512f3f0b1 --- /dev/null +++ b/src/main/java/com/controller/UserController.java @@ -0,0 +1,56 @@ +package com.controller; + +import com.domain.User; +import com.service.UserService; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.sql.SQLException; + + +/** + * @ClassName : UserController + * @Description : 用户控制层 + * @Author :YUHAIyuan + * @Date: 2021-03-20 09:01 + */ +@Controller +public class UserController { + + @Resource + private UserService userService; + + @GetMapping("/login") + public String toLogin(){ + return "login"; + } + + @PostMapping("/login") + public String login(User user, HttpServletRequest request){ + System.out.println("user = " + user); + + User u = userService.select(user); + System.out.println("u = " + u); + if(u != null){ + request.getSession().setAttribute("user",u); + return "main"; + } + + return "login"; + } + + + @GetMapping("/register") + public String toRegister(){ + return "register"; + } + + @PostMapping("/register") + public String register(User user,HttpServletRequest request) throws SQLException { + System.out.println("user = " + user); + return userService.save(user)?"login":"register"; + } +} diff --git a/src/main/java/com/dao/MyLoggingDao.java b/src/main/java/com/dao/MyLoggingDao.java new file mode 100644 index 0000000000000000000000000000000000000000..12c46c9faafb48d65dec7a84036aa4d9e3b2c7f5 --- /dev/null +++ b/src/main/java/com/dao/MyLoggingDao.java @@ -0,0 +1,19 @@ +package com.dao; + +import com.domain.MyLogging; +import com.domain.User; +import org.apache.ibatis.annotations.Insert; +import org.springframework.stereotype.Repository; + +/** + * @ClassName : MyLoggingDao + * @Description : + * @Author : YUHAIyuan + * @Date: 2021-05-21 17:34 + */ +@Repository +public interface MyLoggingDao { + + @Insert("insert into my_logging (url,description,host) values (#{url},#{description},#{host})") + public boolean insert(MyLogging myLogging); +} diff --git a/src/main/java/com/dao/UserDao.java b/src/main/java/com/dao/UserDao.java new file mode 100644 index 0000000000000000000000000000000000000000..ff7ea7bfe126ae0dbbd3b9e2322c43453b0d0cea --- /dev/null +++ b/src/main/java/com/dao/UserDao.java @@ -0,0 +1,42 @@ +package com.dao; + +import com.domain.User; +import com.utils.JDBCUtils; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Select; +import org.springframework.stereotype.Repository; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + + +/** + * @ClassName : UserDao + * @Description : 用户持久层 + * @Author :YUHAIyuan + * @Date: 2021-03-20 09:02 + */ +@Repository +public interface UserDao { + + /** + * 登录查询 + */ + @Select("select * from user where username = #{username} and password = #{password}") + public User select(User user); + + /** + * 根据用户名查询 + * @param user + * @return + */ + @Select("select * from user where username = #{username}") + public User selectOne(User user); + + + @Insert("insert into user (username,password) values (#{username},#{password})") + public boolean insert(User user); + +} diff --git a/src/main/java/com/domain/MyLogging.java b/src/main/java/com/domain/MyLogging.java new file mode 100644 index 0000000000000000000000000000000000000000..a4397b3bc9375e5458588f9b8f92df9459785844 --- /dev/null +++ b/src/main/java/com/domain/MyLogging.java @@ -0,0 +1,67 @@ +package com.domain; + +/** + * @ClassName : MyLogging + * @Description : + * @Author : YUHAIyuan + * @Date: 2021-05-21 17:32 + */ +public class MyLogging { + private Long id; + private String url; + private String description; + private String host; + + public MyLogging() { + } + + public MyLogging(Long id, String url, String description, String host) { + this.id = id; + this.url = url; + this.description = description; + this.host = host; + } + + @Override + public String toString() { + return "MyLogging{" + + "id=" + id + + ", url='" + url + '\'' + + ", description='" + description + '\'' + + ", host='" + host + '\'' + + '}'; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } +} + diff --git a/src/main/java/com/domain/User.java b/src/main/java/com/domain/User.java new file mode 100644 index 0000000000000000000000000000000000000000..92b7c3f7b367543b8d3e5f2d3de6d6873d99fc02 --- /dev/null +++ b/src/main/java/com/domain/User.java @@ -0,0 +1,56 @@ +package com.domain; + + +/** + * @ClassName : User + * @Description : 用户实体 + * @Author :YUHAIyuan + * @Date: 2021-03-20 09:10 + */ +public class User { + private Long id; + private String username; + private String password; + + public User() { + } + + public User(Long id, String username, String password) { + this.id = id; + this.username = username; + this.password = password; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", username='" + username + '\'' + + ", password='" + password + '\'' + + '}'; + } +} diff --git a/src/main/java/com/service/MyLoggingService.java b/src/main/java/com/service/MyLoggingService.java new file mode 100644 index 0000000000000000000000000000000000000000..f4457753ca227584ca7aae44561e70b8dda0107a --- /dev/null +++ b/src/main/java/com/service/MyLoggingService.java @@ -0,0 +1,28 @@ +package com.service; + +import com.dao.MyLoggingDao; +import com.domain.MyLogging; +import com.domain.User; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.sql.SQLException; + +/** + * @ClassName : MyLoggingService + * @Description : + * @Author : YUHAIyuan + * @Date: 2021-05-21 17:35 + */ +@Service +public class MyLoggingService { + + @Resource + private MyLoggingDao myLoggingDao; + + @Transactional(rollbackFor = Exception.class) + public boolean save(MyLogging myLogging) throws SQLException { + return myLoggingDao.insert(myLogging); + } +} diff --git a/src/main/java/com/service/UserService.java b/src/main/java/com/service/UserService.java new file mode 100644 index 0000000000000000000000000000000000000000..7d2c26c3210a40862e81672d8fee2f962089ba9b --- /dev/null +++ b/src/main/java/com/service/UserService.java @@ -0,0 +1,48 @@ +package com.service; + +import com.dao.UserDao; +import com.domain.User; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.sql.SQLException; + + +/** + * @ClassName : UserService + * @Description : 用户业务层 + * @Author :YUHAIyuan + * @Date: 2021-03-20 09:20 + */ +@Service +public class UserService { + + @Resource + private UserDao userDao; +// private UserDao userDao = new UserDao(); + + + public User select(User user){ + return userDao.select(user); + } + + /** + * Transactional注解控制事务,遇到异常回滚 + * @param user + * @return + * @throws SQLException + */ + @Transactional(rollbackFor = Exception.class) + public boolean save(User user) throws SQLException { + User u = userDao.selectOne(user); + + if(null != u){ + throw new RuntimeException("用户已经存在"); + } + + System.out.println("插入的用户是 = " + user); + userDao.insert(user); + return true; + } +} diff --git a/src/main/java/com/utils/JDBCUtils.java b/src/main/java/com/utils/JDBCUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..83bd6d925b46e9c0b78624f25e26cf9889025dae --- /dev/null +++ b/src/main/java/com/utils/JDBCUtils.java @@ -0,0 +1,240 @@ +package com.utils; + +import java.sql.*; + +/** + * @ClassName : JDBCMain + * @Description : + * @Author : + * @Date: 2021-3-20 09:19 + */ +public class JDBCUtils { + + static Connection connection = null; + + /** + * 获取mysql数据库连接 + */ + static public Connection getConnectMysql() { + try { + //通过类的反射加载类驱动 + Class.forName("com.mysql.cj.jdbc.Driver"); + + //连接数据库相关信息 + String url = "jdbc:mysql://localhost/login?serverTimezone=GMT%2B8&user=root&password=123456"; + + //创建连接 + connection = DriverManager.getConnection(url); + System.out.println("成功连接数据库!!!"); + return connection; + + } catch (ClassNotFoundException e) { + System.out.println("载入JDBC驱动类失败"); + } catch (SQLException e) { + System.out.println("创建数据库连接失败"); + } + return null; + } + + + + static public void close(){ + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + System.out.println("mysql链接关闭异常"); + } + } + + /** + * 数据库查询 + */ + static void select(){ + //获取数据库连接 + Connection connection = getConnectMysql(); + + //sql语句 + String sql = "select * from account"; + + //创建Statement对象 + Statement statement = null; + + //查询结果返回集合 + ResultSet resultSet = null; + try { + //获取Statement对象 + statement = connection.createStatement(); + + //执行sql + resultSet = statement.executeQuery(sql); + + while (resultSet.next()){ + //id、name、money表示数据库对应的字段 + System.out.println("resultSet.getString(\"id\") = " + resultSet.getString("id")); + System.out.println("resultSet.getString(\"name\") = " + resultSet.getString("name")); + System.out.println("resultSet.getString(\"money\") = " + resultSet.getString("money")); + } + + + } catch (SQLException e) { + System.out.println("查询数据库失败"); + }finally { + try { + resultSet.close(); + statement.close(); + connection.close(); + } catch (SQLException e) { + System.out.println("关闭资源错误"); + resultSet = null; + statement = null; + connection = null; + } + + } + + + } + + /** + * 数据库插入 + */ + static void insert(){ + //获取数据库连接 + Connection connection = getConnectMysql(); + + //sql语句 + String name = "Tony"; + Integer money = 100; + + //sql语句 + String sql = "insert into account(name,money) values('"+ name +"','"+ money +"')"; + + //创建Statement对象 + Statement statement = null; + + //查询结果返回集合 + ResultSet resultSet = null; + try { + //获取Statement对象 + statement = connection.createStatement(); + + //执行sql + int i = statement.executeUpdate(sql); + System.out.println("数据插入成功,影响的数据条数 = " + i); + + + } catch (SQLException e) { + + System.out.println("插入数据库失败,"+ e.getMessage()); + }finally { + try { + statement.close(); + connection.close(); + } catch (SQLException e) { + System.out.println("关闭资源错误"); + statement = null; + connection = null; + } + + } + + + } + + /** + * 数据库更新 + */ + static void update(){ + //获取数据库连接 + Connection connection = getConnectMysql(); + + //sql语句 + String name = "汤姆猫"; + Integer money = 2000; + + //sql语句 + //String sql = "insert into account(name,money) values('"+ name +"','"+ money +"')"; + String sql = "update account set name = '"+ name +"', money = '"+ money +"' where id = 28"; + + + //创建Statement对象 + Statement statement = null; + + //查询结果返回集合 + ResultSet resultSet = null; + try { + //获取Statement对象 + statement = connection.createStatement(); + + //执行sql + int i = statement.executeUpdate(sql); + System.out.println("数据更新成功,影响的数据条数 = " + i); + + + } catch (SQLException e) { + + System.out.println("更新数据库失败,"+ e.getMessage()); + }finally { + try { + statement.close(); + connection.close(); + } catch (SQLException e) { + System.out.println("关闭资源错误"); + statement = null; + connection = null; + } + + } + + + } + + /** + * 删除数据 + */ + static void delete(){ + //获取数据库连接 + Connection connection = getConnectMysql(); + + //sql语句 + String name = "汤姆猫"; + Integer money = 2000; + + //sql语句 + //String sql = "insert into account(name,money) values('"+ name +"','"+ money +"')"; + String sql = "delete from account where id = 28"; + + + //创建Statement对象 + Statement statement = null; + + //查询结果返回集合 + ResultSet resultSet = null; + try { + //获取Statement对象 + statement = connection.createStatement(); + + //执行sql + int i = statement.executeUpdate(sql); + System.out.println("数据删除成功,影响的数据条数 = " + i); + + + } catch (SQLException e) { + + System.out.println("数据库删除数据失败,"+ e.getMessage()); + }finally { + try { + statement.close(); + connection.close(); + } catch (SQLException e) { + System.out.println("关闭资源错误"); + statement = null; + connection = null; + } + + } + + + } +} diff --git a/src/main/java/com/work06/attribute/entity/Director.java b/src/main/java/com/work06/attribute/entity/Director.java new file mode 100644 index 0000000000000000000000000000000000000000..a2fe0d478c23c1ceb605a15ca689dc2ba446afbc --- /dev/null +++ b/src/main/java/com/work06/attribute/entity/Director.java @@ -0,0 +1,40 @@ +package com.work06.attribute.entity; + +/** + * @ClassName : Director + * @Description : 导演类,属性注入 + * @Author : + * @Date: 2021-04-01 22:45 + */ +public class Director { + +// 属性注入,成员变量 + private MoAttack moAttack = new MoAttack(); + + +// private MoAttack moAttack; +// +// public MoAttack getMoAttack() { +// return moAttack; +// } +// +// public void setMoAttack(MoAttack moAttack) { +// this.moAttack = moAttack; +// } + + /** + * 导演电影 + */ + public void directMovie(){ + moAttack.cityGateAsk(); + } +// +// public static void main(String[] args) { +// MoAttack moAttack = new MoAttack(); +// Director director = new Director(); +// director.setMoAttack(moAttack); +// director.directMovie(); +// +// } + +} diff --git a/src/main/java/com/work06/attribute/entity/LuDeHua.java b/src/main/java/com/work06/attribute/entity/LuDeHua.java new file mode 100644 index 0000000000000000000000000000000000000000..f742c7d6a564a6dc72591e060bb59e3e767a9057 --- /dev/null +++ b/src/main/java/com/work06/attribute/entity/LuDeHua.java @@ -0,0 +1,25 @@ +package com.work06.attribute.entity; + +/** + * @ClassName : LuDeHua + * @Description : 刘德华 + * @Author : + * @Date: 2021-04-01 22:46 + */ +public class LuDeHua { + + /** + * 回复梁国守军 + * @param str + */ + public void responseAsk(String str){ + //打印传过来的字符串 + System.out.println(str); + } + + +// public static void main(String[] args) { +// LuDeHua luDeHua01 = new LuDeHua(); +// luDeHua01.responseAsk("我是刘德华"); +// } +} diff --git a/src/main/java/com/work06/attribute/entity/MoAttack.java b/src/main/java/com/work06/attribute/entity/MoAttack.java new file mode 100644 index 0000000000000000000000000000000000000000..548abe6ebda545970fa5522f20c971720708ed3b --- /dev/null +++ b/src/main/java/com/work06/attribute/entity/MoAttack.java @@ -0,0 +1,23 @@ +package com.work06.attribute.entity; + +/** + * @ClassName : MoAttack + * @Description : 梁国守军 + * @Author : + * @Date: 2021-04-01 22:48 + */ +public class MoAttack { + + + //属性注入,成员变量 + private LuDeHua luDeHua = new LuDeHua(); + + + /** + *梁国守军提问 + */ + public void cityGateAsk(){ + System.out.println("梁国守军:来者何人"); + luDeHua.responseAsk("墨者:墨者革离"); + } +} diff --git a/src/main/java/com/work06/attribute/test/Main.java b/src/main/java/com/work06/attribute/test/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..96e27895d1b459e2b87d1d8ee9db5d17df729556 --- /dev/null +++ b/src/main/java/com/work06/attribute/test/Main.java @@ -0,0 +1,22 @@ +package com.work06.attribute.test; + + +import com.work06.attribute.entity.Director; + +/** + * @ClassName : Main + * @Description : 测试依赖注入 + * @Author : + * @Date: 2021-04-01 22:57 + */ +public class Main { + + public static void main(String[] args) { + // Director :导演类模板 + // 类的使用:用new 关键字进行创建,以Director为类模板,创建一个实例对象director01 + Director director01 = new Director(); + + //调用该实例对象里面的被public修饰方法 + director01.directMovie(); + } +} diff --git a/src/main/java/com/work06/construction/entity/Director.java b/src/main/java/com/work06/construction/entity/Director.java new file mode 100644 index 0000000000000000000000000000000000000000..db2fe07728cb47f6b065317f23733d20d45b65ff --- /dev/null +++ b/src/main/java/com/work06/construction/entity/Director.java @@ -0,0 +1,42 @@ +package com.work06.construction.entity; + +/** + * @ClassName : Director + * @Description : 导演类,构造方法注入 + * @Author : + * @Date: 2021-04-01 22:45 + */ +public class Director { + + //成员变量 + private MoAttack moAttack; + + public Director() { + } + + //有参数的构造方法 + public Director(MoAttack mo){ + moAttack = mo; + } + + + + + /** + * 导演电影 + */ + public void directMovie(){ + moAttack.cityGateAsk(); + } + + + +// public static void main(String[] args) { +// MoAttack mo = new MoAttack(); +// +// //将MoAttack通过构造方法new Director(mo);注入到Director中 +// Director d = new Director(mo); +// d.directMovie(); +// } + +} diff --git a/src/main/java/com/work06/construction/entity/LuDeHua.java b/src/main/java/com/work06/construction/entity/LuDeHua.java new file mode 100644 index 0000000000000000000000000000000000000000..d087aba1a29848b89e292849bed5f539f43284b1 --- /dev/null +++ b/src/main/java/com/work06/construction/entity/LuDeHua.java @@ -0,0 +1,18 @@ +package com.work06.construction.entity; + +/** + * @ClassName : LuDeHua + * @Description : 刘德华 + * @Author : + * @Date: 2021-04-01 22:46 + */ +public class LuDeHua { + + /** + * 回复梁国守军 + * @param str + */ + public void responseAsk(String str){ + System.out.println(str); + } +} diff --git a/src/main/java/com/work06/construction/entity/MoAttack.java b/src/main/java/com/work06/construction/entity/MoAttack.java new file mode 100644 index 0000000000000000000000000000000000000000..2f2706d6589f79dd70d397aaaf288073ec8db326 --- /dev/null +++ b/src/main/java/com/work06/construction/entity/MoAttack.java @@ -0,0 +1,42 @@ +package com.work06.construction.entity; + +/** + * @ClassName : MoAttack + * @Description : 梁国守军 + * @Author : + * @Date: 2021-04-01 22:48 + */ +public class MoAttack { + + //定义了一个刘德华变量 + private LuDeHua luDeHua; + + + //有参参构造方法 + public MoAttack(LuDeHua ldh) { + luDeHua = ldh; + } + + //无参的构造方法 + public MoAttack() { + } + + /** + *梁国守军提问 + */ + public void cityGateAsk(){ + System.out.println("梁国守军:来者何人"); + luDeHua.responseAsk("墨者:墨者革离"); + + } + + + //一切函数的入口,比较特殊的方法 +// public static void main(String[] args) { +// LuDeHua luDeHua = new LuDeHua(); +// +// +// MoAttack moAttack = new MoAttack(luDeHua); +// moAttack.cityGateAsk(); +// } +} diff --git a/src/main/java/com/work06/construction/test/Main.java b/src/main/java/com/work06/construction/test/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..ba703ae90d7c254f4249d8375e28566fcc22b78d --- /dev/null +++ b/src/main/java/com/work06/construction/test/Main.java @@ -0,0 +1,29 @@ +package com.work06.construction.test; + +import com.work06.construction.entity.Director; +import com.work06.construction.entity.LuDeHua; +import com.work06.construction.entity.MoAttack; + +/** + * @ClassName : Main + * @Description : 测试依赖注入 + * @Author : + * @Date: 2021-04-01 22:57 + */ +public class Main { + + //一切函数的入口,比较特殊的方法 + public static void main(String[] args) { + //首先创建需要注入的刘德华 + LuDeHua lu = new LuDeHua(); + + //将创建好的刘德华注入MoAttack + MoAttack mo = new MoAttack(lu); + + //将mo注入给导演类Director + Director director = new Director(mo); + + //使用Director里面的方法 + director.directMovie(); + } +} diff --git a/src/main/java/com/work07/attribute/entity/Director.java b/src/main/java/com/work07/attribute/entity/Director.java new file mode 100644 index 0000000000000000000000000000000000000000..bd47f09aedceef66501f990bf810016b10dddbcd --- /dev/null +++ b/src/main/java/com/work07/attribute/entity/Director.java @@ -0,0 +1,28 @@ +package com.work07.attribute.entity; + +/** + * @ClassName : Director + * @Description : 导演类,属性注入 + * @Author : + * @Date: 2021-04-01 22:45 + */ +public class Director { + + MoAttack moAttack; + + public MoAttack getMoAttack() { + return moAttack; + } + + public void setMoAttack(MoAttack moAttack) { + this.moAttack = moAttack; + } + + /** + * 导演电影 + */ + public void directMovie(){ + moAttack.cityGateAsk(); + } + +} diff --git a/src/main/java/com/work07/attribute/entity/LuDeHua.java b/src/main/java/com/work07/attribute/entity/LuDeHua.java new file mode 100644 index 0000000000000000000000000000000000000000..826e4a3bf540e9c25e50d808cef49d348bd3a214 --- /dev/null +++ b/src/main/java/com/work07/attribute/entity/LuDeHua.java @@ -0,0 +1,19 @@ +package com.work07.attribute.entity; + +/** + * @ClassName : LuDeHua + * @Description : 刘德华 + * @Author : + * @Date: 2021-04-01 22:46 + */ +public class LuDeHua { + + + /** + * 回复梁国守军 + * @param str + */ + public void responseAsk(String str){ + System.out.println(str); + } +} diff --git a/src/main/java/com/work07/attribute/entity/MoAttack.java b/src/main/java/com/work07/attribute/entity/MoAttack.java new file mode 100644 index 0000000000000000000000000000000000000000..e24a6bdac8f181770117222ac5df3eea99fe60e9 --- /dev/null +++ b/src/main/java/com/work07/attribute/entity/MoAttack.java @@ -0,0 +1,31 @@ +package com.work07.attribute.entity; + +/** + * @ClassName : MoAttack + * @Description : 梁国守军 + * @Author : + * @Date: 2021-04-01 22:48 + */ +public class MoAttack { + public void setLuDeHua(LuDeHua luDeHua) { + this.luDeHua = luDeHua; + } + + private LuDeHua luDeHua; + + + public LuDeHua getLuDeHua() { + return luDeHua; + } + + + + /** + *梁国守军提问 + */ + public void cityGateAsk(){ + System.out.println("梁国守军:来者何人"); + luDeHua.responseAsk("墨者:墨者革离"); + + } +} diff --git a/src/main/java/com/work07/attribute/entity/Person.java b/src/main/java/com/work07/attribute/entity/Person.java new file mode 100644 index 0000000000000000000000000000000000000000..0704e7033e0dc594840d7063d2ac61d16b5b537c --- /dev/null +++ b/src/main/java/com/work07/attribute/entity/Person.java @@ -0,0 +1,97 @@ +package com.work07.attribute.entity; + +/** + * @ClassName : Person + * @Description : 测试 + * @Author : + * @Date: 2021-04-01 23:34 + */ +public class Person { + /** + * java类的基本构成:变量+方法 + * 规则:必须要有一个构造方法,如果没有,系统默认生成一个自己看不见构造方法,用于构造一个对象,默认无参的使用的方式:new 类名称(),例如:new Person(); + */ + + + //成员变量 + private Integer id; + private String name; + private String sex; + private Integer age; + + + + //成员方法 + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public void print(){ + System.out.println(this.toString()); + } + + @Override + public String toString() { + return "Person{" + + "id=" + id + + ", name='" + name + '\'' + + ", sex='" + sex + '\'' + + ", age=" + age + + '}'; + } + + + //有参数的构造方法 + public Person(Integer id, String name, String sex, Integer age) { + this.id = id; + this.name = name; + this.sex = sex; + this.age = age; + } + + //无参数的构造方法 + public Person() { + } + + public static void main(String[] args) { + //调用无参构造方法 + Person person01 = new Person(); + System.out.println("person01 = " + person01); + + + //调用有参的构造方法 + Person person02 = new Person(1,"Tony","男",18); + System.out.println("person02 = " + person02); + + //spring容器,自动创建一个容器,该容器存放配置好的对象实例,(相当于把类创建好,放到容器里面,要用的时候直接从容器里面拿) + + } +} diff --git a/src/main/java/com/work07/attribute/test/Main.java b/src/main/java/com/work07/attribute/test/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..6e74f0442160ca2fba309bcf17f7ea2575823ad1 --- /dev/null +++ b/src/main/java/com/work07/attribute/test/Main.java @@ -0,0 +1,42 @@ +package com.work07.attribute.test; + +import com.work07.attribute.entity.Director; +import com.work07.attribute.entity.LuDeHua; +import com.work07.attribute.entity.MoAttack; +import com.work07.attribute.entity.Person; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @ClassName : Main + * @Description : 测试依赖注入 + * @Author : + * @Date: 2021-04-01 22:57 + */ +public class Main { + + public static void main(String[] args) { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("springmvc.xml"); + Director director = (Director) context.getBean("attrDirector"); + + + director.directMovie(); + + } + + public static void constructionTest(){ + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("springmvc.xml"); + + LuDeHua luDeHua = (LuDeHua) context.getBean("attrLuDeHua"); + luDeHua.responseAsk("墨者:墨者革离"); + + MoAttack moAttack = (MoAttack) context.getBean("attrMoAttack"); + moAttack.cityGateAsk(); + + Director director = (Director) context.getBean("attrDirector"); + director.directMovie(); + + Person person = (Person) context.getBean("attrPerson"); + person.print(); + + } +} diff --git a/src/main/java/com/work07/construction/entity/Director.java b/src/main/java/com/work07/construction/entity/Director.java new file mode 100644 index 0000000000000000000000000000000000000000..936b130117a34e910ecc8451627de65f67403e5a --- /dev/null +++ b/src/main/java/com/work07/construction/entity/Director.java @@ -0,0 +1,25 @@ +package com.work07.construction.entity; + +/** + * @ClassName : Director + * @Description : 导演类,属性注入 + * @Author : + * @Date: 2021-04-01 22:45 + */ +public class Director { + + private MoAttack moAttack; + + + public Director(MoAttack moAttack) { + this.moAttack = moAttack; + } + + /** + * 导演电影 + */ + public void directMovie(){ + moAttack.cityGateAsk(); + } + +} diff --git a/src/main/java/com/work07/construction/entity/LuDeHua.java b/src/main/java/com/work07/construction/entity/LuDeHua.java new file mode 100644 index 0000000000000000000000000000000000000000..643fe9e5fcc918001dbd04c1735f7645875bbe70 --- /dev/null +++ b/src/main/java/com/work07/construction/entity/LuDeHua.java @@ -0,0 +1,21 @@ +package com.work07.construction.entity; + +/** + * @ClassName : LuDeHua + * @Description : 刘德华 + * @Author : + * @Date: 2021-04-01 22:46 + */ +public class LuDeHua { + + public LuDeHua() { + } + + /** + * 回复梁国守军 + * @param str + */ + public void responseAsk(String str){ + System.out.println(str); + } +} diff --git a/src/main/java/com/work07/construction/entity/MoAttack.java b/src/main/java/com/work07/construction/entity/MoAttack.java new file mode 100644 index 0000000000000000000000000000000000000000..1e316973f105e236d028691810838d6fe2409295 --- /dev/null +++ b/src/main/java/com/work07/construction/entity/MoAttack.java @@ -0,0 +1,25 @@ +package com.work07.construction.entity; + +/** + * @ClassName : MoAttack + * @Description : 梁国守军 + * @Author : + * @Date: 2021-04-01 22:48 + */ +public class MoAttack { + + private LuDeHua luDeHua; + + public MoAttack(LuDeHua luDeHua) { + this.luDeHua = luDeHua; + } + + /** + *梁国守军提问 + */ + public void cityGateAsk(){ + System.out.println("梁国守军:来者何人"); + luDeHua.responseAsk("墨者:墨者革离"); + + } +} diff --git a/src/main/java/com/work07/construction/entity/Person.java b/src/main/java/com/work07/construction/entity/Person.java new file mode 100644 index 0000000000000000000000000000000000000000..f8599379b73b94f6a50f6715ab391766bf54c8c2 --- /dev/null +++ b/src/main/java/com/work07/construction/entity/Person.java @@ -0,0 +1,37 @@ +package com.work07.construction.entity; + +/** + * @ClassName : Person + * @Description : 测试 + * @Author : + * @Date: 2021-04-01 23:34 + */ +public class Person { + private Integer id; + private String name; + private String sex; + private Integer age; + + + //有参构造方法 + public Person(Integer id, String name, String sex, Integer age) { + this.id = id; + this.name = name; + this.sex = sex; + this.age = age; + } + + public void print(){ + System.out.println(this.toString()); + } + + @Override + public String toString() { + return "Person{" + + "id=" + id + + ", name='" + name + '\'' + + ", sex='" + sex + '\'' + + ", age=" + age + + '}'; + } +} diff --git a/src/main/java/com/work07/construction/test/Main.java b/src/main/java/com/work07/construction/test/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..678fb2462e93c6f3d050ec6c16c0c15f9d696f9b --- /dev/null +++ b/src/main/java/com/work07/construction/test/Main.java @@ -0,0 +1,57 @@ +package com.work07.construction.test; + +import com.work07.construction.entity.Director; +import com.work07.construction.entity.LuDeHua; +import com.work07.construction.entity.MoAttack; +import com.work07.construction.entity.Person; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @ClassName : Main + * @Description : 测试依赖注入 + * @Author : + * @Date: 2021-04-01 22:57 + */ +public class Main { + + public static void main(String[] args) { + +// //找到spring配置文件 +// ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("springmvc.xml"); +// //通过id创建一个LuDeHua对象 +// LuDeHua luDeHua = (LuDeHua) context.getBean("constrLuDeHua"); +// //调用方法 +// luDeHua.responseAsk("hello"); + + + + //找到spring配置文件 + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("springmvc.xml"); + //通过id创建一个LuDeHua对象 + Director d = (Director) context.getBean("constrDirector"); + //调用方法 + d.directMovie(); + + + + +// constructionTest(); + } + + public static void constructionTest(){ + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("springmvc.xml"); + + LuDeHua luDeHua = (LuDeHua) context.getBean("constrLuDeHua"); + luDeHua.responseAsk("墨者:墨者革离"); + + MoAttack moAttack = (MoAttack) context.getBean("constrMoAttack"); + moAttack.cityGateAsk(); + + Director director = (Director) context.getBean("constrDirector"); + director.directMovie(); + + Person person = (Person) context.getBean("constrPerson"); + person.print(); + + } +} diff --git a/src/main/java/com/work08/reflex/MyClassPathXmlApplicationContext.java b/src/main/java/com/work08/reflex/MyClassPathXmlApplicationContext.java new file mode 100644 index 0000000000000000000000000000000000000000..fcb39c33869f248ccc815aa33d655dbad4f271ca --- /dev/null +++ b/src/main/java/com/work08/reflex/MyClassPathXmlApplicationContext.java @@ -0,0 +1,373 @@ +package com.work08.reflex; + + +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.input.SAXBuilder; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * @ClassName : ClassPathXmlApplicationContext + * @Description : 反射 + * @Author :YUHAIyuan + * @Date: 2021-04-13 22:48 + */ +public class MyClassPathXmlApplicationContext { + /** + * 创建一个容器 + */ + private Map container = new HashMap<>(); + + /** + * 初始化容器,包括setter注入和构造注入 + * + * @param xml + * @throws Exception + */ + public void init(String xml) throws Exception { + //自己实现的Spring的IOC容器 + SAXBuilder builder = new SAXBuilder(); + InputStream stream = new FileInputStream(xml); + Document dom = builder.build(stream); + //获取根节点 + Element root = dom.getRootElement(); + //返回的是子节点的集合 + List children = root.getChildren(); + + for (Element child : children) { + if (!child.getName().equals("bean")) {continue;} + + //获取类 + String classPath = child.getAttributeValue("class"); + //通过反射获取类 + Class clazz = Class.forName(classPath); + //获取对象的唯一标识,用唯一标识为key,newInstance为value,存入map中 + String id = child.getAttributeValue("id"); + //property标签对象的集合 + List attrList = child.getChildren(); + //setter注入 + if (attrList.size() > 0 && attrList.get(0).getName().equals("property")){ + setterInject(clazz, id, attrList); + }else if (attrList.size() > 0 && attrList.get(0).getName().equals("constructor-arg")){ + //构造函数注入 + constrInject(clazz, id, attrList); + } + //该类没有成员变量的情况,直接反射注入 + if (attrList.size() == 0) { + Object obj = clazz.newInstance(); + container.put(id, obj); + } + } + } + + /** + * 构造函数注入 + * + * @param clazz 通过反射获取的类 + * @param id bean的id,由xml配置文件进行配置 + * @param attrList xml文件中,bean标签内的标签,像property等 + * @throws ClassNotFoundException + * @throws NoSuchMethodException + * @throws InstantiationException + * @throws IllegalAccessException + * @throws InvocationTargetException + */ + private void constrInject(Class clazz, String id, List attrList) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { + Object obj = null; + if (attrList.size() > 0 && attrList.get(0).getName().equals("constructor-arg")) { + //构造函数的参数类型数组 + Class[] paramClass = new Class[attrList.size()]; + //构造函数的参数值 + Object[] paramObj = new Object[attrList.size()]; + //循环读取标签的数据constructor-arg的type和value + for (int i = 0; i < attrList.size(); i++) { + Element attr = attrList.get(i); + //type="xxxx" + String type = attr.getAttributeValue("type"); + //value="xxxx" + String value = attr.getAttributeValue("value"); + //ref="xxxx" + String ref = attr.getAttributeValue("ref"); + + if (ref == null) { + paramClass[i] = Class.forName(type); + if (null != type && type.equals("java.lang.Integer")) { + paramObj[i] = Integer.valueOf(value); + } else if (null != type && type.equals("java.lang.String")) { + paramObj[i] = String.valueOf(value); + } else if (null != type && type.equals("java.lang.Double")) { + paramObj[i] = Double.valueOf(value); + } else if (null != type && type.equals("java.lang.Float")) { + paramObj[i] = Float.valueOf(value); + } + } else { + paramClass[i] = container.get(ref).getClass(); + paramObj[i] = container.get(ref); + } + } + Constructor constructor = clazz.getConstructor(paramClass); + obj = constructor.newInstance(paramObj); + //添加到容器 + container.put(id, obj); + } + } + + /** + * setter注入初始化 + * @param clazz 通过反射获取的类 + * @param id bean的id,由xml配置文件进行配置 + * @param attrList xml文件中,bean标签内的标签,像property等 + * @throws ClassNotFoundException + * @throws NoSuchMethodException + * @throws IllegalAccessException + * @throws InvocationTargetException + * @throws InstantiationException + */ + private void setterInject(Class clazz, String id, List attrList) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { + //setter注入 + Object obj = clazz.newInstance(); + container.put(id, obj); + if (attrList.size() > 0 && attrList.get(0).getName().equals("property")) { + for (int i = 0; i < attrList.size(); i++) { + Element attr = attrList.get(i); + if (attr.getName().equals("property")) { + //name="xxxx" + String filed = attr.getAttributeValue("name"); + //value="xxxx" + String value = attr.getAttributeValue("value"); + //ref="xxxx" + String ref = attr.getAttributeValue("ref"); + String methodName = "set" + filed.substring(0, 1).toUpperCase() + filed.substring(1); + if (ref == null) { + //获取方法的传入的参数类型,多个参数用数据进行存储 + Class[] types = getMethodParamTypes(obj, methodName); + //传入对应的方法名和方法的参数类型,得到得到方法 + Method method = obj.getClass().getMethod(methodName, types); + if (types[0].getName().contains("Integer")) { + method.invoke(obj, Integer.valueOf(value)); + } else if (types[0].getName().contains("Long")) { + method.invoke(obj, Long.valueOf(value)); + } else if (types[0].getName().contains("Double")) { + method.invoke(obj, Double.valueOf(value)); + } else if (types[0].getName().contains("Float")) { + method.invoke(obj, Float.valueOf(value)); + } else { + //执行方法 + method.invoke(obj, value); + } + } else { + Method method = obj.getClass().getDeclaredMethod(methodName, getMethodParamTypes(obj, methodName)); + method.invoke(obj, container.get(ref)); + } + + } + } + } + } + + /** + * setter注入初始化 + * + * @param xml + * @throws Exception + */ + public void initSetter(String xml) throws Exception { + //自己实现的Spring的IOC容器 + SAXBuilder builder = new SAXBuilder(); + InputStream stream = new FileInputStream(xml); + Document dom = builder.build(stream); + //获取根节点 + Element root = dom.getRootElement(); + //返回的是子节点的集合 + List children = root.getChildren(); + + + for (Element child : children) { + //如果不是bean标签则跳过 + if (!child.getName().equals("bean")) { + continue; + } + + //获取类 + String classPath = child.getAttributeValue("class"); + + //通过反射获取类 + Class clazz = Class.forName(classPath); + + //获取对象的唯一标识,用唯一标识为key,newInstance为value,存入map中 + String id = child.getAttributeValue("id"); + Object obj = clazz.newInstance(); + + + container.put(id, obj); + + //property标签对象的集合 + List attrList = child.getChildren(); + for (Element attr : attrList) { + //name="xxxx" + String filed = attr.getAttributeValue("name"); + //value="xxxx" + String value = attr.getAttributeValue("value"); + //ref="xxxx" + String ref = attr.getAttributeValue("ref"); + + + String methodName = "set" + filed.substring(0, 1).toUpperCase() + filed.substring(1); + + if (ref == null) { + //获取方法的传入的参数类型,多个参数用数据进行存储 + Class[] types = getMethodParamTypes(obj, methodName); + + //传入对应的方法名和方法的参数类型,得到得到方法 + Method method = obj.getClass().getMethod(methodName, types); + + if (types[0].getName().contains("Integer")) { + method.invoke(obj, Integer.valueOf(value)); + } else if (types[0].getName().contains("Long")) { + method.invoke(obj, Long.valueOf(value)); + } else if (types[0].getName().contains("Double")) { + method.invoke(obj, Double.valueOf(value)); + } else if (types[0].getName().contains("Float")) { + method.invoke(obj, Float.valueOf(value)); + } else { + //执行方法 + method.invoke(obj, value); + } + } else { + Method method = obj.getClass().getDeclaredMethod(methodName, getMethodParamTypes(obj, methodName)); + method.invoke(obj, container.get(ref)); + } + + } + + + } + + } + + /** + * 构造函数注入初始化 + * + * @param xml + * @throws Exception + */ + public void initConstr(String xml) throws Exception { + //自己实现的Spring的IOC容器 + SAXBuilder builder = new SAXBuilder(); + InputStream stream = new FileInputStream(xml); + Document dom = builder.build(stream); + //获取根节点 + Element root = dom.getRootElement(); + //返回的是子节点的集合 + List children = root.getChildren(); + + + for (Element child : children) { + if (!child.getName().equals("bean")) { + continue; + } + + //获取类 + String classPath = child.getAttributeValue("class"); + + //通过反射获取类 + Class clazz = Class.forName(classPath); + + + //property标签对象的集合 + List attrList = child.getChildren(); + + //构造函数的参数类型数组 + Class[] paramClass = new Class[attrList.size()]; + + //构造函数的参数值 + Object[] paramObj = new Object[attrList.size()]; + + //循环读取标签的数据constructor-arg的type和value + for (int i = 0; i < attrList.size(); i++) { + //type="xxxx" + String type = attrList.get(i).getAttributeValue("type"); + //value="xxxx" + String value = attrList.get(i).getAttributeValue("value"); + //ref="xxxx" + String ref = attrList.get(i).getAttributeValue("ref"); + + + if (ref == null) { + paramClass[i] = Class.forName(type); + if (null != type && type.equals("java.lang.Integer")) { + paramObj[i] = Integer.valueOf(value); + } else if (null != type && type.equals("java.lang.String")) { + paramObj[i] = String.valueOf(value); + } else if (null != type && type.equals("java.lang.Double")) { + paramObj[i] = Double.valueOf(value); + } else if (null != type && type.equals("java.lang.Float")) { + paramObj[i] = Float.valueOf(value); + } + } else { + paramClass[i] = container.get(ref).getClass(); + paramObj[i] = container.get(ref); + } + + } + + + //获取对象的唯一标识,用唯一标识为key,newInstance为value,存入map中 + String id = child.getAttributeValue("id"); + + Constructor constructor = clazz.getConstructor(paramClass); + Object obj = constructor.newInstance(paramObj); + + //添加到容器 + container.put(id, obj); + } + + } + + /** + * 根据id获取bean + * + * @param id + * @return + */ + public Object getBean(String id) { + return container.get(id); + } + + /** + * 根据方法名称取得反射方法的参数类型(没有考虑同名重载方法使用时注意) + * + * @param classInstance 类实例 + * @param methodName 方法名 + * @return + * @throws ClassNotFoundException + */ + private Class[] getMethodParamTypes(Object classInstance, String methodName) throws ClassNotFoundException { + Class[] paramTypes = null; + //全部方法 + Method[] methods = classInstance.getClass().getMethods(); + for (int i = 0; i < methods.length; i++) { + //和传入方法名匹配 + if (methodName.equals(methods[i].getName())) { + Class[] params = methods[i].getParameterTypes(); + paramTypes = new Class[params.length]; + for (int j = 0; j < params.length; j++) { + paramTypes[j] = Class.forName(params[j].getName()); + } + break; + } + } + return paramTypes; + } + + +} diff --git a/src/main/java/com/work08/test/AttributeTest.java b/src/main/java/com/work08/test/AttributeTest.java new file mode 100644 index 0000000000000000000000000000000000000000..71f7506e5bf2e70a8256d9e0e67c9d7fa44cd73a --- /dev/null +++ b/src/main/java/com/work08/test/AttributeTest.java @@ -0,0 +1,40 @@ +package com.work08.test; + +import com.work07.attribute.entity.Director; +import com.work07.attribute.entity.LuDeHua; +import com.work07.attribute.entity.MoAttack; +import com.work07.attribute.entity.Person; +import com.work08.reflex.MyClassPathXmlApplicationContext; + +/** + * @ClassName : attributeTest + * @Description : 自己实现的setter注入测试1 + * @Author : + * @Date: 2021-04-17 14:35 + */ +public class AttributeTest { + public static void main(String[] args) throws Exception { + + //MyClassPathXmlApplicationContext: 利用反射实现的ioc容器 + MyClassPathXmlApplicationContext context = new MyClassPathXmlApplicationContext(); + + //找到对应的xml文件 + context.init("./src/main/resources/springmvc.xml"); + + //获取容器里面的LuDeHua + LuDeHua luDeHua = (LuDeHua) context.getBean("attrLuDeHua"); + luDeHua.responseAsk("这是setter注入测试"); + + + //获取容器里面的MoAttack + MoAttack moAttack = (MoAttack) context.getBean("attrMoAttack"); + moAttack.cityGateAsk(); + + //获取容器里面的Director + Director director = (Director) context.getBean("attrDirector"); + director.directMovie(); + + + } + +} diff --git a/src/main/java/com/work08/test/ConstructionTest.java b/src/main/java/com/work08/test/ConstructionTest.java new file mode 100644 index 0000000000000000000000000000000000000000..9ef03d5c110625ed7675581605011a57e0f290a0 --- /dev/null +++ b/src/main/java/com/work08/test/ConstructionTest.java @@ -0,0 +1,35 @@ +package com.work08.test; + +import com.work07.construction.entity.Director; +import com.work07.construction.entity.LuDeHua; +import com.work07.construction.entity.MoAttack; +import com.work07.construction.entity.Person; +import com.work08.reflex.MyClassPathXmlApplicationContext; + +/** + * @ClassName : ConstructionTest + * @Description : 自己实现的构造方法注入 + * @Author : + * @Date: 2021-04-17 14:36 + */ +public class ConstructionTest { + public static void main(String[] args) throws Exception { + //MyClassPathXmlApplicationContext: 利用反射实现的ioc容器 + MyClassPathXmlApplicationContext context = new MyClassPathXmlApplicationContext(); + + //找到对应的xml文件 + context.init("./src/main/resources/springmvc.xml"); + + //获取容器里面的LuDeHua + LuDeHua luDeHua = (LuDeHua) context.getBean("constrLuDeHua"); + luDeHua.responseAsk("这是构造方法注入测试"); + + //获取容器里面的MoAttack + MoAttack moAttack = (MoAttack) context.getBean("constrMoAttack"); + moAttack.cityGateAsk(); + + //获取容器里面的Director + Director director = (Director) context.getBean("constrDirector"); + director.directMovie(); + } +} diff --git a/src/main/resources/applicationContext.xml b/src/main/resources/applicationContext.xml new file mode 100644 index 0000000000000000000000000000000000000000..55f6de7a67ec0fdae9b3dca3f323575ccb369a2f --- /dev/null +++ b/src/main/resources/applicationContext.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/springmvc.xml b/src/main/resources/springmvc.xml new file mode 100644 index 0000000000000000000000000000000000000000..a92c73c6d6e45afcbd1120ea7a0bf1d4cdd8a2ad --- /dev/null +++ b/src/main/resources/springmvc.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..acf20e308760ed861724eed4384eaf7d7fbc6d17 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,54 @@ + + + + Archetype Created Web Application + + + org.springframework.web.context.ContextLoaderListener + + + + contextConfigLocation + classpath:applicationContext.xml + + + + + + dispatcherServlet + org.springframework.web.servlet.DispatcherServlet + + + + + + contextConfigLocation + classpath:springmvc.xml + + + + 1 + + + dispatcherServlet + / + + + + + characterEncodingFilter + org.springframework.web.filter.CharacterEncodingFilter + + encoding + UTF-8 + + + + characterEncodingFilter + /* + + + + diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp new file mode 100644 index 0000000000000000000000000000000000000000..e7e80c70326b1b5665a8c12978ac441de5025bf8 --- /dev/null +++ b/src/main/webapp/index.jsp @@ -0,0 +1,23 @@ + <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %> + <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + love + + + + +
+ + +

+ Hello +

+ +
+ + + + diff --git a/src/main/webapp/login.jsp b/src/main/webapp/login.jsp new file mode 100644 index 0000000000000000000000000000000000000000..65c1be6c166526d8cdf327846a5948ecdc09ee94 --- /dev/null +++ b/src/main/webapp/login.jsp @@ -0,0 +1,32 @@ +<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + love + + + + + +
+
+
+ 用户名: + +
+
+ 密码: + +
+
+ +
+ +
+
+ + + + diff --git a/src/main/webapp/main.jsp b/src/main/webapp/main.jsp new file mode 100644 index 0000000000000000000000000000000000000000..20d7a86c645f60d3b827f214737222bd5d047cb4 --- /dev/null +++ b/src/main/webapp/main.jsp @@ -0,0 +1,21 @@ +<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + love + + + + +
+

+ 登录成功 +

+ +
+ + + + diff --git a/src/main/webapp/register.jsp b/src/main/webapp/register.jsp new file mode 100644 index 0000000000000000000000000000000000000000..c9b00250fac28a87ef415b2473f07ce245dccc07 --- /dev/null +++ b/src/main/webapp/register.jsp @@ -0,0 +1,22 @@ +<%-- + Created by IntelliJ IDEA. + User: + Date: 2021/5/20 + Time: 19:21 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 注册 + + +
+ +
+ +
+ +
+ + diff --git a/src/test/com/service/UserServiceTest.java b/src/test/com/service/UserServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..5a9ed72e7e1cbf4e6809dec1a49a2bbd9b62689e --- /dev/null +++ b/src/test/com/service/UserServiceTest.java @@ -0,0 +1,27 @@ +package com.service; + +import com.dao.UserDao; +import com.domain.User; +import org.junit.Test; + +/** + * @ClassName : UserServiceTest + * @Description : 测试层 + * @Author : YUHAIyuan + * @Date: 2021-3-20 09:50 + */ +public class UserServiceTest { + +// @Test +// public void select(){ +// UserDao userDao = new UserDao(); +// User user = new User(); +// user.setUsername("admin"); +// user.setPassword("admin"); +// +// User select = userDao.select(user); +// System.out.println("select = " + select); +// +// } + +} diff --git a/target/classes/com/controller/UserController.class b/target/classes/com/controller/UserController.class new file mode 100644 index 0000000000000000000000000000000000000000..604b6a712dddc790c33298cfed9ba914938191ec Binary files /dev/null and b/target/classes/com/controller/UserController.class differ diff --git a/target/classes/com/dao/UserDao.class b/target/classes/com/dao/UserDao.class new file mode 100644 index 0000000000000000000000000000000000000000..26880b0c053d98c83010c0d0bbe612f0cbc983e3 Binary files /dev/null and b/target/classes/com/dao/UserDao.class differ diff --git a/target/classes/com/domain/User.class b/target/classes/com/domain/User.class new file mode 100644 index 0000000000000000000000000000000000000000..82b311bb20f2d0625267185fc293a3d535a168f4 Binary files /dev/null and b/target/classes/com/domain/User.class differ diff --git a/target/classes/com/service/UserService.class b/target/classes/com/service/UserService.class new file mode 100644 index 0000000000000000000000000000000000000000..ee1e9e9f585153978b5fb96af0c4abed3abe0d11 Binary files /dev/null and b/target/classes/com/service/UserService.class differ diff --git a/target/classes/com/utils/JDBCUtils.class b/target/classes/com/utils/JDBCUtils.class new file mode 100644 index 0000000000000000000000000000000000000000..71b156d8d489b405543548cc150e6487b848a545 Binary files /dev/null and b/target/classes/com/utils/JDBCUtils.class differ diff --git a/target/classes/springmvc.xml b/target/classes/springmvc.xml new file mode 100644 index 0000000000000000000000000000000000000000..a92c73c6d6e45afcbd1120ea7a0bf1d4cdd8a2ad --- /dev/null +++ b/target/classes/springmvc.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/login3/META-INF/MANIFEST.MF b/target/login3/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..df1a10d0d673af8aa66aeacd9e23bba99bc7d30c --- /dev/null +++ b/target/login3/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Created-By: IntelliJ IDEA +Built-By: 86136 +Build-Jdk: version 1.8.0_161 + diff --git a/target/login3/WEB-INF/classes/com/controller/UserController.class b/target/login3/WEB-INF/classes/com/controller/UserController.class new file mode 100644 index 0000000000000000000000000000000000000000..604b6a712dddc790c33298cfed9ba914938191ec Binary files /dev/null and b/target/login3/WEB-INF/classes/com/controller/UserController.class differ diff --git a/target/login3/WEB-INF/classes/com/dao/UserDao.class b/target/login3/WEB-INF/classes/com/dao/UserDao.class new file mode 100644 index 0000000000000000000000000000000000000000..26880b0c053d98c83010c0d0bbe612f0cbc983e3 Binary files /dev/null and b/target/login3/WEB-INF/classes/com/dao/UserDao.class differ diff --git a/target/login3/WEB-INF/classes/com/domain/User.class b/target/login3/WEB-INF/classes/com/domain/User.class new file mode 100644 index 0000000000000000000000000000000000000000..82b311bb20f2d0625267185fc293a3d535a168f4 Binary files /dev/null and b/target/login3/WEB-INF/classes/com/domain/User.class differ diff --git a/target/login3/WEB-INF/classes/com/service/UserService.class b/target/login3/WEB-INF/classes/com/service/UserService.class new file mode 100644 index 0000000000000000000000000000000000000000..ee1e9e9f585153978b5fb96af0c4abed3abe0d11 Binary files /dev/null and b/target/login3/WEB-INF/classes/com/service/UserService.class differ diff --git a/target/login3/WEB-INF/classes/com/utils/JDBCUtils.class b/target/login3/WEB-INF/classes/com/utils/JDBCUtils.class new file mode 100644 index 0000000000000000000000000000000000000000..71b156d8d489b405543548cc150e6487b848a545 Binary files /dev/null and b/target/login3/WEB-INF/classes/com/utils/JDBCUtils.class differ diff --git a/target/login3/WEB-INF/classes/springmvc.xml b/target/login3/WEB-INF/classes/springmvc.xml new file mode 100644 index 0000000000000000000000000000000000000000..a92c73c6d6e45afcbd1120ea7a0bf1d4cdd8a2ad --- /dev/null +++ b/target/login3/WEB-INF/classes/springmvc.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/login3/WEB-INF/lib/javax.servlet-api-3.1.0.jar b/target/login3/WEB-INF/lib/javax.servlet-api-3.1.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..6b14c3d267867e76c04948bb31b3de18e01412ee Binary files /dev/null and b/target/login3/WEB-INF/lib/javax.servlet-api-3.1.0.jar differ diff --git a/target/login3/WEB-INF/lib/javax.servlet.jsp-api-2.3.1.jar b/target/login3/WEB-INF/lib/javax.servlet.jsp-api-2.3.1.jar new file mode 100644 index 0000000000000000000000000000000000000000..74516209429e42af347ec5d00f3e282549ba5e1d Binary files /dev/null and b/target/login3/WEB-INF/lib/javax.servlet.jsp-api-2.3.1.jar differ diff --git a/target/login3/WEB-INF/lib/jstl-1.2.jar b/target/login3/WEB-INF/lib/jstl-1.2.jar new file mode 100644 index 0000000000000000000000000000000000000000..0fd275e94660402f80f01505d28b90a23f7e0209 Binary files /dev/null and b/target/login3/WEB-INF/lib/jstl-1.2.jar differ diff --git a/target/login3/WEB-INF/lib/mysql-connector-java-8.0.22.jar b/target/login3/WEB-INF/lib/mysql-connector-java-8.0.22.jar new file mode 100644 index 0000000000000000000000000000000000000000..412d81faa52ff19c78ccf9b5577e600569a47844 Binary files /dev/null and b/target/login3/WEB-INF/lib/mysql-connector-java-8.0.22.jar differ diff --git a/target/login3/WEB-INF/lib/protobuf-java-3.11.4.jar b/target/login3/WEB-INF/lib/protobuf-java-3.11.4.jar new file mode 100644 index 0000000000000000000000000000000000000000..7224d23dfd2702ff1f4479ed9243124f9924acb4 Binary files /dev/null and b/target/login3/WEB-INF/lib/protobuf-java-3.11.4.jar differ diff --git a/target/login3/WEB-INF/lib/spring-aop-5.2.5.RELEASE.jar b/target/login3/WEB-INF/lib/spring-aop-5.2.5.RELEASE.jar new file mode 100644 index 0000000000000000000000000000000000000000..1525f8f1ab459cb88613429f5ffbf23592a73c1f Binary files /dev/null and b/target/login3/WEB-INF/lib/spring-aop-5.2.5.RELEASE.jar differ diff --git a/target/login3/WEB-INF/lib/spring-beans-5.2.5.RELEASE.jar b/target/login3/WEB-INF/lib/spring-beans-5.2.5.RELEASE.jar new file mode 100644 index 0000000000000000000000000000000000000000..8fb3d89bc89b85d2da383c5706a166bea08f36a2 Binary files /dev/null and b/target/login3/WEB-INF/lib/spring-beans-5.2.5.RELEASE.jar differ diff --git a/target/login3/WEB-INF/lib/spring-context-5.2.5.RELEASE.jar b/target/login3/WEB-INF/lib/spring-context-5.2.5.RELEASE.jar new file mode 100644 index 0000000000000000000000000000000000000000..20d310ec45c892ae22f13e4bdca43c223ea1ac4f Binary files /dev/null and b/target/login3/WEB-INF/lib/spring-context-5.2.5.RELEASE.jar differ diff --git a/target/login3/WEB-INF/lib/spring-core-5.2.5.RELEASE.jar b/target/login3/WEB-INF/lib/spring-core-5.2.5.RELEASE.jar new file mode 100644 index 0000000000000000000000000000000000000000..ceec826d7b0a6b4b6374f6b06cb8ab505bf66579 Binary files /dev/null and b/target/login3/WEB-INF/lib/spring-core-5.2.5.RELEASE.jar differ diff --git a/target/login3/WEB-INF/lib/spring-expression-5.2.5.RELEASE.jar b/target/login3/WEB-INF/lib/spring-expression-5.2.5.RELEASE.jar new file mode 100644 index 0000000000000000000000000000000000000000..41b113740168674969de11462caccf50ff4d7019 Binary files /dev/null and b/target/login3/WEB-INF/lib/spring-expression-5.2.5.RELEASE.jar differ diff --git a/target/login3/WEB-INF/lib/spring-jcl-5.2.5.RELEASE.jar b/target/login3/WEB-INF/lib/spring-jcl-5.2.5.RELEASE.jar new file mode 100644 index 0000000000000000000000000000000000000000..0db2821edfe93c225795026f34a2c1c4c44b6cc6 Binary files /dev/null and b/target/login3/WEB-INF/lib/spring-jcl-5.2.5.RELEASE.jar differ diff --git a/target/login3/WEB-INF/lib/spring-web-5.2.5.RELEASE.jar b/target/login3/WEB-INF/lib/spring-web-5.2.5.RELEASE.jar new file mode 100644 index 0000000000000000000000000000000000000000..50cf9fbdf34e7b978380ab0e0fe83e8d913ae95b Binary files /dev/null and b/target/login3/WEB-INF/lib/spring-web-5.2.5.RELEASE.jar differ diff --git a/target/login3/WEB-INF/lib/spring-webmvc-5.2.5.RELEASE.jar b/target/login3/WEB-INF/lib/spring-webmvc-5.2.5.RELEASE.jar new file mode 100644 index 0000000000000000000000000000000000000000..2b9c233bb277a754246a21ea603bfe3d7e566dc4 Binary files /dev/null and b/target/login3/WEB-INF/lib/spring-webmvc-5.2.5.RELEASE.jar differ diff --git a/target/login3/WEB-INF/web.xml b/target/login3/WEB-INF/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..acf20e308760ed861724eed4384eaf7d7fbc6d17 --- /dev/null +++ b/target/login3/WEB-INF/web.xml @@ -0,0 +1,54 @@ + + + + Archetype Created Web Application + + + org.springframework.web.context.ContextLoaderListener + + + + contextConfigLocation + classpath:applicationContext.xml + + + + + + dispatcherServlet + org.springframework.web.servlet.DispatcherServlet + + + + + + contextConfigLocation + classpath:springmvc.xml + + + + 1 + + + dispatcherServlet + / + + + + + characterEncodingFilter + org.springframework.web.filter.CharacterEncodingFilter + + encoding + UTF-8 + + + + characterEncodingFilter + /* + + + + diff --git a/target/login3/index.jsp b/target/login3/index.jsp new file mode 100644 index 0000000000000000000000000000000000000000..e7e80c70326b1b5665a8c12978ac441de5025bf8 --- /dev/null +++ b/target/login3/index.jsp @@ -0,0 +1,23 @@ + <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %> + <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + love + + + + +
+ + +

+ Hello +

+ +
+ + + + diff --git a/target/login3/login.jsp b/target/login3/login.jsp new file mode 100644 index 0000000000000000000000000000000000000000..65c1be6c166526d8cdf327846a5948ecdc09ee94 --- /dev/null +++ b/target/login3/login.jsp @@ -0,0 +1,32 @@ +<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + love + + + + + +
+
+
+ 用户名: + +
+
+ 密码: + +
+
+ +
+ +
+
+ + + + diff --git a/target/login3/main.jsp b/target/login3/main.jsp new file mode 100644 index 0000000000000000000000000000000000000000..20d7a86c645f60d3b827f214737222bd5d047cb4 --- /dev/null +++ b/target/login3/main.jsp @@ -0,0 +1,21 @@ +<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + love + + + + +
+

+ 登录成功 +

+ +
+ + + + diff --git a/target/test-classes/com/service/UserServiceTest.class b/target/test-classes/com/service/UserServiceTest.class new file mode 100644 index 0000000000000000000000000000000000000000..f935014f3c21823d5bde6229af958a91242778f8 Binary files /dev/null and b/target/test-classes/com/service/UserServiceTest.class differ