2019-02-19 17:07
微信第三方开发平台也是开发的公众号功能,只不过是作为第三方,代替甲方调用 API 而已
所以 jfinal weixin 中原有的功能仍然有用, 你只需要添加一部分与授权有关这类的 API 就好,例如:
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1453779503&token=&lang=zh_CN
然后就是以第三方的身份代替甲方调些接口:
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318587&token=&lang=zh_CN
而调接口功能应该是与 jfinal weixin 一样的,在甲方那事先开好好授权
2019-02-19 15:26
在 YourJFinalConfig 中创建一个 onStart() 方法,然后里头大致这样:
public void onStart() {
List list = model.find(...);
RenderManager.me().getEngine().addSharedObject("list", list);
}
然后就可以在模板中使用了:
#for ( x : list)
#(x.y)
#end
注意,上面的 RenderManager.me().getEngine() 是假定了你要对 render(...) 方法使用的 engine 对象进行配置,如果希望以别的 engine 对象进行配置看一下文档中:
https://www.jfinal.com/doc/6-2
2019-02-19 12:04
改成 @Inject 很方便,具体用法参考文档:
https://www.jfinal.com/doc/4-5
注意,这个时候的拦截器 Tx 需要选择一种配置方式,你可以将其配置在 class 上,例如:
@Before(Tx.class)
public class HomeServiceImpl extends BaseService implements IHmoeService {
...
}
如果你所有业务都配置了这个拦截器,也可以配置成全局的,一行代码搞定所有:
configInterceptor(Interceptors me) {
me.addGlobalServiceInterceptor(new Tx());
}
2019-02-19 11:37
umeditor 上传图片不要使用 JSP,而是做一个 action ,在里头用 getFile() 去接收上传文件,jfinal club 项目中的大致代码如下:
/**
* UploadController 上传控制器,接管 ueditor 上传功能
*/
public class UploadController extends BaseController {
@Injedt
UploadService srv;
/**
* 接管 ueditor 上传图片服务端
*
* 1:该 action 与 ueditor.config.js 中的 serverUrl: "/upload/ueditor" 对应
*
* 2:ueditor 页面加载时会向后端发送 "/xxx?action=config 请求用来获取服务端
* /ueditor-home/jsp/config.json 中的配置,后续的上传将受该配置的影响
*
* 3:ueditor1_4_3_2-utf8-jsp 版本测试上传图片成功所返回的 json 数据格式如下:
* {
* "state": "SUCCESS",
* "title": "1461249851191086496.png",
* "original": "qr.png",
* "type": ".png",
* "url": "/ueditor/jsp/upload/image/20160421/1461249851191086496.png",
* "size": "58640"
* }
*
* 4:如果上传出现错误,直接响应如下的 json 即可:
* {"state": "错误信息"}
*
*/
public void ueditor() {
/**
* ueditor 在页面加载时会向后端请求获取 config.json 内容
*/
if ("config".equals(getPara("action"))) {
render("/assets/ueditor/jsp/config.json");
return;
}
/**
* 对应 config.json 配置的 imageActionName: "uploadimage"
*/
if ( ! "uploadimage".equals(getPara("action"))) {
renderJson("state", "UploadController 只支持图片类型的文件上传");
return ;
}
/**
* uploadType 是通过如代码令 ueditor 在上传图片时通过问号挂参的方式传递过来的自定义参数
* ue.ready(function() {
* ue.execCommand('serverparam', {
* 'uploadType': 'project'
* });
* });
*/
String uploadType = getPara("uploadType");
if (StrKit.isBlank(uploadType)) {
renderJson("state", "上传类型参数缺失");
return ;
}
if (notLogin()) {
renderJson("state", "只有登录用户才可以上传文件");
return ;
}
UploadFile uploadFile = null;
try {
// "upfile" 来自 config.json 中的 imageFieldName 配置项
uploadFile = getFile("upfile", UploadService.uploadTempPath, UploadService.imageMaxSize);
Ret ret = srv.ueditorUpload(getLoginAccount(), uploadType, uploadFile);
// renderJson(ret);
render(new JsonRender(ret).forIE()); // 防止 IE 下出现文件下载现象
}
catch(com.jfinal.upload.ExceededSizeException ex) {
renderJson("state", "上传图片只允许 200K 大小");
}
catch(Exception e) {
if (uploadFile != null) {
uploadFile.getFile().delete();
}
renderJson("state", "上传图片出现未知异常,请告知管理员:" + e.getMessage());
LogKit.error(e.getMessage(), e);
}
}
}
2019-02-18 17:42
@osril 用最新版本的 undertow.sh 脚本,在此下载:
https://gitee.com/jfinal/jfinal-undertow/blob/master/undertow.sh