Bentakın kısıt yabancı anahtar MVC 4
Field | Type | Null | Key | Default | Extra |
+---------------+---------+------+-----+---------+----------------+
| hakemus_id | int(11) | NO | PRI | NULL | auto_increment |
| fk_duuni_id | int(11) | NO | MUL | NULL | |
| fk_ehdokas_id | int(11) | NO | MUL | NULL | |
aşağıda iki sütunlu bir tablo var Ve ben görünümden parametreleri olsun kontrolörü olarak bu
public void insertHakemus(Hakemus hakemus) {
String sql="insert into hakemus(fk_duuni_id, fk_ehdokas_id) values(?,?)";
int ehdokas_id= hakemus.getEhdokas_id();
int duuni_id = hakemus.getDuuni_id();
Object[] ob = new Object[]{duuni_id,ehdokas_id};
jdbcTemplate.update(sql, ob);
}
gibi Dao sınıfında insert yöntemine sahip adlı duuni_id ve ehdokas_id almak için açıklama @RequestParam kullanarak
@RequestMapping(value="sendCV.do", method=RequestMethod.POST)
public String receiveCV(@RequestParam(value="duuni_id") Integer duuni_id,@RequestParam(value="ehdokas_id") Integer ehdokas_id, @ModelAttribute(value="ehdokas") EhdokasImpl ehdokas, Model model){
Hakemus hakemus = new HakemusImpl();
hakemus.setEhdokas_id(ehdokas_id);
hakemus.setDuuni_id(duuni_id);
System.out.println(duuni_id);
System.out.println(ehdokas_id);
if(!ehdokas_id.equals(0) && !duuni_id.equals(0)){
ehdokasdao.editEhdokas(ehdokas);
hakemusdao.insertHakemus(hakemus);
return "redirect:tyopaikat.do";
}
iki sistem yazıcıyı kullanmak duuni_id ve ehdokas_id denetleyin null ya da değil ve sonuçta ben tamam. Bu, View to Controller'dan başarılı olan parametre değer geçişi anlamına gelir. Ama bu kodu çalıştırdığımda, insertHakemus() yönteminde java.lang.NullPointerException hatası alıyorum, herhangi bir fikri olan var mı ?!
stacktrace
Apr 13, 2016 7:10:16 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/vjb.de] is completed
6
1
Apr 13, 2016 7:12:16 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [vietjob] in context with path [/vjb.de] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at vjb.de.vietjob.dao.hakemusDAO.HakemusDaoImpl.insertHakemus(HakemusDaoImpl.java:29)
at vjb.de.vietjob.controller.HakemusController.receiveCV(HakemusController.java:114)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:748)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:833)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Fasulye sınıf
package vjb.de.vietjob.bean.hakemus;
public class HakemusImpl implements Hakemus {
private int hakemus_id;
private int duuni_id;
private int ehdokas_id;
public int getHakemus_id() {
return hakemus_id;
}
public void setHakemus_id(int hakemus_id) {
this.hakemus_id = hakemus_id;
}
public int getDuuni_id() {
return duuni_id;
}
public void setDuuni_id(int duuni_id) {
this.duuni_id = duuni_id;
}
public int getEhdokas_id() {
return ehdokas_id;
}
public void setEhdokas_id(int ehdokas_id) {
this.ehdokas_id = ehdokas_id;
}
}
O değil boş bro {13 Nisan 2016 19:21:55 BİLGİ yeniden org.apache.catalina.core.StandardContext: tamamlandıktan [/vjb.de] adıyla yeniden yüklenmesi Bağlam [email protected]} –
Hakemus hakemus = yeni HakemusImpl(); Bu Hakemus hakemus = yeni Hakemus() olarak değil; – LearningPhase
Bu yorum için üzgünüz, günlüklerinize yakından bakmalıydım. Dao null olamaz – LearningPhase