Java web第五次作业

devtools/2024/9/23 10:30:12/

1.在idea中配置好数据源

2、视频案例中只给出了查询所有结果的示例,请自己完成添加、删除、修改操作的代码。以下供参

考。

 @Delete("delete from emp where id=#{id}")

     public void delete(Integer id);

测试代码

 @Test

     public void testDelete(){

         empMapper.delete(17);

     }

@Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time)" +

            "values (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")

public void insert(Emp emp);

测试代码

@Test

    public void testInsert(){

        Emp emp=new Emp();

        emp.setUsername("Tom");

        emp.setName("汤姆");

        emp.setImage("1.jpg");

        emp.setGender((short)1);

        emp.setJob((short)1);

        emp.setEntrydate(LocalDate.of(2000,1,1));

        emp.setCreateTime(LocalDateTime.now());

        emp.setUpdateTime(LocalDateTime.now());

        emp.setDeptId(1);

empMapper.insert(emp);

     }

@Update("update emp set username=#{username},name=#{name},gender=#{gender}," +

        "image=#{image},job=#{job},entrydate=#{entrydate},dept_id=#{deptId},update_time=#{updateTime} where id=#{id}")

public void update(Emp emp);

测试代码

 @Test

    public void testUpdate(){

        Emp emp=new Emp();

        emp.setId(17);

        emp.setUsername("Tom1");

        emp.setName("汤姆1");

        emp.setImage("1.jpg");

        emp.setGender((short)1);

        emp.setJob((short)1);

        emp.setEntrydate(LocalDate.of(2000,1,1));

        emp.setUpdateTime(LocalDateTime.now());

        emp.setDeptId(1);

        empMapper.update(emp);

    }

@Select("select * from emp where name like '%${name}%' and gender =#{gender} and " +

            "entrydate between #{begin} and #{end} order by update_time desc")

    public List<Emp> list(String name, Short gender, LocalDate begin,LocalDate end);

测试代码

 @Test

    public void testList(){

        empMapper.list("张",(short)1,LocalDate.of(2010,1,1),LocalDate.of(2020,1,1));

        System.out.println(empList);

    }

3、lombok库的使用。尝试将实体类采用注解的方式来实现。

import lombok.*;

//@Getter

//@Setter

//@ToString

//@EqualsAndHashCode

@Data

@NoArgsConstructor

@AllArgsConstructor

public class User {

    private Integer id;

    private String name;

    private Short age;

    private Short gender;

    private String phone;

4、学习idea的调试技巧,并尝试使用。

5、对以下案例使用mybatis进行添加、删除、修改、更新的操作。

@Mapper

public interface PoetMapper {

    @Delete("delete from poet where id=#{id}")

    public void delete(Integer id);

    @Insert("insert into poet(name,gender,dynasty,title,style)" +

            "values (#{name},#{gender},#{dynasty},#{title},#{style})")

    public void insert(Poet poet);

    @Update("update poet set name=#{name},gender=#{gender}," +

            "dynasty=#{dynasty},title=#{title},style=#{style} where id=#{id}")

    public void update(Poet poet);

}

测试代码

@SpringBootTest

class SpringbootMybatisCrudApplicationTests {

     @Autowired

     private PoetMapper poetMapper;

    @Test

    public void testInsert(){

        Poet poet=new Poet();

        poet.setName("汤姆");

        poet.setGender((short)1);

        poet.setDynasty("元代");

        poet.setTitle("诗词爱好者");

        poet.setStyle("无");

        poetMapper.insert(poet);

     }

    @Test

     public void testDelete(){

         poetMapper.delete(7);

     }

    @Test

    public void testUpdate(){

        Poet poet=new Poet();

        poet.setId(18);

        poet.setName("汤姆1");

        poet.setGender((short)1);

        poet.setDynasty("清代");

        poet.setTitle("无");

        poet.setStyle("无");

        poetMapper.update(poet);

    }


http://www.ppmy.cn/devtools/33619.html

相关文章

Transformer中的数据输入构造

文章目录 1. 文本内容2. 字典构造2.1 定义一个类用于字典构造2.2 拆分文本2.3 构造结果 3. 完整代码 1. 文本内容 假如我们有如下一段文本内容&#xff1a; Optics It is the branch of physics that studies the behaviour and properties of light . Optical Science 这段…

【华为】路由综合实验(OSPF+BGP基础)

【华为】路由综合实验 实验需求拓扑配置AR1AR2AR3AR4AR5PC1PC2 查看通信OSPF邻居OSPF路由表 BGPBGP邻居BGP 路由表 配置文档 实验需求 ① 自行规划IP地址 ② 在区域1里面 启用OSPF ③ 在区域1和区域2 启用BGP&#xff0c;使AR4和AR3成为eBGP&#xff0c;AR4和AR5成为iBGP对等体…

500行代码实现贪吃蛇(1)

文章目录 目录1. Win32 API 介绍1.1 Win32 API1.2 控制台程序&#xff08;Console&#xff09;1.3 控制台屏幕上的坐标COORD1.4 [GetStdHandle](https://learn.microsoft.com/zh-cn/windows/console/getstdhandle)1.5 [GetConsoleCursorInfo](https://learn.microsoft.com/zh-c…

AI图书推荐:杀手级ChatGPT提示词——利用人工智能实现成功与盈利

《杀手级ChatGPT提示词——利用人工智能实现成功与盈利》&#xff08;Killer ChatGPT Prompts_ Harness the Power of AI for Success and Profit &#xff09;一书是作者Guy Hart-Davis关于ChatGPT的指南&#xff0c;ChatGPT是OpenAI开发的大语言模型。这本书提供了各种职业角…

Python爬取豆瓣电影Top250数据

任务 爬取豆瓣电影top250中的影片名称、影片海报、年份、地区、类型、评分、评价人数、总体评价&#xff0c;并输出到douban_top250.xlsx文件中 环境 Python 3.8 requests bs4 openpyxl 源码 # 创建一个新的Excel工作簿 workbook openpyxl.Workbook() # 获取默认的工作表…

Golang 设计模式(结构型)

文章目录 代理模式门面模式桥接模式适配器模式外观模式享元模式装饰器模式组合模式 代理模式 代理模式是一种结构型设计模式&#xff0c;用于控制对其他对象的访问。它允许你创建一个代理对象&#xff0c;该对象可以代表原始对象&#xff0c;从而可以控制客户端对原始对象的访…

超级简单羊毛绒吊顶天花板(华为公司iPhone茅台酒),花几分钟换回来几百块(非脚本软件)

项目简介&#xff1a;本项目旨在详细介绍当前市场上正规平台的溢价产品信息&#xff08;如华为、iPhone、茅台酒等&#xff09;&#xff0c;分享实际操作的限时抢购步骤&#xff0c;分析出货流程和策略。只需每天投入数分钟&#xff0c;点击操作&#xff0c;就有机会获得几百元…

vue3 element-plus 让el-container占满屏幕

在刚开始用element-plus的布局时&#xff0c;发现无法占满屏幕&#xff1a; 在App.vue中添加如下css代码&#xff1a; <style>html, body, #app {margin: 0;padding: 0;height: 100%;} </style>同时布局代码所在的component如下所示&#xff1a; <template&g…