看不懂这个类
哪位大佬能帮忙看一下这个类(如下代码)是干什么的么?已知的是service类(如下图)要继承它//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.daowen.ssm.simplecrud;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
public class SimpleBizservice<MapperClass extends SimpleMapper> implements Bizservice<MapperClass> {
@Autowired
private MapperClass mapper = null;
public SimpleBizservice() {
}
public MapperClass getMapper() {
return this.mapper;
}
public List getEntity() {
return this.mapper.getAllEntity();
}
public <T> T save(T t) {
Class<?>[] funIntf = this.mapper.getClass().getInterfaces();
Class<?> mapperClazz = null;
if (funIntf != null && funIntf.length > 0) {
mapperClazz = funIntf;
}
Class<?> clz = this.getEntityClass(mapperClazz);
if (clz != null && !clz.isInstance(t)) {
System.out.println("不是实体类");
return null;
} else {
this.mapper.save(t);
return t;
}
}
public List getPageEntitys(String where, int pageIndex, int pageSize) {
return this.mapper.getPageEntitys(where, pageIndex, pageSize);
}
public int getRecordCount(String where) {
return this.mapper.getRecordCount(where);
}
public List getEntity(String where) {
return this.mapper.getEntitys(where);
}
public <T> List<T> getTopEntity(String where, int topCount) {
return this.mapper.getTopEntity(where, topCount);
}
private Class<?> getEntityClass(Class<?> mapperClass) {
Type[] types = mapperClass.getGenericInterfaces();
Class<?> entityClass = null;
Type[] var4 = types;
int var5 = types.length;
for(int var6 = 0; var6 < var5; ++var6) {
Type type = var4;
if (type instanceof ParameterizedType) {
ParameterizedType t = (ParameterizedType)type;
if (t.getRawType() == SimpleMapper.class) {
entityClass = (Class)t.getActualTypeArguments();
break;
}
}
}
return entityClass;
}
public <T> int update(T t) {
return this.mapper.update(t);
}
public int delete(String where) {
return this.mapper.delete(where);
}
public Boolean isExist(String where) {
return this.getRecordCount(where) > 0;
}
public <T> T load(int id) {
Class<?>[] funIntf = this.mapper.getClass().getInterfaces();
Class<?> mapperClazz = null;
if (funIntf != null && funIntf.length > 0) {
mapperClazz = funIntf;
}
Class<?> entityClzz = this.getEntityClass(mapperClazz);
TableMetadata tm = TableMetadata.forClass(entityClzz);
String where = MessageFormat.format("where{0}={1}", tm.getPkColumn(), id);
List list = this.getEntity(where);
return list == null ? null : list.get(0);
}
public <T> T load(String where) {
List<T> list = this.mapper.getEntitys(where);
return list != null && list.size() != 0 ? list.get(0) : null;
}
public <T> List<T> query(String nativateSql) {
return this.mapper.query(nativateSql);
}
public List<HashMap<String, Object>> queryToMap(String nativateSql) {
return this.mapper.queryToMap(nativateSql);
}
public int executeUpdate(String sql) {
return this.mapper.nativeUpdate(sql);
}
}
看不懂啊 凭我小学的拼音水平,感觉像是什么会员之类的 就是一个扩展的Service可以理解为是个有一堆基础方法的基类, 单表CRUD操作都包含,减少开发工作量 这不就是个框架中的数据操作类喽,已经集成了几个常用的对象操作功能,更新,删除,判断存在等,有啥不明白的? lhlking 发表于 2022-4-19 10:35
凭我小学的拼音水平,感觉像是什么会员之类的
以我幼儿园的拼音水平,感觉我也没必要上小学了{:301_997:} 这个是mvc架构里的servcie层,调用数据库的,mapper就是对应数据库的操作,至于具体的业务逻辑你得自己知道。 直接引用应该就可以。
页:
[1]