- 配置环境yaml
spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/mybatisplus_db?serverTimezone=UTC username: root password: root
- 书写数据库实体类
package com.itheima.domain;import lombok.*;@Datapublic class User { private Long id; private String name; private String password; private Integer age; private String tel; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getTel() { return tel; } public void setTel(String tel) { this.tel = tel; } @java.lang.Override public java.lang.String toString() { return "User{" + "id=" + id + ", name='" + name + '\'' + ", password='" + password + '\'' + ", age=" + age + ", tel='" + tel + '\'' + '}'; }}
- 数据层书写
package com.itheima.dao;import com.baomidou.mybatisplus.core.mapper.BaseMapper;import com.itheima.domain.User;import org.apache.ibatis.annotations.Mapper;// @Mapper为了使扫描到该数据层包(SpringBoot中提及)@Mapper// 注意:MyBatisPlus不需要书写方法,我们直接继承BaseMapper类,并表明我们所使用的实体类即可public interface UserDao extends BaseMapper<User> { // 不需要书写方法,在BaseMapper类中为我们配置了大量的数据库方法来查询,新增,修改,删除}
经验总结扩展阅读
-
-
-
-
角色《且试天下》上线3天惹争议,女主眉毛若隐若现,男主服装是打印的?
-
-
-
-
-
01谈恋爱可以 愿你我皆遇良人,愿所有的温柔爱意都要长久
-
2023年淘宝4月份有满减活动吗 2023年淘宝4月份有满减活动吗
-
-
-
|亲爱的小孩:看到肖路“对着父亲遗像下跪”,才知他为何婚姻不幸
-
-
-
-
-
2023年农历七月廿七买衣服吉日 2023年农历七月廿七宜买衣服吗
-
-