grails - 不在一个 GSP 上但在另一个 Grails 上呈现的域内容列表
问题描述
对,所以我的测试视图代码是:
@Secured(["IS_AUTHENTICATED_REMEMBERED", "IS_AUTHENTICATED_FULLY"])
def list(){
def allPosts = postService.getPosts()
}
<body>
<h1>Welcome to the main feed, <sec:loggedInUserInfo field="username" var="username"/></h2>
<g:if test="${flash.message}">
<div class="messageContainer">
<div style="display: block">${flash.message}</div>
</div>
</g:if>
<p/>
<div>
<g:each var="post" in="${allPosts}">
<p>Last Name: ${post.content}</p>
<p>First Name: ${post.content}</p>
</g:each>
</div>
</body>
</html>
这有效,
这只是为了测试是否还有其他问题,但我希望它可以解决的问题是:
@Secured(["IS_AUTHENTICATED_REMEMBERED", "IS_AUTHENTICATED_FULLY"])
def wall() {
def allPosts = postService.getPosts()
profile = springSecurityService.currentUser.getProfile()
if(!profile){
redirect(controller: "profile", action: "viewProfile")
}else {
[profile: profile]
}
}
和
<!doctype html>
<html>
<head>
<meta name="layout" content="main"/>
</head>
<body>
<h1>Welcome to the main feed, <sec:loggedInUserInfo field="username" var="username"/></h2>
<g:if test="${flash.message}">
<div class="messageContainer">
<div style="display: block">${flash.message}</div>
</div>
</g:if>
<p/>
<div>
<h3>
What are you thinking?
</h3>
</p>
<div>
<g:form action="addPost">
<g:textArea class="postContent" id="postContent" name="content" rows="3" cols="50"/><br/>
<g:submitButton class="postSubmit loginButton" name="post" value="Post"/>
</g:form>
<div>
</div><br/>
<div class="PostContainer">
<g:each var="post" in="${allPosts}">
<p>${post.content}</p>
<p>${post.content}</p>
</g:each>
</div>
</div>
</body>
</html>
但帖子和内容不会在第二个示例中呈现
还有postService:
@Transactional
class PostService {
def getPosts() {
[allPosts:Post.list()]
}
}
对此的任何见解将不胜感激。
我正在为浏览器使用 Windows 10 和 chrome
解决方案
尝试以这种方式从服务返回
@Transactional
class PostService {
def getPosts() {
Post.list()
}
}
推荐阅读
- opendaylight - 使用 Yangtools 无法从 yang 文件生成 Pojos
- javascript - 我想用 server.js 中 req.body 的新数据填充employeeData
- arrays - swift reversed的时间复杂度是多少?
- macos - 无法导入证书以登录钥匙串 (OS X 10.13.5)
- java - 使用在不同机器上运行的 db 触发器调用 java 程序
- javascript - 通过给它你想要它突出显示的单词来突出显示文本
- java - 方法调用递归 onResume Activity java.lang.StackOverflowError: stack size 8MB
- mysql - 为什么在某些情况下减去 unsigned int 列的值的查询会失败?
- kubernetes - Kubernetes EKS 入口和 TLS
- java - 如何使用 opencv 编辑图像以使用 OCR 读取文本