lambdaQuery()
this.lambdaQuery().eq(Yewuduixiang::getZhongWenMingCheng, yewuduixiang.getZhongWenMingCheng()).count() > 0
lt:less than 小于
le:less than or equal to 小于等于
eq:equal to 等于
ne:not equal to 不等于
ge:greater than or equal to 大于等于
gt:greater than 大于
lq: 是小于等于
Maybatis-Plus中在Yewuduixiang表中getZhongWenMingCheng(获取ZhongWenMingCheng字段)
中值为逗号后面的值的SQL查询。count是查询结果的数量。
BeanUtils.copyProperties(x, y)
BeanUtils.copyProperties(“源对象”, “目标对象”)
用处:将源对象复制到目标对象
BeanUtils.copyProperties(x, y);
y中的存在的属性,x中一定要有,但是x中可以有多余的属性;
x中与y中相同的属性都会被替换,不管是否有值;
x、 y中的属性要名字相同,才能被赋值,不然的话需要手动赋值;
Spring的BeanUtils的CopyProperties方法需要对应的属性有getter和setter方法;
如果存在属性完全相同的内部类,但是不是同一个内部类,即分别属于各自的内部类,spring会认为属性不同,不会copy;
spring和apache的copy属性的方法源和目的参数的位置正好相反,所以导包和调用的时候都要注意一下。
Java时间使用
计算两个时间的相差天数:5号-6号==2天
long l = sdf.parse(jieShuShiJian).getTime() - sdf.parse(kaiShiShiJian).getTime();
if (l<0){
return Result.error("请输入正确的开始和结束时间");
}
long tianShu = (l / 86400000L) +1;
//创建一个时间段list,存数据如"2022-12-06","2022-12-07"
List<String> shiJian = new ArrayList<>();
//创建时间格式
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
//循环天数相加,写入shiJian
for (int i = 0; i < tianShu; i++) {
Date date=sdf.parse(kaiShiShiJian);
Calendar rightNow=Calendar.getInstance();
rightNow.setTime(date);
rightNow.add(Calendar.DAY_OF_YEAR,i);
String endTime=null;
endTime=sdf.format(rightNow.getTime());
// System.out.println("endTime=="+endTime);
shiJian.add(endTime);
}
vue时间使用
//计算时间段的天数
var d = new Date(this.jieShuShiJian) - new Date(this.kaiShiShiJian)
this.tianShu = d / 86400000 + 1
console.log('this.tianShu=', this.tianShu)
//遍历天数,从开始时间一天一天加
for (var q = 0; q < this.tianShu; q++) {
let childrens = []
this.riqi = {}
let str = new Date(new Date().setDate(new Date(this.kaiShiShiJian).getDate() + q)).toLocaleDateString()
let str2 = moment(str).format('YYYY-MM-DD')
}
根据实体获取对应的 Service
/**
* 根据实体获取对应的 Service
*
* @param entity 实体类
* @return
*/
public static IService<Object> getService(Class<?> entity) {
//获取实体类对应的Service
IService<Object> entityService = null;
try {
//首字母转小写 + ServiceImpl
entityService = (IService) SpringContextUtils.getBean(com.baomidou.mybatisplus.core.toolkit.StringUtils.firstToLowerCase(ClassUtil.getClassName(entity, true) + "ServiceImpl"), IService.class);
} catch (Exception e) {
//啥也不做
}
return entityService;
}
通过 反射绕过泛型检查–list
这样就能让一个list存不同类型的数据了
import java.lang.reflect.Method;
import java.util.ArrayList;
/*
* 通过反射越过泛型检查
*
* 例如:有一个String泛型的集合,怎样能向这个集合中添加一个Integer类型的值?
*/
public class fanShe {
public static void main(String[] args) throws Exception{
ArrayList<Integer> strList = new ArrayList<>();
strList.add(100);
strList.add(200);
// strList.add(100);
//获取ArrayList的Class对象,反向的调用add()方法,添加数据
Class listClass = strList.getClass(); //得到 strList 对象的字节码 对象
//获取add()方法
Method m = listClass.getMethod("add", Object.class);
//调用add()方法
m.invoke(strList, "aaa");
m.invoke(strList, false);
//遍历集合
for(Object obj : strList){
System.out.println(obj);
}
}
}
获取当前线程的HttpServletRequest
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();