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,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
|
||||
<file url="file://$PROJECT_DIR$/mybatisTest01/log/test.log" charset="UTF-8" />
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
</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>
|
@ -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>
|
Binary file not shown.
@ -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<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);
|
||||
}
|
@ -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>
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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,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,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>
|
Loading…
Reference in new issue