2023 1330 20:49 commit

main
Mth Zhang 9 months ago
parent bc2dbb52d8
commit 815843348f

@ -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.

@ -1,3 +0,0 @@
# test_Res
所有练习

@ -8,10 +8,12 @@
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" /> <outputRelativeToContentRoot value="true" />
<module name="mybatisTest01" /> <module name="mybatisTest01" />
<module name="reverse" />
</profile> </profile>
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel target="8"> <bytecodeTargetLevel target="8">
<module name="mybatisTest01" target="1.8" /> <module name="mybatisTest01" target="1.8" />
<module name="reverse" target="1.8" />
</bytecodeTargetLevel> </bytecodeTargetLevel>
</component> </component>
</project> </project>

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8"> <component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
<file url="file://$PROJECT_DIR$/mybatisTest01/log/test.log" charset="UTF-8" />
<file url="PROJECT" charset="UTF-8" /> <file url="PROJECT" charset="UTF-8" />
</component> </component>
</project> </project>

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: log4j:log4j:1.2.16">
<CLASSES>
<root url="jar://D:/java-application/Tools/maven_repository/log4j/log4j/1.2.16/log4j-1.2.16.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/java-application/Tools/maven_repository/log4j/log4j/1.2.16/log4j-1.2.16-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/java-application/Tools/maven_repository/log4j/log4j/1.2.16/log4j-1.2.16-sources.jar!/" />
</SOURCES>
</library>
</component>

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.slf4j:slf4j-api:1.6.1">
<CLASSES>
<root url="jar://D:/java-application/Tools/maven_repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/java-application/Tools/maven_repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/java-application/Tools/maven_repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-sources.jar!/" />
</SOURCES>
</library>
</component>

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.slf4j:slf4j-log4j12:1.6.1">
<CLASSES>
<root url="jar://D:/java-application/Tools/maven_repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/java-application/Tools/maven_repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/java-application/Tools/maven_repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1-sources.jar!/" />
</SOURCES>
</library>
</component>

@ -7,6 +7,7 @@
<option name="originalFiles"> <option name="originalFiles">
<list> <list>
<option value="$PROJECT_DIR$/mybatisTest01/pom.xml" /> <option value="$PROJECT_DIR$/mybatisTest01/pom.xml" />
<option value="$PROJECT_DIR$/reverse/pom.xml" />
</list> </list>
</option> </option>
</component> </component>

@ -4,6 +4,7 @@
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/mybatisTest01/mybatisTest01.iml" filepath="$PROJECT_DIR$/mybatisTest01/mybatisTest01.iml" /> <module fileurl="file://$PROJECT_DIR$/mybatisTest01/mybatisTest01.iml" filepath="$PROJECT_DIR$/mybatisTest01/mybatisTest01.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/mybatis_all.iml" filepath="$PROJECT_DIR$/.idea/mybatis_all.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/mybatis_all.iml" filepath="$PROJECT_DIR$/.idea/mybatis_all.iml" />
<module fileurl="file://$PROJECT_DIR$/reverse/reverse.iml" filepath="$PROJECT_DIR$/reverse/reverse.iml" />
</modules> </modules>
</component> </component>
</project> </project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

@ -10,5 +10,5 @@ import java.util.List;
* @Version 1.0 * @Version 1.0
*/ */
public interface DeptMapper { public interface DeptMapper {
List<Emp> findEmpByDeptnoAndSal(Integer deptno, Double sal); List<Emp> findEmpByDeptnoAndSal(Integer deptno,Double sal);
} }

@ -1,9 +1,20 @@
package com.zhangzeyuan.mapper; package com.zhangzeyuan.mapper;
import com.zhangzeyuan.pojo.Emp;
import java.util.List;
/** /**
* @Author ZZY_1 * @Author ZZY_1
* @Date 2023/12/27 23:15 * @Date 2023/12/27 23:15
* @Version 1.0 * @Version 1.0
*/ */
public interface EmpMapper2 { public interface EmpMapper2 {
List<Emp> findByCondition(Emp emp);
List<Emp> findByCondition2(Emp emp);
int updateEmpByCondtion(Emp emp);
int updateEmpByCondtion2(Emp emp);
List<Emp> findByEname(String ename);
List<Emp> findByEmpnoList(List<Integer> empnos );
} }

