diff --git a/mybatis519/src/main/java/cn/czyx007/bean/Brand.java b/mybatis519/src/main/java/cn/czyx007/bean/Brand.java new file mode 100644 index 0000000..b1a0a4c --- /dev/null +++ b/mybatis519/src/main/java/cn/czyx007/bean/Brand.java @@ -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; +} diff --git a/mybatis519/src/main/java/cn/czyx007/bean/Emp.java b/mybatis519/src/main/java/cn/czyx007/bean/Emp.java new file mode 100644 index 0000000..ceab6d1 --- /dev/null +++ b/mybatis519/src/main/java/cn/czyx007/bean/Emp.java @@ -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; +} diff --git a/mybatis519/src/main/java/cn/czyx007/bean/Husband.java b/mybatis519/src/main/java/cn/czyx007/bean/Husband.java new file mode 100644 index 0000000..3676068 --- /dev/null +++ b/mybatis519/src/main/java/cn/czyx007/bean/Husband.java @@ -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; +} diff --git a/mybatis519/src/main/java/cn/czyx007/bean/Wife.java b/mybatis519/src/main/java/cn/czyx007/bean/Wife.java new file mode 100644 index 0000000..180d84d --- /dev/null +++ b/mybatis519/src/main/java/cn/czyx007/bean/Wife.java @@ -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; +} diff --git a/mybatis519/src/main/java/cn/czyx007/mapper/BrandMapper.java b/mybatis519/src/main/java/cn/czyx007/mapper/BrandMapper.java new file mode 100644 index 0000000..8db6aec --- /dev/null +++ b/mybatis519/src/main/java/cn/czyx007/mapper/BrandMapper.java @@ -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 getBrandAll(); +} diff --git a/mybatis519/src/main/java/cn/czyx007/mapper/EmpMapper.java b/mybatis519/src/main/java/cn/czyx007/mapper/EmpMapper.java new file mode 100644 index 0000000..ecf928d --- /dev/null +++ b/mybatis519/src/main/java/cn/czyx007/mapper/EmpMapper.java @@ -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 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 selectEmpByOrder(String o); + + //根据名字模糊,工资范围查询 + @Select("select * from person_info.emp where ename like concat('%',#{ename},'%') and epay >= #{startPay} and epay <= #{endPay}") + List 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 map); +} diff --git a/mybatis519/src/main/java/cn/czyx007/mapper/HusbandMapper.java b/mybatis519/src/main/java/cn/czyx007/mapper/HusbandMapper.java new file mode 100644 index 0000000..eb76762 --- /dev/null +++ b/mybatis519/src/main/java/cn/czyx007/mapper/HusbandMapper.java @@ -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); +} diff --git a/mybatis519/src/main/java/cn/czyx007/mapper/WifeMapper.java b/mybatis519/src/main/java/cn/czyx007/mapper/WifeMapper.java new file mode 100644 index 0000000..4974870 --- /dev/null +++ b/mybatis519/src/main/java/cn/czyx007/mapper/WifeMapper.java @@ -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> getHusAndWife(); + +// List 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 getWifeAll(); +} diff --git a/mybatis519/src/main/resources/cn/czyx007/mapper/BrandMapper.xml b/mybatis519/src/main/resources/cn/czyx007/mapper/BrandMapper.xml new file mode 100644 index 0000000..ab99636 --- /dev/null +++ b/mybatis519/src/main/resources/cn/czyx007/mapper/BrandMapper.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/mybatis519/src/main/resources/cn/czyx007/mapper/EmpMapper.xml b/mybatis519/src/main/resources/cn/czyx007/mapper/EmpMapper.xml new file mode 100644 index 0000000..f172b8b --- /dev/null +++ b/mybatis519/src/main/resources/cn/czyx007/mapper/EmpMapper.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/mybatis519/src/main/resources/cn/czyx007/mapper/HusbandMapper.xml b/mybatis519/src/main/resources/cn/czyx007/mapper/HusbandMapper.xml new file mode 100644 index 0000000..2a0ed6d --- /dev/null +++ b/mybatis519/src/main/resources/cn/czyx007/mapper/HusbandMapper.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/mybatis519/src/main/resources/cn/czyx007/mapper/WifeMapper.xml b/mybatis519/src/main/resources/cn/czyx007/mapper/WifeMapper.xml new file mode 100644 index 0000000..0ba9921 --- /dev/null +++ b/mybatis519/src/main/resources/cn/czyx007/mapper/WifeMapper.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mybatis519/src/test/java/TestEmpDemo.java b/mybatis519/src/test/java/TestEmpDemo.java new file mode 100644 index 0000000..cc542f3 --- /dev/null +++ b/mybatis519/src/test/java/TestEmpDemo.java @@ -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)); + } +}