package com.yuefangwang.run;
import ch.qos.logback.core.pattern.color.BlueCompositeConverter;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;
import com.yuefangwang.run.DataMapper.entity.Ping;
import com.yuefangwang.run.DataMapper.mapper.PingMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import javax.swing.event.ListDataListener;
import java.util.*;
import static javax.swing.text.html.HTML.Attribute.VALUE;
import static org.springframework.boot.jackson.JsonComponent.Scope.VALUES;
@SpringBootTest
public class Test2 {
@Autowired(required = false)
private PingMapper pingMapper;
@Test
public void testSelect() {
System.out.println(("----- selectAll method test 逐个开始有问题吗?可以先演示一个么------"));
QueryWrapper<Ping> wrapper = new QueryWrapper<>(); //创建qw
1根据 whereWrapper 条件,更新记录 把id=1的记录,设置颜色为 new red.
// int update(@Param(Constants.ENTITY) T updateEntity, @Param(Constants.WRAPPER) Wrapper<T> whereWrapper);
System.out.println("1根据 whereWrapper 条件,更新记录"); //打印功能提示
wrapper.clear();//这个的意思是把原来wrapper的条件清理了吗,嗯
wrapper.eq("id","1"); //wrapper 要修改的 条件 比如 要把成绩低于60的同学修改为不及格。 UPDATE 成绩表 SET 考核结果='不及格' WHERE (成绩 < 60)
Ping ping = new Ping();
ping.setColor("new red"); //要改的字段。 设置为不合格
pingMapper.update(ping, wrapper);
int update1 = pingMapper.update(ping,wrapper); //Execute SQL:UPDATE ping SET color='new red' WHERE (id = '1')
System.out.println( JSONObject.toJSON(update1));// 执行结果。1:成功,0:没找到有条件的 1
2根据 ID 修改
// int updateById(@Param(Constants.ENTITY) T entity);
// System.out.println("2根据 ID 修改");
// wrapper.clear();
// wrapper.eq("id","2");
// Pinging ping1= new Pinging();
// ping.setColor("new Blue");
// int updateByID = pingMapper.update(ping, wrapper);
// System.out.println( JSONObject.toJSON(updateByID));
//
3// 根据 entity 条件,删除记录
int delete(@Param(Constants.WRAPPER) Wrapper<T> wrapper);
// System.out.println("根据 entity 条件,删除记录");
// QueryWrapper<Ping> Wrapper = new QueryWrapper<>();
// wrapper.clear();
// wrapper.eq("age","5");
// Pinging ping3= new Pinging();
// int delete = pingMapper.delete(wrapper);
// System.out.println( JSONObject.toJSON(delete));
4删除(根据ID 批量删除)
// int deleteBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);
// System.out.println("根据ID 批量删除");
// Collection idList = new ArrayList<>();
// idList.add("2");
// idList.add("3");
// idList.add("4");
// int deleteBatchIds = pingMapper.deleteBatchIds(idList);
// System.out.println( JSONObject.toJSON(deleteBatchIds));
// 5根据 ID 删除
int deleteById(Serializable id);
// System.out.println("根据 ID 删除");
// wrapper.clear();
// wrapper.eq("id","3");
// Pinging ping4= new Pinging();
// int deleteById = pingMapper.deleteById(3);
// System.out.println( JSONObject.toJSON(deleteById));
/ 5查询(根据 columnMap 条件)
List<T> selectByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
// System.out.println("根据 columnMap 条件"); //打印功能提示
// HashMap<String, Object> map = new HashMap<>();
// map.put("thename","Tom");
// List<Ping> pingList2 = pingMapper.selectByMap(map);
// System.out.println( JSONObject.toJSON(pingList2));
// 6根据 columnMap 条件,删除记录
int deleteByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
// System.out.println("根据 columnMap 条件,删除记录");
// HashMap<String, Object> map = new HashMap<>();
// map.put("thename","jack");
// Pinging ping5= new Pinging();
// int deleteByMap = pingMapper.deleteByMap(map);
// System.out.println( JSONObject.toJSON(deleteByMap));
// 7// 插入一条记录
// int insert(T entity);
System.out.println("插入一条记录");
Pinging ping6= new Pinging();
int insert = pingMapper.insert(ping);
System.out.println( JSONObject.toJSON(insert));未完成
}
private class Pinging {
}
}