2020-08-03 17:26
@Final 问题已经解决,修改后的代码如下
```
package com.litong.jfinal.controller;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Model;
import com.litong.layui.vo.JsonBean;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class LayuiCurdControler> extends Controller {
private volatile Class clazz = null;
public void getEclassName() {
String name = getBeanClass().getName();
// String name = e.getClass().getName();
HashMap hashMap = new HashMap();
hashMap.put("className", name);
renderJson(hashMap);
}
@SuppressWarnings("unchecked")
public Class getBeanClass() {
if (clazz == null) {
Type type = this.getClass().getGenericSuperclass();
ParameterizedType parameterizedType = (ParameterizedType) type;
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
clazz = (Class) actualTypeArguments[0];
}
return clazz;
}
public void saveOrUpdate() {
Class beanClass = getBeanClass();
E e = getBean(beanClass, "");
log.info("e:{}", e);
e.save();
renderJson(new JsonBean("test success"));
}
}
```
2020-08-01 14:23
@JFinal
https://www.bilibili.com/video/BV1i5411a7Hd
视频如上,测试在子类中正常,在父类中不行
2020-01-31 17:01
@JFinal 我使用你的方法多次测试都不可行,但是我使用下面的代码可行,分享一下
public class EchoController extends Controller {
public void index() {
Kv kv = getKv();
HashMap params = (HashMap) kv;
renderJson(params);
}
}