Customer类
package com.czxy.domain;
import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "customer",keepGlobalPrefix = true) //表名
public class Customer {
//1.随机一个字符串
//@TableId(type = IdType.ASSIGN_UUID)
//2.随机一个数字(Long)雪花算法
//@TableId(type = IdType.ASSIGN_ID)
//3.获得自动增长列信息
@TableId(type = IdType.AUTO)
private Integer cid;
private String cname;
private String password;
private String telephone;
private Double money;
@Version
@TableField(fill = FieldFill.INSERT)
private Integer version;
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@TableField(fill = FieldFill.INSERT_UPDATe)
private Date updateTime;
//@TableLogic
//@TableField(fill = FieldFill.INSERT)
//private Integer deleted;
// exist 是否存储到数据库(是否是临时数据)
//@TableField(exist = false)
//private List ids;
}
CustomerMapper (dao层)
package com.czxy.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.czxy.domain.Customer; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; // 编写dao层 @Mapper public interface CustomerMapper extends BaseMapper{ // 查询所有 //@Select("select * from tmp_customer") public List findAll(); // 模糊查询 //@Select("select * from tmp_customer where cname like #{cname}") public List findByCname(@Param("cname")String cname); // 添加 //@Insert("insert into tmp_customer value(8,'测试555','12123','555',8000,0,null,null)") //@Insert("insert into tmp_customer (a,b,v) values(a,b,c)") public void addCustomer(Customer customer); // 删除 //@Delete("delete from tmp_customer where cid = 7") public void deleteCustomer(@Param("cid")Integer cid); // 修改 //@Update("update tmp_customer set password = 2323 , money = 555 where cname = '测试333'") public void editCustomer(Customer customer); }
Xml
yml:
测试类:
package com.czxy;
import com.czxy.domain.Customer;
import com.czxy.mapper.CustomerMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;
@RunWith(SpringRunner.class) //spring整合Junit测试
@SpringBootTest(classes = MybatisPlusApplication.class) // spring boot整合Junit测试
public class TestCustomerMapperDome06_xml {
@Resource
private CustomerMapper customerMapper;
@Test
public void testXml(){
List list = customerMapper.findAll();
list.forEach(System.out::println);
}
@Test
public void testFindByCname(){
String cname = "%o%";
List byCname = customerMapper.findByCname(cname);
byCname.forEach(System.out::println);
}
@Test
public void testAdd(){
// Customer customer = new Customer(7,"测试555","12123","555",8000d,0,null,null,null,null);
// customerMapper.addCustomer(customer);
}
@Test
public void testDelete(){
customerMapper.deleteCustomer(8);
}
@Test
public void testEdit(){
Customer customer = new Customer();
customer.setPassword("520");
customer.setMoney(520d);
customer.setCid(7);
customerMapper.editCustomer(customer);
}
}



