测试使用HttpScope
This commit is contained in:
parent
fbe33de5a4
commit
e2ef8c0162
@ -25,6 +25,13 @@
|
|||||||
|
|
||||||
<!--<rewrite type="location" match="^/([^-]+)-[^-\.]+\.png(.*)" forward="/$1.png"/>-->
|
<!--<rewrite type="location" match="^/([^-]+)-[^-\.]+\.png(.*)" forward="/$1.png"/>-->
|
||||||
</resource-servlet>
|
</resource-servlet>
|
||||||
|
<!--
|
||||||
|
【节点在<server>中唯一】
|
||||||
|
当Server为HTTP协议时,render才有效. 指定输出引擎的实现类
|
||||||
|
value: 输出引擎的实现类, 必须是org.redkale.net.http.HttpRender的子类
|
||||||
|
-->
|
||||||
|
<render value="com.lxyer.bbs.base.EnjoyRender">
|
||||||
|
</render>
|
||||||
</server>
|
</server>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
BIN
lib/redkale.jar
BIN
lib/redkale.jar
Binary file not shown.
41
src/com/lxyer/bbs/base/EnjoyRender.java
Normal file
41
src/com/lxyer/bbs/base/EnjoyRender.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package com.lxyer.bbs.base;
|
||||||
|
|
||||||
|
import com.jfinal.template.Engine;
|
||||||
|
import com.jfinal.template.Template;
|
||||||
|
import org.redkale.convert.Convert;
|
||||||
|
import org.redkale.net.http.*;
|
||||||
|
import org.redkale.util.AnyValue;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by JUECHENG at 2018/1/30 0:18.
|
||||||
|
*/
|
||||||
|
public class EnjoyRender implements HttpRender<HttpScope> {
|
||||||
|
|
||||||
|
@Resource(name = "SERVER_ROOT")
|
||||||
|
protected File webroot;
|
||||||
|
|
||||||
|
private static final Engine engine = new Engine();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(HttpContext context, AnyValue config) {
|
||||||
|
engine.setBaseTemplatePath(webroot.getPath());
|
||||||
|
engine.addSharedObject("EJ", new EJ());
|
||||||
|
engine.addSharedFunction("/_t/layout.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderTo(HttpRequest request, HttpResponse response, Convert convert, HttpScope scope) {
|
||||||
|
Template template = engine.getTemplate(scope.getReferid());
|
||||||
|
String str = template.renderToString(scope.getAttributes());
|
||||||
|
response.setContentType("text/html; charset=UTF-8");
|
||||||
|
response.finish(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class getType() {
|
||||||
|
return HttpScope.class;
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,16 @@
|
|||||||
package com.lxyer.bbs.content;
|
package com.lxyer.bbs.content;
|
||||||
|
|
||||||
|
import com.jfinal.kit.Kv;
|
||||||
import com.lxyer.bbs.base.BaseService;
|
import com.lxyer.bbs.base.BaseService;
|
||||||
import com.lxyer.bbs.base.LxyKit;
|
import com.lxyer.bbs.base.LxyKit;
|
||||||
import com.lxyer.bbs.base.RetCodes;
|
import com.lxyer.bbs.base.RetCodes;
|
||||||
|
import com.lxyer.bbs.base.user.UserInfo;
|
||||||
import com.lxyer.bbs.base.user.UserService;
|
import com.lxyer.bbs.base.user.UserService;
|
||||||
import com.lxyer.bbs.content.ContentInfo;
|
import com.lxyer.bbs.content.ContentInfo;
|
||||||
import com.lxyer.bbs.base.entity.ActLog;
|
import com.lxyer.bbs.base.entity.ActLog;
|
||||||
import com.lxyer.bbs.content.Content;
|
import com.lxyer.bbs.content.Content;
|
||||||
import com.lxyer.bbs.base.user.User;
|
import com.lxyer.bbs.base.user.User;
|
||||||
import org.redkale.net.http.RestMapping;
|
import org.redkale.net.http.*;
|
||||||
import org.redkale.net.http.RestParam;
|
|
||||||
import org.redkale.net.http.RestService;
|
|
||||||
import org.redkale.net.http.RestSessionid;
|
|
||||||
import org.redkale.service.RetResult;
|
import org.redkale.service.RetResult;
|
||||||
import org.redkale.source.*;
|
import org.redkale.source.*;
|
||||||
import org.redkale.util.SelectColumn;
|
import org.redkale.util.SelectColumn;
|
||||||
@ -186,4 +185,32 @@ public class ContentService extends BaseService{
|
|||||||
return RetResult.success();
|
return RetResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RestMapping(name = "t",auth = false, comment = "测试HttpScope 模板使用")
|
||||||
|
public HttpScope t(){
|
||||||
|
ContentService contentService = this;
|
||||||
|
Flipper flipper = new Flipper().limit(30).sort("top DESC,createTime DESC");
|
||||||
|
//置顶贴
|
||||||
|
FilterNode topNode = FilterNode.create("status", FilterExpress.NOTEQUAL, -1).and("top", FilterExpress.GREATERTHAN, 0);
|
||||||
|
Sheet<ContentInfo> top = contentService.contentQuery(flipper, topNode);
|
||||||
|
|
||||||
|
//非置顶贴
|
||||||
|
FilterNode untopNode = FilterNode.create("status", FilterExpress.NOTEQUAL, -1).and("top", 0);
|
||||||
|
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, untopNode);
|
||||||
|
|
||||||
|
//热帖
|
||||||
|
/*Flipper flipper2 = new Flipper().limit(8).sort("viewNum DESC");
|
||||||
|
Sheet<ContentInfo> hotView = contentService.contentQuery(flipper2, "");*/
|
||||||
|
|
||||||
|
//热议
|
||||||
|
Flipper flipper3 = new Flipper().limit(8).sort("replyNum DESC");
|
||||||
|
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "");
|
||||||
|
|
||||||
|
//最新加入
|
||||||
|
Sheet<UserInfo> lastReg = userService.lastReg();
|
||||||
|
|
||||||
|
Kv kv = Kv.by("top", top).set("contents", contents).set("hotReply", hotReply).set("lastReg", lastReg);
|
||||||
|
|
||||||
|
return HttpScope.refer("index.html").attr(kv);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user