@ -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<Emp> listAll();
List<Dept> listOneAndMore();
List<Emp> findEmpsByDeptno(int deptno);
Dept findDeptByDeptno(int deptno);
}

@ -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<Project> listMoreAndMore(int pid);
}

@ -4,6 +4,9 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/** /**
* @Author ZZY_1 * @Author ZZY_1
* @Date 2023/12/26 22:14 * @Date 2023/12/26 22:14
@ -12,8 +15,14 @@ import lombok.NoArgsConstructor;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class Dept { public class Dept implements Serializable {
private Integer deptno; private Integer deptno;
private String dname; private String dname;
private String loc; private String loc;
private List<Emp> emps;
public Dept(Integer deptno, String dname, String loc) {
this.deptno = deptno;
this.dname = dname;
this.loc = loc;
}
} }

@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
/** /**
@ -14,7 +15,7 @@ import java.util.Date;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class Emp { public class Emp implements Serializable {
private Integer empno ; private Integer empno ;
private String ename ; private String ename ;
private String job ; private String job ;
@ -23,5 +24,16 @@ public class Emp {
private Double sal ; private Double sal ;
private Double comm ; private Double comm ;
private Integer deptno ; 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;
}
} }

@ -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<ProjectRecord> recordList;
}

@ -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;
}

@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhangzeyuan.mapper.EmpMapper2">
<sql id="columns">
emp.EMPNO,
emp.ENAME,
emp.JOB,
emp.MGR,
emp.HIREDATE,
emp.SAL,
emp.COMM,
emp.DEPTNO
</sql>
<!-- set 标签,动态修改-->
<update id="updateEmpByCondtion">
update emp
<set>
<if test="empno !=null">
, EMPNO =#{empno}
</if>
<if test="ename !=null and ename !=''">
, ENAME =#{ename}
</if>
<if test="job !=null and job !=''">
, job =#{job}
</if>
<if test="mgr !=null ">
, MGR =#{mgr}
</if>
<if test="hiredate !=null ">
, HIREDATE =#{hiredate}
</if>
<if test="sal !=null">
, SAL =#{sal}
</if>
<if test="comm !=null and comm !=''">
, COMM =#{comm}
</if>
</set>
where empno =#{empno};
</update>
<!-- 使用trim标签可以代替set 也可以替代where-->
<update id="updateEmpByCondtion2">
update emp
<trim prefix="set" prefixOverrides=",">
<if test="empno !=null">
, EMPNO =#{empno}
</if>
<if test="ename !=null and ename !=''">
, ENAME =#{ename}
</if>
<if test="job !=null and job !=''">
, job =#{job}
</if>
<if test="mgr !=null ">
, MGR =#{mgr}
</if>
<if test="hiredate !=null ">
, HIREDATE =#{hiredate}
</if>
<if test="sal !=null">
, SAL =#{sal}
</if>
<if test="comm !=null and comm !=''">
, COMM =#{comm}
</if>
</trim>
where empno =#{empno};
</update>
<!--bind标签可以 用来拼接字符串 可以使用param1 也可以使用 传过来的名-->
<select id="findByEname" resultType="emp" parameterType="string">
<bind name="ename1" value="'%'+ename+'%'"/>
select
<include refid="columns"/>
from emp where ename like #{ename1}
</select>
<!-- where if标签-->
<select id="findByCondition" resultType="emp">
select * from emp
<where>
<if test="empno !=null">
and empno =#{empno}
</if>
<if test="ename !=null and ename !=''">
and ename =#{ename}
</if>
<if test="hiredate !=null ">
and hiredate =#{hiredate}
</if>
</where>
</select>
<!--where 标签可以自动 生成 where 1 =1 并且干掉第一个and-->
<select id="findByCondition2" resultType="emp">
select * from emp
<where>
<choose>
<when test="empno !=null">
and empno =#{empno}
</when>
<when test="ename !=null and ename !=''">
and ename =#{ename}
</when>
<when test="hiredate !=null ">
and hiredate =#{hiredate}
</when>
<otherwise>
</otherwise>
</choose>
</where>
</select>
<select id="findByEmpnoList" resultType="com.zhangzeyuan.pojo.Emp">
select
<include refid="columns"></include>
from emp where empno in
<foreach collection="list" item="empno" separator="," open="(" close=")">
#{empno}
</foreach>
</select>
</mapper>

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhangzeyuan.mapper.EmpMapper3">
<resultMap id="empMap" type="emp" autoMapping="true">
<result column="ename" property="ename"></result>
<association property="dept" javaType="dept">
<id column="deptno" property="deptno"></id>
<result column="dname" property="dname"></result>
<result column="loc" property="loc"></result>
</association>
</resultMap>
<resultMap id="deptMap" type="dept">
<id column="deptno" property="deptno"></id>
<result column="dname" property="dname"></result>
<result column="loc" property="loc"></result>
<collection property="emps" ofType="emp" >
<id column="empno" property="empno"></id>
<result column="ename" property="ename"></result>
<result column="job" property="job"></result>
<result column="hiredate" property="hiredate"></result>
<result column="mgr" property="mgr"></result>
<result column="sal" property="sal"></result>
<result column="comm" property="comm"></result>
<result column="deptno" property="deptno"></result>
</collection>
</resultMap>
<resultMap id="deptJoinEmps" type="dept">
<id property="deptno" column="deptno"/>
<result property="dname" column="dname"/>
<result property="loc" column="loc"/>
<collection property="emps"
select="com.zhangzeyuan.mapper.EmpMapper3.findEmpsByDeptno"
javaType="list"
column="deptno"
jdbcType="INTEGER"
fetchType="lazy" >
</collection>
</resultMap>
<select id="listAll" resultMap="empMap">
select * from emp a left join dept b
on a.deptno = b.deptno
</select>
<select id="listOneAndMore" resultMap="deptMap">
select * from dept a left join emp b
on a.deptno = b.deptno
</select>
<select id="findEmpsByDeptno" resultType="com.zhangzeyuan.pojo.Emp">
select * from emp where deptno =#{deptno};
</select>
<select id="findDeptByDeptno" resultMap="deptJoinEmps">
select * from dept where deptno =#{deptno};
</select>
</mapper>

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhangzeyuan.mapper.ProjectMapper">
<resultMap id="projectMap" type="project">
<id column="pid" property="pid"/>
<result column="pname" property="pname"/>
<result column="money" property="money"/>
<collection property="recordList" ofType="projectRecord">
<id column="empno" property="empno"/>
<id column="pid" property="pid"/>
<association property="emp" javaType="emp">
<id column="empno" property="empno"></id>
<result column="ename" property="ename"></result>
<result column="job" property="job"></result>
<result column="hiredate" property="hiredate"></result>
<result column="mgr" property="mgr"></result>
<result column="sal" property="sal"></result>
<result column="comm" property="comm"></result>
<result column="deptno" property="deptno"></result>
</association>
</collection>
</resultMap>
<select id="listMoreAndMore" resultMap="projectMap">
select * from
projectrecord a
left join emp b
on a.empno = b.EMPNO
LEFT JOIN projects c
on a.pid = c.pid
where a.pid =#{pid}
</select>
</mapper>

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG"> <Configuration status="INFO">
<Appenders> <Appenders>
<Console name="Console" target="SYSTEM_ERR"> <Console name="Console" target="SYSTEM_ERR">
<PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" /> <PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" />
@ -16,7 +16,7 @@
</Appenders> </Appenders>
<Loggers> <Loggers>
<Root level="DEBUG"> <Root level="debug">
<AppenderRef ref="Console" /> <AppenderRef ref="Console" />
<AppenderRef ref="RollingFile" /> <AppenderRef ref="RollingFile" />
</Root> </Root>

@ -7,6 +7,11 @@
<properties resource="db.properties"></properties> <properties resource="db.properties"></properties>
<settings> <settings>
<!-- 打开延迟加载的开关-->
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="aggressiveLazyLoading" value="true"/>
<!--设置日志处理方式 LOG4J和 LOG4J2--> <!--设置日志处理方式 LOG4J和 LOG4J2-->
<setting name="logImpl" value="LOG4J2"/> <setting name="logImpl" value="LOG4J2"/>
</settings> </settings>

@ -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<Emp> emps = mapper.findByCondition( emp);
List<Emp> 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<Emp> 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<Emp> emps = mapper.findByCondition( emp);
List<Emp> 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<Emp> emps = mapper.findByCondition( emp);
ArrayList<Integer> integers = new ArrayList<Integer>();
integers.add(1);
integers.add(2);
integers.add(3);
integers.add(4);
List<Emp> emps= mapper.findByEmpnoList(integers);
sqlSession.commit();
System.out.println(emps);
}
@After
public void close() {
sqlSession.close();
}
}

@ -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<Emp> emps = mapper.listAll();
sqlSession.commit();
emps.forEach(emp -> {
System.out.println(emp);
});
}
@Test
public void findOneAndMore() {
EmpMapper3 mapper = sqlSession.getMapper(EmpMapper3.class);
List<Dept> 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();
}
}

@ -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<Project> 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();
}
}

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG"> <Configuration status="INFO">
<Appenders> <Appenders>
<Console name="Console" target="SYSTEM_ERR"> <Console name="Console" target="SYSTEM_ERR">
<PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" /> <PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" />
@ -16,7 +16,7 @@
</Appenders> </Appenders>
<Loggers> <Loggers>
<Root level="DEBUG"> <Root level="debug">
<AppenderRef ref="Console" /> <AppenderRef ref="Console" />
<AppenderRef ref="RollingFile" /> <AppenderRef ref="RollingFile" />
</Root> </Root>

@ -7,6 +7,11 @@
<properties resource="db.properties"></properties> <properties resource="db.properties"></properties>
<settings> <settings>
<!-- 打开延迟加载的开关-->
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="aggressiveLazyLoading" value="true"/>
<!--设置日志处理方式 LOG4J和 LOG4J2--> <!--设置日志处理方式 LOG4J和 LOG4J2-->
<setting name="logImpl" value="LOG4J2"/> <setting name="logImpl" value="LOG4J2"/>
</settings> </settings>

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.google.protobuf:protobuf-java:3.11.4">
<CLASSES>
<root url="jar://D:/java-application/Tools/maven_repository/com/google/protobuf/protobuf-java/3.11.4/protobuf-java-3.11.4.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/java-application/Tools/maven_repository/com/google/protobuf/protobuf-java/3.11.4/protobuf-java-3.11.4-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/java-application/Tools/maven_repository/com/google/protobuf/protobuf-java/3.11.4/protobuf-java-3.11.4-sources.jar!/" />
</SOURCES>
</library>
</component>

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: log4j:log4j:1.2.16">
<CLASSES>
<root url="jar://D:/java-application/Tools/maven_repository/log4j/log4j/1.2.16/log4j-1.2.16.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/java-application/Tools/maven_repository/log4j/log4j/1.2.16/log4j-1.2.16-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/java-application/Tools/maven_repository/log4j/log4j/1.2.16/log4j-1.2.16-sources.jar!/" />
</SOURCES>
</library>
</component>

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: mysql:mysql-connector-java:8.0.28">
<CLASSES>
<root url="jar://D:/java-application/Tools/maven_repository/mysql/mysql-connector-java/8.0.28/mysql-connector-java-8.0.28.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/java-application/Tools/maven_repository/mysql/mysql-connector-java/8.0.28/mysql-connector-java-8.0.28-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/java-application/Tools/maven_repository/mysql/mysql-connector-java/8.0.28/mysql-connector-java-8.0.28-sources.jar!/" />
</SOURCES>
</library>
</component>

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.mybatis.generator:mybatis-generator-core:1.3.5">
<CLASSES>
<root url="jar://D:/java-application/Tools/maven_repository/org/mybatis/generator/mybatis-generator-core/1.3.5/mybatis-generator-core-1.3.5.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/java-application/Tools/maven_repository/org/mybatis/generator/mybatis-generator-core/1.3.5/mybatis-generator-core-1.3.5-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/java-application/Tools/maven_repository/org/mybatis/generator/mybatis-generator-core/1.3.5/mybatis-generator-core-1.3.5-sources.jar!/" />
</SOURCES>
</library>
</component>

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.slf4j:slf4j-api:1.6.1">
<CLASSES>
<root url="jar://D:/java-application/Tools/maven_repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/java-application/Tools/maven_repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/java-application/Tools/maven_repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-sources.jar!/" />
</SOURCES>
</library>
</component>

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.slf4j:slf4j-log4j12:1.6.1">
<CLASSES>
<root url="jar://D:/java-application/Tools/maven_repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://D:/java-application/Tools/maven_repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://D:/java-application/Tools/maven_repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1-sources.jar!/" />
</SOURCES>
</library>
</component>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/reverse.iml" filepath="$PROJECT_DIR$/reverse.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.zhangzeyuan</groupId>
<artifactId>reverse</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- mysql驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<!-- 日志包,方便查看执行信息-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
<!-- 代码生成工具jar -->
<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
</dependencies>
</project>

@ -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<String> warnings = new ArrayList<String>();
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();
}
}
}

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="testTables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<!-- <jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/mybatis" userId="root"
password="123">
</jdbcConnection> -->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.56.99:3306/mydb?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=Asia/Shanghai&amp;allowPublicKeyRetrieval=true"
userId="root"
password="root">
</jdbcConnection>
<!-- 默认false把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- targetProject:生成PO类的位置 -->
<javaModelGenerator targetPackage="com.zhangzeyuan.pojo"
targetProject=".\src">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- targetProject:mapper映射文件生成的位置 -->
<sqlMapGenerator targetPackage="com.zhangzeyuan.mapper"
targetProject=".\src">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- targetPackagemapper接口生成的位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.zhangzeyuan.mapper"
targetProject=".\src">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 指定数据库表 -->
<table tableName="emp" domainObjectName="Emp"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
<columnOverride column="id" javaType="Integer" />
</table>
</context>
</generatorConfiguration>

@ -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

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--继承父项目方式-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
</parent>
<groupId>org.zhangzeyuan</groupId>
<artifactId>springboot01</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency><dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.12</version>
<exclusions>
<exclusion>
<artifactId>mybatis-spring-boot-starter</artifactId>
<groupId>org.mybatis.spring.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- Druid是由阿里巴巴推出的数据库连接池。它结合了C3P0、DBCP、PROXOOL等数据库连接池的优点。
之所以从众多数据库连接池中脱颖而出,还有一个重要的原因就是它包含控制台,很方便的帮助我们实现对于sql执行的监控。
-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<!--freeMaker依赖-->
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>-->
<!-- https://mvnrepository.com/artifact/org.attoparser/attoparser -->
<dependency>
<groupId>org.attoparser</groupId>
<artifactId>attoparser</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.4.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -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);
}
}

@ -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<Emp> findByPage(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize){
return empService.findByPage(pageNum,pageSize);
}
}

@ -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<String, Object> map) {
map.put("name", "漩涡刘能");
return "show";
}
@RequestMapping("/showEmp")
public ModelAndView showEmp(Map<String, Object> map) {
ModelAndView mv = new ModelAndView();
List<Emp> list = empService.findAll();
mv.addObject("empList", list);
mv.setViewName("showEmp");
return mv;
}
@RequestMapping("/showEmpMap")
public ModelAndView testMap(){
ModelAndView mv =new ModelAndView();
List<Emp> list =empService.findAll();
Map<String,Emp> empMap =new HashMap<>();
for (Emp emp : list) {
empMap.put(emp.getEmpno().toString(), emp);
}
mv.addObject("empMap", empMap);
mv.setViewName("showEmpMap");
return mv;
}
}

@ -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<User> findAll() {
List<User> all = userService.findAll();
return all;
}
}

@ -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<String,Object> map) {
map.put("msg", "testMessage");
return "index";
}
}

@ -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<Emp> findAll();
}

@ -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<User> findAll();
}

@ -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;
}

@ -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;
}

@ -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<Emp> findByPage(Integer pageNum, Integer pageSize);
List<Emp> findAll();
}

@ -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<User> findAll();
}

@ -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<Emp> findByPage(Integer pageNum, Integer pageSize) {
Page<Emp> page = PageHelper.startPage(pageNum, pageSize);
List<Emp> list =empMapper.findAll();
PageInfo<Emp> 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<Emp> findAll() {
List<Emp> list =empMapper.findAll();
return list;
}
}

@ -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<User> findAll() {
List<User> users= userMapper.findAll();
return users;
}
}

@ -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

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="${catalina.base}/logs/" />
<!-- 控制台输出 -->
<appender name="Stdout" class="ch.qos.logback.core.ConsoleAppender">
<!-- 日志输出编码 -->
<layout class="ch.qos.logback.classic.PatternLayout">
<!--格式化输出:%d表示日期%thread表示线程名%-5level级别从左显示5个字符宽度%msg日志消息%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</pattern>
</layout>
</appender>
<!-- 按照每天生成日志文件 -->
<appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名-->
<FileNamePattern>${LOG_HOME}/server.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<!--格式化输出:%d表示日期%thread表示线程名%-5level级别从左显示5个字符宽度%msg日志消息%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</pattern>
</layout>
<!--日志文件最大的大小-->
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
</appender>
<!-- 日志输出级别 -->
<root level="info">
<appender-ref ref="Stdout" />
<appender-ref ref="RollingFile" />
</root>
<logger name="com.zhangzeyuan.mapper" level="DEBUG"></logger>
<!--日志异步到数据库 -->
<!-- <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
日志异步到数据库
<connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
连接池
<dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
<driverClass>com.mysql.jdbc.Driver</driverClass>
<url>jdbc:mysql://127.0.0.1:3306/databaseName</url>
<user>root</user>
<password>root</password>
</dataSource>
</connectionSource>
</appender> -->
</configuration>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhangzeyuan.mapper.EmpMapper">
<!-- <resultMap id=""></resultMap>-->
<select id="findAll" resultType="emp">
select * from emp
</select>
</mapper>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhangzeyuan.mapper.UserMapper">
<!-- <resultMap id=""></resultMap>-->
<select id="findAll" resultType="user">
select * from user
</select>
</mapper>

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
this is first thymeleaf!
<span th:text="pageMessage"></span>
<span th:text="${msg}"></span>
</body>
</html>

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
this is first freemakerPage
<br/>
${name}
${name}
<br/>
</body>
</html>

@ -0,0 +1,55 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
#empTable{
width: 80%;
border: 1px solid blue;
margin: 0px auto;
}
#empTable th,td{
border: 1px solid green;
text-align: center;
}
</style>
</head>
<body>
<table id empTable cellpadding="1px" cellspacing="0px">
<tr>
<td>索引</td>
<td>工号</td>
<td>姓名</td>
<td>岗位</td>
<td>上级</td>
<td>入职日期</td>
<td>入职时间</td>
<td>入职日期时间</td>
<td>入职日期串</td>
<td>薪资</td>
<td>补助</td>
<td>部门号</td>
</tr>
<#if empList??>
<#list empList as emp>
<tr <#if emp_index%2==0>style="background-color:deepskyblue" </#if>>
<td>${emp_index}</td>
<td>${emp.empno}</td>
<td <#if emp.ename == 'KING'>style="color:blue"</#if> >${emp.ename}</td>
<td>${emp.job}</td>
<td>${emp.mgr!'无'}</td>
<td>${emp.hiredate?date}</td>
<td>${emp.hiredate?time}</td>
<td>${emp.hiredate?datetime}</td>
<td>${emp.hiredate?string('yyyy-MM')}</td>
<td <#if emp.sal gte 3000>style="color:green"</#if> >${emp.sal}</td>
<td>${emp.comm!0}</td>
<td>${emp.deptno}</td>
</tr>
</#list>
</#if>
</table>
</body>
</html>

@ -0,0 +1,49 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
#empTable{
width: 80%;
border: 1px solid blue;
margin: 0px auto;
}
#empTable th,td{
border: 1px solid green;
text-align: center;
}
</style>
</head>
<body>
输出7521员工信息<br/>
工号:${empMap['7521'].empno}<br/>
姓名:${empMap['7521'].ename}<br/>
岗位:${empMap['7521'].job}<br/>
薪资:${empMap['7521'].sal}<br/>
部门号:${empMap['7521'].deptno}<br/>
<table id="empTable" cellpadding="0px" cellspacing="0px">
<tr>
<th>索引</th>
<th>工号</th>
<th>姓名</th>
<th>岗位</th>
<th>薪资</th>
<th>部门号</th>
</tr>
<#list empMap?keys as k>
<tr>
<th>${k_index}</th>
<th>${k}</th>
<th>${empMap[k].ename}</th>
<th>${empMap[k].job}</th>
<th>${empMap[k].sal}</th>
<th>${empMap[k].deptno}</th>
</tr>
</#list>
</table>
</body>
</html>
Loading…
Cancel
Save