gpt4 book ai didi

grails - 无法从 Grails 中的服务执行保存操作

转载 作者:行者123 更新时间:2023-12-02 14:29:50 31 4
gpt4 key购买 nike

我正在尝试从服务类中保存表单详细信息。我正在用 remoteForm 尝试这个,但我无法从我的 Controller 转到服务。当我这样做时,会发生以下错误。

.....Error
|
java.lang.NullPointerException
Error |
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
Error |
at org.codehaus.groovy.grails.orm.support.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:85)
Error |
at com.standout.utilityapplication.DataEntrySevice$$EPutsrXF.saveDataentryDetails(DataEntrySevice.groovy)
Error |
at com.standout.utilityapplication.DataEntrySevice$$DPutsrXF.__execute(Unknown Source)
Error |
at com.standout.utilityapplication.DataEntrySevice.__execute(DataEntrySevice.groovy)
Error |
at com.standout.utilityapplication.DataEntrySevice$saveDataentryDetails.call(Unknown Source)
Error |
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
Error |
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
Error |
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
Error |
at com.standout.utilityapplication.DataEntryController$$EPutsrXF.saveAjax(DataEntryController.groovy:21)
Error |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Error |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
Error |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Error |
at java.lang.reflect.Method.invoke(Method.java:606)
Error |
at org.springsource.loaded.ri.ReloadedTypeInvoker$2.invoke(ReloadedTypeInvoker.java:122)
Error |
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1299)
Error |
at org.codehaus.groovy.grails.web.servlet.mvc.MixedGrailsControllerHelper.invoke(MixedGrailsControllerHelper.java:154)
Error |
at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleAction(AbstractGrailsControllerHelper.java:375)
Error |
at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.executeAction(AbstractGrailsControllerHelper.java:252)
Error |
at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleURI(AbstractGrailsControllerHelper.java:205)
Error |
at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleURI(AbstractGrailsControllerHelper.java:126)
Error |
at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:72)
Error |
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:50)
Error |
at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:347)
Error |
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
Error |
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
Error |
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
Error |
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
Error |
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
Error |
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
Error |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
Error |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
Error |
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Error |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
Error |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
Error |
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198)
Error |
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
Error |
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
Error |
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
Error |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
Error |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
Error |
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
Error |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
Error |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
Error |
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
Error |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
Error |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
Error |
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
Error |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
Error |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
Error |
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
Error |
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
Error |
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
Error |
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
Error |
at org.codehaus.groovy.grails.web.mapping.UrlMappingUtils.forwardRequestForUrlMappingInfo(UrlMappingUtils.java:178)
Error |
at org.codehaus.groovy.grails.web.mapping.UrlMappingUtils.forwardRequestForUrlMappingInfo(UrlMappingUtils.java:144)
Error |
at org.codehaus.groovy.grails.web.mapping.UrlMappingUtils.forwardRequestForUrlMappingInfo(UrlMappingUtils.java:135)
Error |
at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:216)
Error |
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Error |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
Error |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
Error |
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
Error |
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
Error |
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
Error |
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
Error |
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
Error |
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
Error |
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53)
Error |
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
Error |
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
Error |
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
Error |
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
Error |
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
Error |
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
Error |
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
Error |
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:62)
Error |
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
Error |
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
Error |
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
Error |
at grails.plugin.springsecurity.web.SecurityRequestHolderFilter.doFilter(SecurityRequestHolderFilter.java:59)
Error |
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
Error |
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
Error |
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
Error |
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
Error |
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
Error |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
Error |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
Error |
at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:69)
Error |
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Error |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
Error |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
Error |
at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
Error |
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Error |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
Error |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
Error |
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
Error |
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Error |
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
Error |
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
Error |
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
Error |
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
Error |
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
Error |
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
Error |
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
Error |
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
Error |
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
Error |
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
Error |
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
Error |
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
Error |
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
Error |
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
Error |
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
Error |
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
Error |
at java.lang.Thread.run(Thread.java:745)
2016-08-25 19:56:55,051 [http-bio-8080-exec-6] INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/utilityapplication] - GroovyPagesServlet: "/WEB-INF/grails-app/views/dataEntry/saveAjax.gsp" not found

