由于“g:link”而无法运行 Grails 2.4.2 应用程序

问题描述 投票:0回答:0

应该运行该应用程序以创建博客帖子。但是,当我尝试运行我的应用程序时遇到错误

1

当我删除 g:link 它可以运行但是我的项目需要使用 g:link 所以当我使用 g:link 时出错

下面是我的代码

_form.gsp

<%@ page import="blog.posting.website.Post" %>



<div class="fieldcontain ${hasErrors(bean: postInstance, field: 'title', 'error')} required">
    <label for="title">
        <g:message code="post.title.label" default="Title" />
        <span class="required-indicator">*</span>
    </label>
    <g:textField name="title" required="" value="${postInstance?.title}"/>

</div>

<div class="fieldcontain ${hasErrors(bean: postInstance, field: 'content', 'error')} required">
    <label for="content">
        <g:message code="post.content.label" default="Content" />
        <span class="required-indicator">*</span>
    </label>
    <g:textField name="content" required="" value="${postInstance?.content}"/>

</div>

<div class="fieldcontain ${hasErrors(bean: postInstance, field: 'userId', 'error')} required">
    <label for="userId">
        <g:message code="post.userId.label" default="User Id" />
        <span class="required-indicator">*</span>
    </label>
    <g:textField name="userId" required="" value="${postInstance?.userId}"/>

</div>

<div class="fieldcontain ${hasErrors(bean: postInstance, field: 'comments', 'error')} ">
    <label for="comments">
        <g:message code="post.comments.label" default="Comments" />
        
    </label>
    
<ul class="one-to-many">
<g:each in="${postInstance?.comments?}" var="c">
    <li><g:link controller="comment" action="show" id="${c.id}">${c?.encodeAsHTML()}</g:link></li>
</g:each>
<li class="add">
<g:link controller="comment" action="create" params="['post.id': postInstance?.id]">${message(code: 'default.add.label', args: [message(code: 'comment.label', default: 'Comment')])}</g:link>
</li>
</ul>


</div>


创建.gsp

<!DOCTYPE html>
<html>
<head>
    <title>Create New Post</title>
</head>
<body>
    <h1>Create New Post</h1>
    <g:form action="save">
        <label>Title:</label>
        <g:textField name="title" /><br />
        <label>Content:</label>
        <g:textArea name="content" /><br />
        <label>User ID:</label>
        <g:textField name="userId" /><br />
        <button>Save</button>
    </g:form>
    <br />
    <g:link action="list">Back to Posts</g:link>
</body>
</html>

编辑.gsp

<%@ page import="blog.posting.website.Post" %>
<html>
<head>
    <title>Edit Post</title>
</head>
<body>
    <h1>Edit Post</h1>
    <g:form action="update">
        <input type="hidden" name="id" value="${post.id}" />
        <label>Title:</label>
        <g:textField name="title" value="${post.title}" /><br />
        <label>Content:</label>
        <g:textArea name="content" value="${post.content}" /><br />
        <label>User ID:</label>
        <g:textField name="userId" value="${post.userId}" /><br />
        <button>Save</button>
    </g:form>
<br />
       <g:link action="show" id="${post.id}">Back to Post</g:link>
   </body>
   </html>

索引.gsp


<%@ page import="blog.posting.website.Post" %>
<!DOCTYPE html>
<html>
<head>
    <title>Posts</title>
</head>
<body>
    <h1>Posts</h1>
    <table>
        <thead>
            <tr>
                <th>ID</th>
                <th>Title</th>
                <th>User ID</th>
                <th>Date Created</th>
                <th>Last Updated</th>
                <th></th>
                       </tr>
       </thead>
       <tbody>
       <g:each in="${posts}" var="post">
           <tr>
               <td>${post.id}</td>
               <td><g:link action="show" id="${post.id}">${post.title}</g:link></td>
               <td>${post.userId}</td>
               <td>${post.dateCreated}</td>
               <td>${post.lastUpdated}</td>
               <td><g:link action="edit" id="${post.id}">Edit</g:link></td>
               <td><g:form action="delete">
                       <input type="hidden" name="id" value="${post.id}" />
                       <button>Delete</button>
                   </g:form></td>
           </tr>
       </g:each>
       </tbody>
   </table>
   <br />
   <g:link action="create">Create New Post</g:link>
</body>
   </html>


显示.gsp


<%@ page import="blog.posting.website.Post" %>
<!DOCTYPE html>
<html>
<head>
    <title>${post.title}</title>
</head>
<body>
    <h1>${post.title}</h1>
    <p>${post.content}</p>
    <p>User ID: ${post.userId}</p>
    <p>Date Created: ${post.dateCreated}</p>
    <p>Last Updated: ${post.lastUpdated}</p>
    <h2>Comments</h2>
    <ul>
        <g:each in="${post.comments}" var="comment">
            <li>${comment.content}</li>
        </g:each>
    </ul>
    <g:link action="edit" id="${post.id}">Edit</g:link>
    <g:form action="delete">
        <input type="hidden" name="id" value="${post.id}" />
        <button>Delete</button>
    </g:form>
    <br />
    <g:link action="list">Back to Posts</g:link>
</body>
</html>

urlmappings.groovy

class UrlMappings {

    static mappings = {
        "/$controller/$action?/$id?(.$format)?"{
            constraints {
                // apply constraints here
            }
        }

        "/"(view:"/post/create")
        "500"(view:'/error')
    }
}
grails groovy urlmappings.groovy glink
© www.soinside.com 2019 - 2024. All rights reserved.