1 2 3 4 5 6 7 8 | class Entry { static belongsTo = [author:User] String title String summary Date dateCreated Date lastUpdated } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <g:form action="save" method="post" > <div class="dialog"> <table> <tbody> <!-- SNIP --> <tr class="prop"> <td valign="top" class="name"> <label for="author">Author:</label> </td> <td valign="top" class="value ${hasErrors(bean:entryInstance, field:'author','errors')}"> <g:select optionKey="id" from="${User.list()}" name="author.id" value="${entryInstance?.author?.id}" ></g:select> </td> </tr> <!-- SNIP --> </tbody> </table> </div> </g:form> |
1 2 3 4 | <g:form action="save" method="post" > <input type="hidden" name="author.id" value="${session.user.id}" /> <!-- SNIP --> </g:form> |
1 2 3 4 5 6 7 8 9 10 11 | def save = { def entryInstance = new Entry(params) entryInstance.author = User.get(session.user.id) if(!entryInstance.hasErrors() && entryInstance.save()) { flash.message = "Entry ${entryInstance.id} created" redirect(action:show,id:entryInstance.id) } else { render(view:'create',model:[entryInstance:entryInstance]) } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |