- 配置环境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类中为我们配置了大量的数据库方法来查询,新增,修改,删除}
经验总结扩展阅读
-
连衣裙 炎热的夏天,穿一件短款修身连衣裙游逛商厦绝对是最惬意的事情!
-
-
-
-
-
-
-
28岁女白领:靠出轨38岁领导走向事业顶峰,我却过得很煎熬
-
-
-
-
久久说情感 凤凰男要求AA制,多年后却向妻子求助,妻子回应:我有钱,但不帮
-
-
-
-
-
卡西欧手表哪一款性价比高,卡西欧系列的手表都有哪些好的推荐?
-
-
-
事业单位高温补贴多少钱 事业单位高温补贴发放是每年都有吗