这是我的 dataentry.gsp 文件
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<meta name="layout" content="main"/>
<title>Data Entry</title>
</head>
<body>
<div id="saveMsgDiv"></div>
<g:formRemote name="dataEntryForm" update="saveMsgDiv" url="[controller: 'DataEntry', action:'saveAjax']">

<table align="center">
<tr>
<td>
<label for='employeeId'>EmployeeID:</label>
</td>
<td>
<g:textField name='employee_id' required id='employee_id'/>
</td>
</tr>

<tr>
<td>
<label for='team'>Team:</label>
</td>
<td>
<g:select name='team' required id='team' from="${['Java', 'QA', 'Database']}"
noSelection="['':'---select---']"/>
</td>
</tr>

<tr>
<td>
<label for='receiptDate'>Receipt Date:</label>
</td>
<td>
<g:textField name='receipt_dt' required id='receipt_dt'/>
</td>
</tr>

<tr>
<td>
<label for='restaurantName'>Restaurant Name:</label>
</td>
<td>
<g:textField name='restaurant_name' required id='restaurant_name'/>
</td>
</tr>
<tr>
<td>
<label for='numberOfPersons'>Number of Persons:</label>
</td>
<td>
<g:textField name='number_of_persons' required id='number_of_persons' maxlength="3"/>
</td>
</tr>
<tr>
<td>
<label for='amount'>Amount:</label>
</td>
<td>
<g:textField name='amount' required id='amount'/>
</td>
</tr>
<tr>
<td>
<label for='billSubmittedDate'>Bill Submitted Date:</label>
</td>
<td>
<g:textField name='bill_submitted_dt' required id='bill_submitted_dt'/>
</td>
</tr>
<tr>
<td>
<label for='reImbursed'>Reimbursed:</label>
</td>
<td>
<g:textField name='reimbursed' required id='reimbursed'/>
</td>
</tr>
<tr>
<td>
<label for='submitBank'>Submitted to Bank:</label>
</td>
<td>
<g:textField name='presented_bank_fl' required id='presented_bank_fl'/>
</td>
</tr>
<tr>
<td>
<label for='dateOfSubmission'>Date of Bank Submission:</label>
</td>
<td>
<g:textField name='presented_bank_dt' required id='presented_bank_dt'/>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center;">
<g:submitButton name="Submit" style="cursor:pointer"/>
</td>
</tr>
</table>
</g:formRemote>
</body>
</html>

这是我的 DataEntryController.groovy
package com.standout.utilityapplication

import grails.plugin.springsecurity.annotation.Secured
import groovy.sql.Sql


@Secured(['ROLE_DATAENTRY'])
class DataEntryController {

def dataSource
def index() { }
def dataentry(){
println("Inside DataEntryController")
}

def saveAjax(){
def result
try{
DataEntrySevice service = new DataEntrySevice()
service.saveDataentryDetails(params)
}
catch(Exception e){
e.printStackTrace();
}

}

}

这是我的 DataEntryService.groovy
package com.standout.utilityapplication

import grails.transaction.Transactional
import groovy.sql.Sql

@Transactional
class DataEntrySevice {

def dataSource
def int saveDataentryDetails(Map params) {
def result
try{

Dataentry d = new Dataentry();
d.amount = params.amount
d.bill_submitted_dt = params.bill_submitted_dt
d.employee_id = params.employee_id
d.number_of_persons = params.number_of_persons
d.presented_bank_dt = params.presented_bank_dt
d.presented_bank_fl = params.presented_bank_fl
d.receipt_dt = params.receipt_dt
d.reimbursed = params.reimbursed
d.restaurant_name = params.restaurant_name
d.team = params.team
d.save();

}
catch(Exception e){
e.printStackTrace();
}
catch(Exception e){
println(e)
}
return result
}
}

最佳答案

您没有正确注入(inject)服务。你必须以这种方式注入(inject)它

@Secured(['ROLE_DATAENTRY'])
class DataEntryController {

def dataSource

DataEntrySevice service

def index() { }
def dataentry(){
println("Inside DataEntryController")
}

def saveAjax(){
def result
try{

service.saveDataentryDetails(params)
}
catch(Exception e){
e.printStackTrace();
}

}

}

关于grails - 无法从 Grails 中的服务执行保存操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39148386/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com