diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 137069b..0000000 --- a/LICENSE +++ /dev/null @@ -1,73 +0,0 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. - -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: - - (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. - - You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - -To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/README.md b/README.md deleted file mode 100644 index ca0f502..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# test_Res - -所有练习 \ No newline at end of file diff --git a/mybatis_all/.idea/compiler.xml b/mybatis_all/.idea/compiler.xml index df268c2..15d0deb 100644 --- a/mybatis_all/.idea/compiler.xml +++ b/mybatis_all/.idea/compiler.xml @@ -8,10 +8,12 @@ + + \ No newline at end of file diff --git a/mybatis_all/.idea/encodings.xml b/mybatis_all/.idea/encodings.xml index c2bae49..6390bd5 100644 --- a/mybatis_all/.idea/encodings.xml +++ b/mybatis_all/.idea/encodings.xml @@ -1,6 +1,7 @@ + \ No newline at end of file diff --git a/mybatis_all/.idea/libraries/Maven__log4j_log4j_1_2_16.xml b/mybatis_all/.idea/libraries/Maven__log4j_log4j_1_2_16.xml new file mode 100644 index 0000000..056b664 --- /dev/null +++ b/mybatis_all/.idea/libraries/Maven__log4j_log4j_1_2_16.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis_all/.idea/libraries/Maven__org_slf4j_slf4j_api_1_6_1.xml b/mybatis_all/.idea/libraries/Maven__org_slf4j_slf4j_api_1_6_1.xml new file mode 100644 index 0000000..fb6127c --- /dev/null +++ b/mybatis_all/.idea/libraries/Maven__org_slf4j_slf4j_api_1_6_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis_all/.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_6_1.xml b/mybatis_all/.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_6_1.xml new file mode 100644 index 0000000..1cc6743 --- /dev/null +++ b/mybatis_all/.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_6_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis_all/.idea/misc.xml b/mybatis_all/.idea/misc.xml index 2340d62..c5c73fd 100644 --- a/mybatis_all/.idea/misc.xml +++ b/mybatis_all/.idea/misc.xml @@ -7,6 +7,7 @@ diff --git a/mybatis_all/.idea/modules.xml b/mybatis_all/.idea/modules.xml index 0fad2be..0ec370b 100644 --- a/mybatis_all/.idea/modules.xml +++ b/mybatis_all/.idea/modules.xml @@ -4,6 +4,7 @@ + \ No newline at end of file diff --git a/mybatis_all/.idea/vcs.xml b/mybatis_all/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/mybatis_all/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/mybatis_all/mybatisTest01/log/test.log b/mybatis_all/mybatisTest01/log/test.log deleted file mode 100644 index 35a445f..0000000 Binary files a/mybatis_all/mybatisTest01/log/test.log and /dev/null differ diff --git a/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/DeptMapper.java b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/DeptMapper.java index 8beba43..61b31b8 100644 --- a/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/DeptMapper.java +++ b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/DeptMapper.java @@ -10,5 +10,5 @@ import java.util.List; * @Version 1.0 */ public interface DeptMapper { - List findEmpByDeptnoAndSal(Integer deptno, Double sal); + List findEmpByDeptnoAndSal(Integer deptno,Double sal); } diff --git a/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/EmpMapper2.java b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/EmpMapper2.java index 2739125..cb61a60 100644 --- a/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/EmpMapper2.java +++ b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/EmpMapper2.java @@ -1,9 +1,20 @@ package com.zhangzeyuan.mapper; +import com.zhangzeyuan.pojo.Emp; + +import java.util.List; + /** * @Author ZZY_1 * @Date 2023/12/27 23:15 * @Version 1.0 */ public interface EmpMapper2 { + List findByCondition(Emp emp); + + List findByCondition2(Emp emp); + int updateEmpByCondtion(Emp emp); + int updateEmpByCondtion2(Emp emp); + List findByEname(String ename); + List findByEmpnoList(List empnos ); } diff --git a/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/EmpMapper3.java b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/EmpMapper3.java new file mode 100644 index 0000000..fd799cd --- /dev/null +++ b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/EmpMapper3.java @@ -0,0 +1,18 @@ +package com.zhangzeyuan.mapper; + +import com.zhangzeyuan.pojo.Dept; +import com.zhangzeyuan.pojo.Emp; + +import java.util.List; + +/** + * @Author ZZY_1 + * @Date 2023/12/28 22:58 + * @Version 1.0 + */ +public interface EmpMapper3 { + List listAll(); + List listOneAndMore(); + List findEmpsByDeptno(int deptno); + Dept findDeptByDeptno(int deptno); +} diff --git a/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/ProjectMapper.java b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/ProjectMapper.java new file mode 100644 index 0000000..d4e27eb --- /dev/null +++ b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/mapper/ProjectMapper.java @@ -0,0 +1,16 @@ +package com.zhangzeyuan.mapper; + +import com.zhangzeyuan.pojo.Dept; +import com.zhangzeyuan.pojo.Project; + +import java.util.List; + +/** + * @Author ZZY_1 + * @Date 2023/12/28 23:40 + * @Version 1.0 + */ +public interface ProjectMapper { + + List listMoreAndMore(int pid); +} diff --git a/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/Dept.java b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/Dept.java index 7e3e7e7..3c76ce7 100644 --- a/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/Dept.java +++ b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/Dept.java @@ -4,6 +4,9 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import java.io.Serializable; +import java.util.List; + /** * @Author ZZY_1 * @Date 2023/12/26 22:14 @@ -12,8 +15,14 @@ import lombok.NoArgsConstructor; @Data @NoArgsConstructor @AllArgsConstructor -public class Dept { +public class Dept implements Serializable { private Integer deptno; private String dname; private String loc; + private List emps; + public Dept(Integer deptno, String dname, String loc) { + this.deptno = deptno; + this.dname = dname; + this.loc = loc; + } } diff --git a/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/Emp.java b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/Emp.java index 0784db2..6a05b10 100644 --- a/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/Emp.java +++ b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/Emp.java @@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import java.io.Serializable; import java.util.Date; /** @@ -14,7 +15,7 @@ import java.util.Date; @Data @NoArgsConstructor @AllArgsConstructor -public class Emp { +public class Emp implements Serializable { private Integer empno ; private String ename ; private String job ; @@ -23,5 +24,16 @@ public class Emp { private Double sal ; private Double comm ; private Integer deptno ; + private Dept dept; + public Emp(Integer empno, String ename, String job, Integer mgr, Date hiredate, Double sal, Double comm, Integer deptno) { + this.empno = empno; + this.ename = ename; + this.job = job; + this.mgr = mgr; + this.hiredate = hiredate; + this.sal = sal; + this.comm = comm; + this.deptno = deptno; + } } diff --git a/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/Project.java b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/Project.java new file mode 100644 index 0000000..c361913 --- /dev/null +++ b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/Project.java @@ -0,0 +1,23 @@ +package com.zhangzeyuan.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + +/** + * @Author ZZY_1 + * @Date 2023/12/28 23:36 + * @Version 1.0 + */ +@NoArgsConstructor +@AllArgsConstructor +@Data +public class Project implements Serializable { + private Integer pid; + private String pname; + private Integer money; + private List recordList; +} diff --git a/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/ProjectRecord.java b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/ProjectRecord.java new file mode 100644 index 0000000..c05f668 --- /dev/null +++ b/mybatis_all/mybatisTest01/src/main/java/com/zhangzeyuan/pojo/ProjectRecord.java @@ -0,0 +1,21 @@ +package com.zhangzeyuan.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @Author ZZY_1 + * @Date 2023/12/28 23:34 + * @Version 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ProjectRecord implements Serializable { + private Integer empno; + private Integer pid; + private Emp emp; +} diff --git a/mybatis_all/mybatisTest01/src/main/resources/com/zhangzeyuan/mapper/EmpMapper2.xml b/mybatis_all/mybatisTest01/src/main/resources/com/zhangzeyuan/mapper/EmpMapper2.xml new file mode 100644 index 0000000..d7646e6 --- /dev/null +++ b/mybatis_all/mybatisTest01/src/main/resources/com/zhangzeyuan/mapper/EmpMapper2.xml @@ -0,0 +1,125 @@ + + + + + emp.EMPNO, + emp.ENAME, + emp.JOB, + emp.MGR, + emp.HIREDATE, + emp.SAL, + emp.COMM, + emp.DEPTNO + + + + update emp + + + , EMPNO =#{empno} + + + , ENAME =#{ename} + + + , job =#{job} + + + , MGR =#{mgr} + + + , HIREDATE =#{hiredate} + + + , SAL =#{sal} + + + , COMM =#{comm} + + + where empno =#{empno}; + + + + update emp + + + , EMPNO =#{empno} + + + , ENAME =#{ename} + + + , job =#{job} + + + , MGR =#{mgr} + + + , HIREDATE =#{hiredate} + + + , SAL =#{sal} + + + , COMM =#{comm} + + + where empno =#{empno}; + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis_all/mybatisTest01/src/main/resources/com/zhangzeyuan/mapper/EmpMapper3.xml b/mybatis_all/mybatisTest01/src/main/resources/com/zhangzeyuan/mapper/EmpMapper3.xml new file mode 100644 index 0000000..06c7b9c --- /dev/null +++ b/mybatis_all/mybatisTest01/src/main/resources/com/zhangzeyuan/mapper/EmpMapper3.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis_all/mybatisTest01/src/main/resources/com/zhangzeyuan/mapper/ProjectMapper.xml b/mybatis_all/mybatisTest01/src/main/resources/com/zhangzeyuan/mapper/ProjectMapper.xml new file mode 100644 index 0000000..0d03a0b --- /dev/null +++ b/mybatis_all/mybatisTest01/src/main/resources/com/zhangzeyuan/mapper/ProjectMapper.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis_all/mybatisTest01/src/main/resources/log4j2.xml b/mybatis_all/mybatisTest01/src/main/resources/log4j2.xml index 322503c..850024a 100644 --- a/mybatis_all/mybatisTest01/src/main/resources/log4j2.xml +++ b/mybatis_all/mybatisTest01/src/main/resources/log4j2.xml @@ -1,5 +1,5 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/mybatis_all/mybatisTest01/src/main/resources/sqlMapConfig.xml b/mybatis_all/mybatisTest01/src/main/resources/sqlMapConfig.xml index b7d63df..78cffd2 100644 --- a/mybatis_all/mybatisTest01/src/main/resources/sqlMapConfig.xml +++ b/mybatis_all/mybatisTest01/src/main/resources/sqlMapConfig.xml @@ -7,6 +7,11 @@ + + + + + diff --git a/mybatis_all/mybatisTest01/src/test/java/com/zhangzeyuan/test/TestEmpDynamicSelect.java b/mybatis_all/mybatisTest01/src/test/java/com/zhangzeyuan/test/TestEmpDynamicSelect.java new file mode 100644 index 0000000..ada130e --- /dev/null +++ b/mybatis_all/mybatisTest01/src/test/java/com/zhangzeyuan/test/TestEmpDynamicSelect.java @@ -0,0 +1,99 @@ +package com.zhangzeyuan.test; + +import com.zhangzeyuan.mapper.EmpCurdMapper; +import com.zhangzeyuan.mapper.EmpMapper2; +import com.zhangzeyuan.pojo.Emp; +import org.apache.ibatis.io.Resources; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.SqlSessionFactoryBuilder; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * @Author ZZY_1 + * @Date 2023/12/26 22:16 + * @Version 1.0 + */ +public class TestEmpDynamicSelect { + SqlSession sqlSession ; + //在之前运行 + @Before + public void init() { + SqlSessionFactoryBuilder ssfb = new SqlSessionFactoryBuilder(); + InputStream resourceAsStream = null; + try { + resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml"); + } catch (IOException e) { + e.printStackTrace(); + } + SqlSessionFactory factory = ssfb.build(resourceAsStream); + sqlSession = factory.openSession(); + + } + + @Test + public void dynamic() throws ParseException { + EmpMapper2 mapper = sqlSession.getMapper(EmpMapper2.class); + Date parse = new SimpleDateFormat("yyyy-MM-dd").parse("2023-12-27"); + Emp emp =new Emp(null,"按住啦Baby","SALESMAN",7839,parse,3100.0, 200.0,10 ); + // List emps = mapper.findByCondition( emp); + List emps = mapper.findByCondition2( emp); + sqlSession.commit(); + System.out.println(emps); + + } + + @Test + public void testSetTrim() throws ParseException { + EmpMapper2 mapper = sqlSession.getMapper(EmpMapper2.class); + // Date parse = new SimpleDateFormat("yyyy-MM-dd").parse("2023-12-27"); + Emp emp =new Emp( ); + emp.setEmpno(2); + emp.setEname("小凤仙"); + emp.setJob("CLERK"); + // List emps = mapper.findByCondition( emp); + int i= mapper.updateEmpByCondtion2( emp); + sqlSession.commit(); + System.out.println(i); + + } + + @Test + public void testBind() throws ParseException { + EmpMapper2 mapper = sqlSession.getMapper(EmpMapper2.class); + // Date parse = new SimpleDateFormat("yyyy-MM-dd").parse("2023-12-27"); + // List emps = mapper.findByCondition( emp); + List emps= mapper.findByEname( "凤仙"); + sqlSession.commit(); + System.out.println(emps); + + } + @Test + public void testForeach() throws ParseException { + EmpMapper2 mapper = sqlSession.getMapper(EmpMapper2.class); + // Date parse = new SimpleDateFormat("yyyy-MM-dd").parse("2023-12-27"); + // List emps = mapper.findByCondition( emp); + ArrayList integers = new ArrayList(); + integers.add(1); + integers.add(2); + integers.add(3); + integers.add(4); + List emps= mapper.findByEmpnoList(integers); + sqlSession.commit(); + System.out.println(emps); + + } + @After + public void close() { + sqlSession.close(); + + } +} diff --git a/mybatis_all/mybatisTest01/src/test/java/com/zhangzeyuan/test/TestEmpMapper3.java b/mybatis_all/mybatisTest01/src/test/java/com/zhangzeyuan/test/TestEmpMapper3.java new file mode 100644 index 0000000..05713a9 --- /dev/null +++ b/mybatis_all/mybatisTest01/src/test/java/com/zhangzeyuan/test/TestEmpMapper3.java @@ -0,0 +1,98 @@ +package com.zhangzeyuan.test; + +import com.zhangzeyuan.mapper.DeptMapper; +import com.zhangzeyuan.mapper.EmpMapper3; +import com.zhangzeyuan.pojo.Dept; +import com.zhangzeyuan.pojo.Emp; +import org.apache.ibatis.io.Resources; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.SqlSessionFactoryBuilder; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @Author ZZY_1 + * @Date 2023/12/26 22:16 + * @Version 1.0 + * + * 测试一对一,一对多,多对多 + */ +public class TestEmpMapper3 { + SqlSession sqlSession ; + //在之前运行 + @Before + public void init() { + SqlSessionFactoryBuilder ssfb = new SqlSessionFactoryBuilder(); + InputStream resourceAsStream = null; + try { + resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml"); + } catch (IOException e) { + e.printStackTrace(); + } + SqlSessionFactory factory = ssfb.build(resourceAsStream); + sqlSession = factory.openSession(); + + } + + @Test + public void findAll() { + EmpMapper3 mapper = sqlSession.getMapper(EmpMapper3.class); + List emps = mapper.listAll(); + sqlSession.commit(); + emps.forEach(emp -> { + System.out.println(emp); + }); + + } + + + @Test + public void findOneAndMore() { + EmpMapper3 mapper = sqlSession.getMapper(EmpMapper3.class); + List emps = mapper.listOneAndMore(); + sqlSession.commit(); + emps.forEach(dept -> { + System.out.println(dept); + }); + + + + } + + /** + * 测试级联查询 + */ + @Test + public void testJoinSelect() { + EmpMapper3 mapper = sqlSession.getMapper(EmpMapper3.class); + Dept deptByDeptno = mapper.findDeptByDeptno(30); + /* System.out.println(deptByDeptno.getDeptno()); + System.out.println(deptByDeptno.getDname()); + System.out.println(deptByDeptno.getLoc());*/ + // System.out.println(deptByDeptno); + //lazy延迟加载只有在有get的情况下才会查询 + //sqlSession.commit(); + // System.out.println(deptByDeptno.getEmps()); + } + @Test + public void testArgs() { + } + //测试对象作为参数 + @Test + public void testObjArgs() { + } + @After + public void close() { + sqlSession.close(); + + } +} diff --git a/mybatis_all/mybatisTest01/src/test/java/com/zhangzeyuan/test/TestProjectMapper.java b/mybatis_all/mybatisTest01/src/test/java/com/zhangzeyuan/test/TestProjectMapper.java new file mode 100644 index 0000000..2fe59c1 --- /dev/null +++ b/mybatis_all/mybatisTest01/src/test/java/com/zhangzeyuan/test/TestProjectMapper.java @@ -0,0 +1,86 @@ +package com.zhangzeyuan.test; + +import com.zhangzeyuan.mapper.EmpMapper3; +import com.zhangzeyuan.mapper.ProjectMapper; +import com.zhangzeyuan.pojo.Dept; +import com.zhangzeyuan.pojo.Emp; +import com.zhangzeyuan.pojo.Project; +import org.apache.ibatis.io.Resources; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.SqlSessionFactoryBuilder; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +/** + * @Author ZZY_1 + * @Date 2023/12/26 22:16 + * @Version 1.0 + * + * 测试一对一,一对多,多对多 + */ +public class TestProjectMapper { + SqlSession sqlSession ; + //在之前运行 + @Before + public void init() { + SqlSessionFactoryBuilder ssfb = new SqlSessionFactoryBuilder(); + InputStream resourceAsStream = null; + try { + resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml"); + } catch (IOException e) { + e.printStackTrace(); + } + SqlSessionFactory factory = ssfb.build(resourceAsStream); + sqlSession = factory.openSession(); + + } + + @Test + public void findAll() { + ProjectMapper mapper = sqlSession.getMapper(ProjectMapper.class); + List projects = mapper.listMoreAndMore(1); + //sqlSession.commit(); + for (Project project : projects) { + System.out.println(project); + } + } + + + + @Test + public void findOneAndMore() { + + + } + + /** + * mybatis参数传递的三种方式 + * 1 单个基础数据类型作为参数 + * 2 多个基础数据类型的map 集合作为参数 + * 3 引用类型作为参数 + */ + @Test + public void testSingleArg() { + } + @Test + public void testMapArgs() { + } + @Test + public void testArgs() { + } + //测试对象作为参数 + @Test + public void testObjArgs() { + } + @After + public void close() { + sqlSession.close(); + + } +} diff --git a/mybatis_all/mybatisTest01/target/classes/META-INF/mybatisTest01.kotlin_module b/mybatis_all/mybatisTest01/target/classes/META-INF/mybatisTest01.kotlin_module deleted file mode 100644 index a49347a..0000000 Binary files a/mybatis_all/mybatisTest01/target/classes/META-INF/mybatisTest01.kotlin_module and /dev/null differ diff --git a/mybatis_all/mybatisTest01/target/classes/com/zhangzeyuan/pojo/Dept.class b/mybatis_all/mybatisTest01/target/classes/com/zhangzeyuan/pojo/Dept.class index a079b6d..e878104 100644 Binary files a/mybatis_all/mybatisTest01/target/classes/com/zhangzeyuan/pojo/Dept.class and b/mybatis_all/mybatisTest01/target/classes/com/zhangzeyuan/pojo/Dept.class differ diff --git a/mybatis_all/mybatisTest01/target/classes/com/zhangzeyuan/pojo/Emp.class b/mybatis_all/mybatisTest01/target/classes/com/zhangzeyuan/pojo/Emp.class index e7c688d..c4b6d30 100644 Binary files a/mybatis_all/mybatisTest01/target/classes/com/zhangzeyuan/pojo/Emp.class and b/mybatis_all/mybatisTest01/target/classes/com/zhangzeyuan/pojo/Emp.class differ diff --git a/mybatis_all/mybatisTest01/target/classes/log4j2.xml b/mybatis_all/mybatisTest01/target/classes/log4j2.xml index 322503c..850024a 100644 --- a/mybatis_all/mybatisTest01/target/classes/log4j2.xml +++ b/mybatis_all/mybatisTest01/target/classes/log4j2.xml @@ -1,5 +1,5 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/mybatis_all/mybatisTest01/target/classes/sqlMapConfig.xml b/mybatis_all/mybatisTest01/target/classes/sqlMapConfig.xml index b7d63df..78cffd2 100644 --- a/mybatis_all/mybatisTest01/target/classes/sqlMapConfig.xml +++ b/mybatis_all/mybatisTest01/target/classes/sqlMapConfig.xml @@ -7,6 +7,11 @@ + + + + + diff --git a/mybatis_all/mybatisTest01/target/test-classes/META-INF/mybatisTest01.kotlin_module b/mybatis_all/mybatisTest01/target/test-classes/META-INF/mybatisTest01.kotlin_module deleted file mode 100644 index a49347a..0000000 Binary files a/mybatis_all/mybatisTest01/target/test-classes/META-INF/mybatisTest01.kotlin_module and /dev/null differ diff --git a/mybatis_all/reverse/.idea/.gitignore b/mybatis_all/reverse/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/mybatis_all/reverse/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/mybatis_all/reverse/.idea/libraries/Maven__com_google_protobuf_protobuf_java_3_11_4.xml b/mybatis_all/reverse/.idea/libraries/Maven__com_google_protobuf_protobuf_java_3_11_4.xml new file mode 100644 index 0000000..cf24073 --- /dev/null +++ b/mybatis_all/reverse/.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/mybatis_all/reverse/.idea/libraries/Maven__log4j_log4j_1_2_16.xml b/mybatis_all/reverse/.idea/libraries/Maven__log4j_log4j_1_2_16.xml new file mode 100644 index 0000000..056b664 --- /dev/null +++ b/mybatis_all/reverse/.idea/libraries/Maven__log4j_log4j_1_2_16.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis_all/reverse/.idea/libraries/Maven__mysql_mysql_connector_java_8_0_28.xml b/mybatis_all/reverse/.idea/libraries/Maven__mysql_mysql_connector_java_8_0_28.xml new file mode 100644 index 0000000..b427b86 --- /dev/null +++ b/mybatis_all/reverse/.idea/libraries/Maven__mysql_mysql_connector_java_8_0_28.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis_all/reverse/.idea/libraries/Maven__org_mybatis_generator_mybatis_generator_core_1_3_5.xml b/mybatis_all/reverse/.idea/libraries/Maven__org_mybatis_generator_mybatis_generator_core_1_3_5.xml new file mode 100644 index 0000000..7c572d4 --- /dev/null +++ b/mybatis_all/reverse/.idea/libraries/Maven__org_mybatis_generator_mybatis_generator_core_1_3_5.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis_all/reverse/.idea/libraries/Maven__org_slf4j_slf4j_api_1_6_1.xml b/mybatis_all/reverse/.idea/libraries/Maven__org_slf4j_slf4j_api_1_6_1.xml new file mode 100644 index 0000000..fb6127c --- /dev/null +++ b/mybatis_all/reverse/.idea/libraries/Maven__org_slf4j_slf4j_api_1_6_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis_all/reverse/.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_6_1.xml b/mybatis_all/reverse/.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_6_1.xml new file mode 100644 index 0000000..1cc6743 --- /dev/null +++ b/mybatis_all/reverse/.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_6_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis_all/reverse/.idea/modules.xml b/mybatis_all/reverse/.idea/modules.xml new file mode 100644 index 0000000..f07066d --- /dev/null +++ b/mybatis_all/reverse/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/mybatis_all/reverse/.idea/vcs.xml b/mybatis_all/reverse/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/mybatis_all/reverse/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/mybatis_all/reverse/pom.xml b/mybatis_all/reverse/pom.xml new file mode 100644 index 0000000..8811aa0 --- /dev/null +++ b/mybatis_all/reverse/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + org.zhangzeyuan + reverse + 1.0-SNAPSHOT + + + + + + mysql + mysql-connector-java + 8.0.28 + + + + + org.slf4j + slf4j-log4j12 + 1.6.1 + + + + + + org.mybatis.generator + mybatis-generator-core + 1.3.5 + + + + + + \ No newline at end of file diff --git a/mybatis_all/reverse/src/main/java/com/zhangzeyuan/gennerator/GeneratorSqlmap.java b/mybatis_all/reverse/src/main/java/com/zhangzeyuan/gennerator/GeneratorSqlmap.java new file mode 100644 index 0000000..bb23fd4 --- /dev/null +++ b/mybatis_all/reverse/src/main/java/com/zhangzeyuan/gennerator/GeneratorSqlmap.java @@ -0,0 +1,37 @@ +package com.zhangzeyuan.gennerator; +import org.mybatis.generator.api.MyBatisGenerator; +import org.mybatis.generator.config.Configuration; +import org.mybatis.generator.config.xml.ConfigurationParser; +import org.mybatis.generator.internal.DefaultShellCallback; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +/** + * @Author ZZY_1 + * @Date 2023/12/29 15:16 + * @Version 1.0 + */ +public class GeneratorSqlmap { + public void generator() throws Exception{ + List warnings = new ArrayList(); + boolean overwrite = true; + + File configFile = new File("D:\\ideaWork\\test_Res\\mybatis_all\\reverse\\target\\classes\\generatorConfig.xml"); + ConfigurationParser cp = new ConfigurationParser(warnings); + Configuration config = cp.parseConfiguration(configFile); + DefaultShellCallback callback = new DefaultShellCallback(overwrite); + MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, + callback, warnings); + myBatisGenerator.generate(null); + + } + public static void main(String[] args) throws Exception { + try { + GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap(); + generatorSqlmap.generator(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/mybatis_all/reverse/src/main/resources/generatorConfig.xml b/mybatis_all/reverse/src/main/resources/generatorConfig.xml new file mode 100644 index 0000000..81c7828 --- /dev/null +++ b/mybatis_all/reverse/src/main/resources/generatorConfig.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
\ No newline at end of file diff --git a/mybatis_all/reverse/src/main/resources/log4j.properties b/mybatis_all/reverse/src/main/resources/log4j.properties new file mode 100644 index 0000000..d72505d --- /dev/null +++ b/mybatis_all/reverse/src/main/resources/log4j.properties @@ -0,0 +1,11 @@ +log4j.rootLogger=debug,stdout +log4j.appender.file.encoding=UTF-8 + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.err +log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout + +log4j.appender.logfile=org.apache.log4j.FileAppender +log4j.appender.logfile.File=D:/ideaWork/test_Res/mybatis_all/reverse/log/log4j.log +log4j.appender.logfile.layout=org.apache.log4j.PatternLayout +log4j.appender.logfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %l %F %p %m%n \ No newline at end of file diff --git a/springboot_all/springboot01/pom.xml b/springboot_all/springboot01/pom.xml new file mode 100644 index 0000000..d4f4eb1 --- /dev/null +++ b/springboot_all/springboot01/pom.xml @@ -0,0 +1,89 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.4.2 + + org.zhangzeyuan + springboot01 + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.1.3 + + + mysql + mysql-connector-java + 8.0.28 + + + org.projectlombok + lombok + 1.18.12 + provided + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.2.12 + + + mybatis-spring-boot-starter + org.mybatis.spring.boot + + + + + + com.alibaba + druid-spring-boot-starter + 1.1.10 + + + + + + org.attoparser + attoparser + 2.0.5.RELEASE + + + + + org.springframework.boot + spring-boot-starter-thymeleaf + 2.4.5 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/SpringBoot01Application.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/SpringBoot01Application.java new file mode 100644 index 0000000..3e4d4c5 --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/SpringBoot01Application.java @@ -0,0 +1,18 @@ +package com.zhangzeyuan; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.stereotype.Component; + +/** + * @Author ZZY_1 + * @Date 2023/12/29 16:36 + * @Version 1.0 + */ +@SpringBootApplication +//@Component("com.zhangzeyuan.mapper") +public class SpringBoot01Application { + public static void main(String[] args) { + SpringApplication.run(SpringBoot01Application.class, args); + } +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/EmpController.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/EmpController.java new file mode 100644 index 0000000..bbeafe0 --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/EmpController.java @@ -0,0 +1,27 @@ +package com.zhangzeyuan.controller; + +import com.github.pagehelper.PageInfo; +import com.zhangzeyuan.pojo.Emp; +import com.zhangzeyuan.service.EmpService; +import org.springframework.stereotype.Controller; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import java.util.List; +/** + * @Author ZZY_1 + * @Date 2023/12/30 12:07 + * @Version 1.0 + */ +@Controller("/emp") +public class EmpController { + @Autowired + private EmpService empService; + @RequestMapping("/findByPage/{pageNum}/{pageSize}") + @ResponseBody + public PageInfo findByPage(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize){ + return empService.findByPage(pageNum,pageSize); + } +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/FreemarkerController.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/FreemarkerController.java new file mode 100644 index 0000000..feddeaa --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/FreemarkerController.java @@ -0,0 +1,49 @@ +package com.zhangzeyuan.controller; + +import com.zhangzeyuan.pojo.Emp; +import com.zhangzeyuan.service.EmpService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author ZZY_1 + * @Date 2023/12/30 17:37 + * @Version 1.0 + */ +@Controller +public class FreemarkerController { + @Autowired + private EmpService empService; + + @RequestMapping("/show") + public String freemarger(Map map) { + map.put("name", "漩涡刘能"); + return "show"; + } + @RequestMapping("/showEmp") + public ModelAndView showEmp(Map map) { + ModelAndView mv = new ModelAndView(); + List list = empService.findAll(); + mv.addObject("empList", list); + mv.setViewName("showEmp"); + return mv; + } + @RequestMapping("/showEmpMap") + public ModelAndView testMap(){ + ModelAndView mv =new ModelAndView(); + List list =empService.findAll(); + Map empMap =new HashMap<>(); + for (Emp emp : list) { + empMap.put(emp.getEmpno().toString(), emp); + } + mv.addObject("empMap", empMap); + mv.setViewName("showEmpMap"); + return mv; + } +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/MyController.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/MyController.java new file mode 100644 index 0000000..f36319d --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/MyController.java @@ -0,0 +1,35 @@ +package com.zhangzeyuan.controller; + +import com.zhangzeyuan.pojo.User; +import com.zhangzeyuan.service.UserService; +import com.zhangzeyuan.service.impl.UserServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.List; + +/** + * @Author ZZY_1 + * @Date 2023/12/29 16:36 + * @Version 1.0 + */ +@Controller("/user") +public class MyController { + @Autowired + private UserService userService; + @RequestMapping("/secondController") + @ResponseBody + public String secondController() { + return "hello springboot01"; + } + + @RequestMapping("findAll") + @ResponseBody + public List findAll() { + List all = userService.findAll(); + return all; + } + +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/ThymeleafController.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/ThymeleafController.java new file mode 100644 index 0000000..461b6b6 --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/controller/ThymeleafController.java @@ -0,0 +1,20 @@ +package com.zhangzeyuan.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.Map; + +/** + * @Author ZZY_1 + * @Date 2023/12/30 19:19 + * @Version 1.0 + */ +@Controller +public class ThymeleafController { + @RequestMapping("/showIndex") + public String showIndex(Map map) { + map.put("msg", "testMessage"); + return "index"; + } +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/mapper/EmpMapper.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/mapper/EmpMapper.java new file mode 100644 index 0000000..a1524e8 --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/mapper/EmpMapper.java @@ -0,0 +1,16 @@ +package com.zhangzeyuan.mapper; + +import com.zhangzeyuan.pojo.Emp; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @Author ZZY_1 + * @Date 2023/12/30 12:09 + * @Version 1.0 + */ +@Mapper +public interface EmpMapper { + List findAll(); +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/mapper/UserMapper.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/mapper/UserMapper.java new file mode 100644 index 0000000..b8f563f --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/mapper/UserMapper.java @@ -0,0 +1,17 @@ +package com.zhangzeyuan.mapper; + +import com.zhangzeyuan.pojo.User; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @Author ZZY_1 + * @Date 2023/12/30 11:26 + * @Version 1.0 + */ +@Mapper +public interface UserMapper { + + List findAll(); +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/pojo/Emp.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/pojo/Emp.java new file mode 100644 index 0000000..52e683f --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/pojo/Emp.java @@ -0,0 +1,30 @@ +package com.zhangzeyuan.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.Date; +@NoArgsConstructor +@AllArgsConstructor +@Data +public class Emp implements Serializable { + private Integer empno; + + private String ename; + + private String job; + + private Integer mgr; + + private Date hiredate; + + private Double sal; + + private Double comm; + + private Integer deptno; + + +} \ No newline at end of file diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/pojo/User.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/pojo/User.java new file mode 100644 index 0000000..d7b58d9 --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/pojo/User.java @@ -0,0 +1,22 @@ +package com.zhangzeyuan.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @Author ZZY_1 + * @Date 2023/12/30 11:25 + * @Version 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class User implements Serializable { + private Integer uid; + private String username; + private String password; + +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/EmpService.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/EmpService.java new file mode 100644 index 0000000..f5f5c76 --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/EmpService.java @@ -0,0 +1,16 @@ +package com.zhangzeyuan.service; + +import com.github.pagehelper.PageInfo; +import com.zhangzeyuan.pojo.Emp; + +import java.util.List; + +/** + * @Author ZZY_1 + * @Date 2023/12/30 12:08 + * @Version 1.0 + */ +public interface EmpService { + PageInfo findByPage(Integer pageNum, Integer pageSize); + List findAll(); +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/UserService.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/UserService.java new file mode 100644 index 0000000..cba143f --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/UserService.java @@ -0,0 +1,14 @@ +package com.zhangzeyuan.service; + +import com.zhangzeyuan.pojo.User; + +import java.util.List; + +/** + * @Author ZZY_1 + * @Date 2023/12/30 11:26 + * @Version 1.0 + */ +public interface UserService { + List findAll(); +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/impl/EmpServiceImpl.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/impl/EmpServiceImpl.java new file mode 100644 index 0000000..a15da29 --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/impl/EmpServiceImpl.java @@ -0,0 +1,49 @@ +package com.zhangzeyuan.service.impl; + +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.zhangzeyuan.mapper.EmpMapper; +import com.zhangzeyuan.pojo.Emp; +import com.zhangzeyuan.service.EmpService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Author ZZY_1 + * @Date 2023/12/30 12:08 + * @Version 1.0 + */ +@Service +public class EmpServiceImpl implements EmpService { + @Autowired + EmpMapper empMapper; + @Override + public PageInfo findByPage(Integer pageNum, Integer pageSize) { + Page page = PageHelper.startPage(pageNum, pageSize); + List list =empMapper.findAll(); + PageInfo pi = new PageInfo<>(list); + // 方式1 + System.out.println("当前页:"+page.getPageNum()); + System.out.println("总页数"+page.getPages()); + System.out.println("页大小:"+page.getPageSize()); + System.out.println("总记录数:"+page.getTotal()); + System.out.println("当前页数据"+page.getResult()); + + // 方式2 + System.out.println("当前页:"+pi.getPageNum()); + System.out.println("总页数"+pi.getPages()); + System.out.println("页大小:"+pi.getPageSize()); + System.out.println("总记录数:"+pi.getTotal()); + System.out.println("当前页数据"+pi); + return pi; + } + + @Override + public List findAll() { + List list =empMapper.findAll(); + return list; + } +} diff --git a/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/impl/UserServiceImpl.java b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..5d351ce --- /dev/null +++ b/springboot_all/springboot01/src/main/java/com/zhangzeyuan/service/impl/UserServiceImpl.java @@ -0,0 +1,29 @@ +package com.zhangzeyuan.service.impl; + +import com.zhangzeyuan.mapper.UserMapper; +import com.zhangzeyuan.pojo.User; +import com.zhangzeyuan.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * @Author ZZY_1 + * @Date 2023/12/30 11:27 + * @Version 1.0 + */ +@Service +@Transactional +public class UserServiceImpl implements UserService { + @Autowired + private UserMapper userMapper; + + + @Override + public List findAll() { + List users= userMapper.findAll(); + return users; + } +} diff --git a/springboot_all/springboot01/src/main/resources/application.yml b/springboot_all/springboot01/src/main/resources/application.yml new file mode 100644 index 0000000..a9c5a44 --- /dev/null +++ b/springboot_all/springboot01/src/main/resources/application.yml @@ -0,0 +1,54 @@ +server: + port: 8081 + servlet: + context-path: /springboot01 +spring: + datasource: + url: jdbc:mysql://192.168.56.99:3306/mydb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: root +mybatis: + mapper-locations: classpath:mybatis/*.xml + type-aliases-package: com.zhangzeyuan.pojo +druid: + # 连接池的配置信息 + # 初始化大小,最小,最大 + initial-size: 5 + min-idle: 5 + maxActive: 20 + # 配置获取连接等待超时的时间 + maxWait: 60000 + # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 + timeBetweenEvictionRunsMillis: 60000 + # 配置一个连接在池中最小生存的时间,单位是毫秒 + minEvictableIdleTimeMillis: 300000 + validationQuery: SELECT 1 + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + # 打开PSCache,并且指定每个连接上PSCache的大小 + poolPreparedStatements: true + maxPoolPreparedStatementPerConnectionSize: 20 + # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 + filters: stat,wall,slf4j + # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 + connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 + # 配置DruidStatFilter + web-stat-filter: + enabled: true + url-pattern: "/*" + exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*" + # 配置DruidStatViewServlet + stat-view-servlet: + url-pattern: "/druid/*" + # IP白名单(没有配置或者为空,则允许所有访问) + allow: 127.0.0.1,192.168.56.99 + # IP黑名单 (存在共同时,deny优先于allow) + deny: 192.168.1.188 + # 禁用HTML页面上的“Reset All”功能 + reset-enable: false + # 登录名 + login-username: admin + # 登录密码 + login-password: 123456 \ No newline at end of file diff --git a/springboot_all/springboot01/src/main/resources/logback.xml b/springboot_all/springboot01/src/main/resources/logback.xml new file mode 100644 index 0000000..4348d37 --- /dev/null +++ b/springboot_all/springboot01/src/main/resources/logback.xml @@ -0,0 +1,56 @@ + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + + + + + + + + ${LOG_HOME}/server.%d{yyyy-MM-dd}.log + 30 + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + + + + + 10MB + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/springboot_all/springboot01/src/main/resources/mybatis/EmpMapper.xml b/springboot_all/springboot01/src/main/resources/mybatis/EmpMapper.xml new file mode 100644 index 0000000..0f85777 --- /dev/null +++ b/springboot_all/springboot01/src/main/resources/mybatis/EmpMapper.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/springboot_all/springboot01/src/main/resources/mybatis/UserMapper.xml b/springboot_all/springboot01/src/main/resources/mybatis/UserMapper.xml new file mode 100644 index 0000000..0a9341e --- /dev/null +++ b/springboot_all/springboot01/src/main/resources/mybatis/UserMapper.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/springboot_all/springboot01/src/main/resources/templates/index.html b/springboot_all/springboot01/src/main/resources/templates/index.html new file mode 100644 index 0000000..6513172 --- /dev/null +++ b/springboot_all/springboot01/src/main/resources/templates/index.html @@ -0,0 +1,12 @@ + + + + + Title + + + this is first thymeleaf! + + + + \ No newline at end of file diff --git a/springboot_all/springboot01/src/main/resources/templates/show.ftlh b/springboot_all/springboot01/src/main/resources/templates/show.ftlh new file mode 100644 index 0000000..ec86004 --- /dev/null +++ b/springboot_all/springboot01/src/main/resources/templates/show.ftlh @@ -0,0 +1,14 @@ + + + + + Title + + +this is first freemakerPage +
+${name} +${name} +
+ + \ No newline at end of file diff --git a/springboot_all/springboot01/src/main/resources/templates/showEmp.ftlh b/springboot_all/springboot01/src/main/resources/templates/showEmp.ftlh new file mode 100644 index 0000000..8a73454 --- /dev/null +++ b/springboot_all/springboot01/src/main/resources/templates/showEmp.ftlh @@ -0,0 +1,55 @@ + + + + + Title + + + + + + + + + + + + + + + + + + + <#if empList??> + <#list empList as emp> + style="background-color:deepskyblue" > + + + + + + + + + + + + + + + +
索引工号姓名岗位上级入职日期入职时间入职日期时间入职日期串薪资补助部门号
${emp_index}${emp.empno}style="color:blue" >${emp.ename}${emp.job}${emp.mgr!'无'}${emp.hiredate?date}${emp.hiredate?time}${emp.hiredate?datetime}${emp.hiredate?string('yyyy-MM')}style="color:green" >${emp.sal}${emp.comm!0}${emp.deptno}
+ + + \ No newline at end of file diff --git a/springboot_all/springboot01/src/main/resources/templates/showEmpMap.ftlh b/springboot_all/springboot01/src/main/resources/templates/showEmpMap.ftlh new file mode 100644 index 0000000..b9c78ab --- /dev/null +++ b/springboot_all/springboot01/src/main/resources/templates/showEmpMap.ftlh @@ -0,0 +1,49 @@ + + + + + Title + + + +输出7521员工信息:
+工号:${empMap['7521'].empno}
+姓名:${empMap['7521'].ename}
+岗位:${empMap['7521'].job}
+薪资:${empMap['7521'].sal}
+部门号:${empMap['7521'].deptno}
+ + + + + + + + + + + <#list empMap?keys as k> + + + + + + + + + + +
索引工号姓名岗位薪资部门号
${k_index}${k}${empMap[k].ename}${empMap[k].job}${empMap[k].sal}${empMap[k].deptno}
+ + + \ No newline at end of file