NutzCN Logo
问答 怎么才能根据返回值返回不同的Beetl视图, Context参数怎么传递
发布于 2612天前 作者 bigcatzeng 1713 次浏览 复制 上一个帖子 下一个帖子
标签:
	@At("/index")
	@GET
	@Ok("beetl:project/index.html")
	public String index(@Attr(scope = Scope.SESSION, value = "me") int userId ) {
		Context ctx = Lang.context();
		
//		return projectService.index(userId, ctx, null);
		
		if ( ... )
			return "beetl:project/index1.html";
		else if (...)
			return "beetl:project/index2.html";
		else
			return "beetl:project/index3.html";
		
	}
14 回复

加个re,根据返回值决定,re后面的是默认值,返回null的时候生效

@Ok("re:beetl:project/index.html")

大神, beetl视图的参数Context怎么传过去?

public String index(@Attr(scope = Scope.SESSION, value = "me") int userId , ViewModel vm) {
          vm.setv(..........);
         ....
         ...
}

或者传入req来设置attr也可以

我的意思是怎么把数据传给Beetl去渲染?

通过ViewModel 或 req.setAttr

if (projectXList.size() == 0) {
return "beetl:project/index_none.html";
} else {
vm.setv("projectList", projectXList);
return "beetl:project/index_all.html";
}

报错, beetl提示没有找到资源

贴报错提示

index.html

    <% for(obj in projectList){ %>  
        <div class="project-item">
          <div class="row"><h2><a href="${base}/user/project/show?id=${obj.projectId}" class="project-name">${obj.projectName}</a></h2></div>
    <%}%>

日志

>>06:50:48:变量未定义(VAR_NOT_DEFINED):projectList 位于57行 资源:project/index.html
54|
55|    <% for(obj in projectList){ %>
56|        <div class="project-item">
57|          <div class="row"><h2><a href="${base}/user/project/show?id=${obj.projectId}" class="project-name">${obj.projectName}</a></h2></div>
58|    <%}%>
59|

obj.projectList

那如果我多设置了几个参数怎么处理:)
vm.setv("projectList1", projectXList);
vm.setv("projectList2", projectXList1);

只是加个前缀obj.哦

明白了, ViewModel 就是obj, 谢谢! :)

添加回复
请先登陆
回到顶部