5/19 10:57
This commit is contained in:
parent
1f710543bc
commit
989af8a612
35
mybatis519/src/main/java/cn/czyx007/bean/Brand.java
Normal file
35
mybatis519/src/main/java/cn/czyx007/bean/Brand.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package cn.czyx007.bean;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/17 - 14:15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Brand implements Serializable {
|
||||||
|
private static final long serialVersionUID = 372981646177803083L;
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String brandName;
|
||||||
|
|
||||||
|
private String companyName;
|
||||||
|
|
||||||
|
private Integer ordered;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
//本身返回:1 和 0
|
||||||
|
//想返回:启用 和 禁用
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
private Date createDate;
|
||||||
|
}
|
25
mybatis519/src/main/java/cn/czyx007/bean/Emp.java
Normal file
25
mybatis519/src/main/java/cn/czyx007/bean/Emp.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package cn.czyx007.bean;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/16 - 11:02
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Data
|
||||||
|
public class Emp implements Serializable {
|
||||||
|
private static final long serialVersionUID = -89822489848437850L;
|
||||||
|
private Integer eid;
|
||||||
|
private String ename;
|
||||||
|
private String esex;
|
||||||
|
private Date estartime;
|
||||||
|
private Float epay;
|
||||||
|
private Integer did;
|
||||||
|
}
|
19
mybatis519/src/main/java/cn/czyx007/bean/Husband.java
Normal file
19
mybatis519/src/main/java/cn/czyx007/bean/Husband.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package cn.czyx007.bean;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/17 - 15:57
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Husband {
|
||||||
|
private Integer husId;
|
||||||
|
private Integer age;
|
||||||
|
private String gender;
|
||||||
|
private String husbandName;
|
||||||
|
}
|
22
mybatis519/src/main/java/cn/czyx007/bean/Wife.java
Normal file
22
mybatis519/src/main/java/cn/czyx007/bean/Wife.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package cn.czyx007.bean;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/17 - 15:57
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Wife {
|
||||||
|
private Integer wifeId;
|
||||||
|
private Integer wifeAge;
|
||||||
|
private String sex;
|
||||||
|
private String wifeName;
|
||||||
|
private Integer hId; //老公的id外建
|
||||||
|
|
||||||
|
private Husband husband;
|
||||||
|
}
|
16
mybatis519/src/main/java/cn/czyx007/mapper/BrandMapper.java
Normal file
16
mybatis519/src/main/java/cn/czyx007/mapper/BrandMapper.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package cn.czyx007.mapper;
|
||||||
|
|
||||||
|
import cn.czyx007.bean.Brand;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/17 - 14:16
|
||||||
|
*/
|
||||||
|
public interface BrandMapper {
|
||||||
|
//查询所有品牌
|
||||||
|
@Select("select * from person_info.tb_brand")
|
||||||
|
List<Brand> getBrandAll();
|
||||||
|
}
|
41
mybatis519/src/main/java/cn/czyx007/mapper/EmpMapper.java
Normal file
41
mybatis519/src/main/java/cn/czyx007/mapper/EmpMapper.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package cn.czyx007.mapper;
|
||||||
|
|
||||||
|
import cn.czyx007.bean.Emp;
|
||||||
|
import org.apache.ibatis.annotations.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/16 - 11:17
|
||||||
|
*/
|
||||||
|
public interface EmpMapper {
|
||||||
|
//查询所有数据
|
||||||
|
List<Emp> getAll();
|
||||||
|
|
||||||
|
//根据id查询
|
||||||
|
@Select("select * from person_info.emp where eid = #{eid}")
|
||||||
|
Emp getEmpById(Integer eid);
|
||||||
|
|
||||||
|
//插入一条数据
|
||||||
|
@Insert("insert into person_info.emp(ename,esex,estartime) values (#{ename},#{esex},#{estartime})")
|
||||||
|
@Options(useGeneratedKeys = true, keyProperty = "eid")
|
||||||
|
int insertEmp(Emp emp);
|
||||||
|
|
||||||
|
//根据eid删除一条数据
|
||||||
|
@Delete("delete from person_info.emp where eid = #{eid}")
|
||||||
|
int deleteEmp(Integer eid);
|
||||||
|
|
||||||
|
//排序查询
|
||||||
|
@Select("select * from person_info.emp order by estartime ${o}")
|
||||||
|
List<Emp> selectEmpByOrder(String o);
|
||||||
|
|
||||||
|
//根据名字模糊,工资范围查询
|
||||||
|
@Select("select * from person_info.emp where ename like concat('%',#{ename},'%') and epay >= #{startPay} and epay <= #{endPay}")
|
||||||
|
List<Emp> selectEmpBySome(@Param("ename") String ename, @Param("startPay") double startPay, @Param("endPay") double endPay);
|
||||||
|
|
||||||
|
//根据id修改
|
||||||
|
@Update("update person_info.emp set ename = #{ename}, esex = #{esex}, epay = #{epay} where eid = #{eid}")
|
||||||
|
int updateEmpById(Map<String, Object> map);
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package cn.czyx007.mapper;
|
||||||
|
|
||||||
|
import cn.czyx007.bean.Husband;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/17 - 15:58
|
||||||
|
*/
|
||||||
|
public interface HusbandMapper {
|
||||||
|
|
||||||
|
Husband getHusbandById(Integer hid);
|
||||||
|
}
|
30
mybatis519/src/main/java/cn/czyx007/mapper/WifeMapper.java
Normal file
30
mybatis519/src/main/java/cn/czyx007/mapper/WifeMapper.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package cn.czyx007.mapper;
|
||||||
|
|
||||||
|
import cn.czyx007.bean.Wife;
|
||||||
|
import org.apache.ibatis.annotations.*;
|
||||||
|
import org.apache.ibatis.mapping.FetchType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/17 - 15:58
|
||||||
|
*/
|
||||||
|
public interface WifeMapper {
|
||||||
|
//查询老公和老婆的信息
|
||||||
|
@Select("select * from person_info.husband h inner join person_info.wife w on h.hus_id = w.hid")
|
||||||
|
List<Map<String, Object>> getHusAndWife();
|
||||||
|
|
||||||
|
// List<Wife> getHusbandWifeInfo();
|
||||||
|
|
||||||
|
@Select("select * from person_info.wife")
|
||||||
|
@Results(id = "wifeLazyMap", value = {
|
||||||
|
@Result(id = true, column = "wife_id", property = "wifeId"),
|
||||||
|
@Result(column = "wife_name", property = "wifeName"),
|
||||||
|
@Result(column = "hid", property = "hId"),
|
||||||
|
@Result(column = "hid", property = "husband",
|
||||||
|
one = @One(select = "cn.czyx007.mapper.HusbandMapper.getHusbandById", fetchType = FetchType.LAZY))
|
||||||
|
})
|
||||||
|
List<Wife> getWifeAll();
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
<?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="cn.czyx007.mapper.BrandMapper">
|
||||||
|
|
||||||
|
</mapper>
|
@ -0,0 +1,13 @@
|
|||||||
|
<?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="cn.czyx007.mapper.EmpMapper">
|
||||||
|
<!-- <insert id="insertEmp" useGeneratedKeys="true" keyProperty="eid">-->
|
||||||
|
<!-- insert into person_info.emp(ename,esex,estartime) values (#{ename}, #{esex}, #{estartime})-->
|
||||||
|
<!-- </insert>-->
|
||||||
|
<select id="getAll" resultType="cn.czyx007.bean.Emp">
|
||||||
|
select * from person_info.emp
|
||||||
|
</select>
|
||||||
|
</mapper>
|
@ -0,0 +1,14 @@
|
|||||||
|
<?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="cn.czyx007.mapper.HusbandMapper">
|
||||||
|
<resultMap id="hudMap" type="cn.czyx007.bean.Husband">
|
||||||
|
<id property="husId" column="hud_id"/>
|
||||||
|
<result property="husbandName" column="hudband_name"/>
|
||||||
|
</resultMap>
|
||||||
|
<select id="getHusbandById" resultMap="hudMap">
|
||||||
|
select * from person_info.husband where hus_id = #{hid}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
@ -0,0 +1,34 @@
|
|||||||
|
<?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="cn.czyx007.mapper.WifeMapper">
|
||||||
|
<resultMap id="wifeMap" type="cn.czyx007.bean.Wife">
|
||||||
|
<id property="wifeId" column="wife_id"/>
|
||||||
|
<result property="wifeName" column="wife_name"/>
|
||||||
|
<!--映射老公信息 association:用于一对一的关系映射-->
|
||||||
|
<association property="husband" javaType="cn.czyx007.bean.Husband">
|
||||||
|
<id property="husId" column="hus_id"/>
|
||||||
|
<result property="husbandName" column="husband_name"/>
|
||||||
|
</association>
|
||||||
|
</resultMap>
|
||||||
|
<select id="getHusbandWifeInfo" resultMap="wifeMap">
|
||||||
|
SELECT * FROM person_info.husband h INNER JOIN person_info.wife w on h.hus_id=w.hid
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- <resultMap id="wifeLazyMap" type="cn.czyx007.bean.Wife">-->
|
||||||
|
<!-- <id property="wifeId" column="wife_id"/>-->
|
||||||
|
<!-- <result property="wifeName" column="wife_name"/>-->
|
||||||
|
<!-- <result column="hid" property="hId"/>-->
|
||||||
|
<!-- <!–映射老公信息 association:用于一.对一的关系映射–>-->
|
||||||
|
<!-- <association property="husband" javaType="cn.czyx007.bean.Husband"-->
|
||||||
|
<!-- select="cn.czyx007.mapper.HusbandMapper.getHusbandById" column="hid" fetchType="lazy">-->
|
||||||
|
<!-- <id property="husId" column="hus_id"/>-->
|
||||||
|
<!-- <result property="husbandName" column="husband_name"/>-->
|
||||||
|
<!-- </association>-->
|
||||||
|
<!-- </resultMap>-->
|
||||||
|
<!-- <select id="getWifeAll" resultMap="wifeLazyMap">-->
|
||||||
|
<!-- select * from person_info.wife-->
|
||||||
|
<!-- </select>-->
|
||||||
|
</mapper>
|
27
mybatis519/src/test/java/TestEmpDemo.java
Normal file
27
mybatis519/src/test/java/TestEmpDemo.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import cn.czyx007.bean.Emp;
|
||||||
|
import cn.czyx007.mapper.EmpMapper;
|
||||||
|
import cn.czyx007.utils.SqlSessionUtil;
|
||||||
|
import lombok.extern.log4j.Log4j;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 张宇轩
|
||||||
|
* @createTime : 2023/5/17 - 9:09
|
||||||
|
*/
|
||||||
|
@Log4j
|
||||||
|
public class TestEmpDemo {
|
||||||
|
static EmpMapper empMapper = SqlSessionUtil.getSqlSession().getMapper(EmpMapper.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInsert(){
|
||||||
|
Emp emp = new Emp();
|
||||||
|
emp.setEname("123");
|
||||||
|
emp.setEsex("123");
|
||||||
|
emp.setEstartime(new Date());
|
||||||
|
System.out.println(empMapper.insertEmp(emp));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user