为什么我得到500(内部服务器错误)

时间:2018-05-13 12:23:04

标签: jquery ajax spring-mvc

我正在尝试使用ajax调用在我的程序中获取list of countries,如下所示

这是我的ajax电话

function countryList(){

        var url = contextPath+"/master/country";
        $.ajax({          
            url : url,

            type:"get",     
            contentType:'application/json; charset=utf-8',     
            dataType: 'json' ,
            async: false,  
            success:function(response) 
            {       
                console.log(response);
                alert(response); 
                 var slno=0;
                for(var i=0;i<response.data.length;i++)
                    {
                    slno++;
                    $('#countryTable').append("<tr><td>"+slno+"</td><td>"+response.data[i].countryName+"</td><td><i class='fas fa-eye fa-2x eye countryEye'><input type='hidden' value='"+response.data[i].countryId+"'></td></tr>")

                    }          
                $('#countryTable').DataTable();  



            }
        });
     }  

这是我的实体类

package com.rasvek.cms.entity;
// Generated May 13, 2018 3:08:53 PM by Hibernate Tools 5.1.7.Final

import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * MasterAddressCountry generated by hbm2java
 */
@Entity
@Table(name = "master_address_country", catalog = "campus_guru_01")
public class MasterAddressCountry implements java.io.Serializable {

    private Integer countryId;
    private String countryName;
    private String countryShortCode;
    private String status;
    private Set<MasterAddressState> masterAddressStates = new HashSet<MasterAddressState>(0);
    private Set<MasterAddress> masterAddresses = new HashSet<MasterAddress>(0);

    public MasterAddressCountry() {
    }

    public MasterAddressCountry(String countryName, String countryShortCode, String status,
            Set<MasterAddressState> masterAddressStates, Set<MasterAddress> masterAddresses) {
        this.countryName = countryName;
        this.countryShortCode = countryShortCode;
        this.status = status;
        this.masterAddressStates = masterAddressStates;
        this.masterAddresses = masterAddresses;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)

    @Column(name = "country_id", unique = true, nullable = false)
    public Integer getCountryId() {
        return this.countryId;
    }

    public void setCountryId(Integer countryId) {
        this.countryId = countryId;
    }

    @Column(name = "country_name")
    public String getCountryName() {
        return this.countryName;
    }

    public void setCountryName(String countryName) {
        this.countryName = countryName;
    }

    @Column(name = "country_short_code")
    public String getCountryShortCode() {
        return this.countryShortCode;
    }

    public void setCountryShortCode(String countryShortCode) {
        this.countryShortCode = countryShortCode;
    }

    @Column(name = "status", length = 4)
    public String getStatus() {
        return this.status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "masterAddressCountry")
    public Set<MasterAddressState> getMasterAddressStates() {
        return this.masterAddressStates;
    }

    public void setMasterAddressStates(Set<MasterAddressState> masterAddressStates) {
        this.masterAddressStates = masterAddressStates;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "masterAddressCountry")
    public Set<MasterAddress> getMasterAddresses() {
        return this.masterAddresses;
    }

    public void setMasterAddresses(Set<MasterAddress> masterAddresses) {
        this.masterAddresses = masterAddresses;
    }

}

这是我的控制器和方法

@RestController
@RequestMapping(value="/master")
public class MasterController
{

    @Autowired
    private MasterServiceInter service;
    private HttpHeaders headers = null;
    Map<String, Object> message = new HashMap<String, Object>();
    @GetMapping("/country")   
    public ResponseEntity<Map<String, Object>> getMasterAddressCountryList()  {

        List<MasterAddressCountry>  MasterAddressCountryList = service.getMasterAddressCountryList();

        for(MasterAddressCountry cc: MasterAddressCountryList)
        {
            System.out.println(cc.getCountryName());  
        }
        System.out.println(MasterAddressCountryList);       
        ResponseEntity<Map<String, Object>> responseEntity=null;
        try {
        headers = new HttpHeaders();
        if (!MasterAddressCountryList.isEmpty()) {
            headers.add("head", "MasterAddressCountry");
            message.put("status", true);
            message.put("data", MasterAddressCountryList);
            responseEntity=new ResponseEntity<Map<String, Object>>(message, headers, HttpStatus.OK);
        } else {
            headers.add("head", "null");
            message.put("status", false);
            message.put("data", MasterAddressCountryList);    
            message.put("errorMessage", "No Data Found");
            responseEntity=new ResponseEntity<Map<String, Object>>(message, headers, HttpStatus.NOT_FOUND);
        }
    }catch (Exception e) {
        e.printStackTrace();
    }
        return responseEntity;
    }
    }

SERVICE

@Override 
    @Transactional
    public List<MasterAddressCountry> getMasterAddressCountryList() {
        // TODO Auto-generated method stub
        System.out.println("service");
        return theMasterDao.getMasterAddressCountryList();
    }

DAO

@Override
    public List<MasterAddressCountry> getMasterAddressCountryList() {


        List<MasterAddressCountry> MasterAddressCountryList=null;  
         try {
                currentSession = sessionFactory.getCurrentSession();
                critBuilder = currentSession.getCriteriaBuilder();
                CriteriaQuery<MasterAddressCountry> critQuery = critBuilder.createQuery(MasterAddressCountry.class);
                Root<MasterAddressCountry> root = critQuery.from(MasterAddressCountry.class);
                critQuery.select(root);
                Query<MasterAddressCountry> query = currentSession.createQuery(critQuery);
                 MasterAddressCountryList =query.getResultList();  



         }catch (Exception e) {
            e.printStackTrace();
        }
         System.out.println(MasterAddressCountryList);
        return MasterAddressCountryList;
    }  

ajax get call进入控制器和每一层list of countries also getting from database,但响应没有进入ajax调用 给出以下错误

GET http://localhost:8015/campasAdmin/master/country 500 (Internal Server Error)

请帮帮我

请查看日志

    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'masteraddr0_.city' in 'field list'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:353)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.getResultSet(AbstractLoadPlanBasedLoader.java:419)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeQueryStatement(AbstractLoadPlanBasedLoader.java:191)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:121)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:86)
    at org.hibernate.loader.collection.plan.AbstractLoadPlanBasedCollectionInitializer.initialize(AbstractLoadPlanBasedCollectionInitializer.java:87)
    at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:688)
    at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:75)
    at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:2184)
    at org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:565)
    at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:247)
    at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:561)
    at org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:729)
    at org.hibernate.engine.internal.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:926)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:346)
    at org.hibernate.loader.Loader.doList(Loader.java:2692)
    at org.hibernate.loader.Loader.doList(Loader.java:2675)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507)
    at org.hibernate.loader.Loader.list(Loader.java:2502)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:392)
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1489)
    at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445)
    at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414)
    at org.hibernate.query.Query.getResultList(Query.java:146)
    at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:72)
    at com.rasvek.cms.dao.MasterDaoImpl.getMasterAddressCountryList(MasterDaoImpl.java:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy97.getMasterAddressCountryList(Unknown Source)
    at com.rasvek.cms.service.MasterSeviceImpl.getMasterAddressCountryList(MasterSeviceImpl.java:35)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy98.getMasterAddressCountryList(Unknown Source)
    at com.rasvek.cms.controller.MasterController.getMasterAddressCountryList(MasterController.java:46)
    at com.rasvek.cms.controller.MasterController$$FastClassBySpringCGLIB$$c2eff8c2.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
    at com.rasvek.cms.controller.MasterController$$EnhancerBySpringCGLIB$$1a26ca50.getMasterAddressCountryList(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
WARN  2018-05-13 17:42:41,330 84323  (http-nio-8015-exec-11:org.hibernate.engine.jdbc.spi.SqlExceptionHelper):
      [org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions(SqlExceptionHelper.java:129)] 
      SQL Error: 1054, SQLState: 42S22

ERROR 2018-05-13 17:42:41,330 84323  (http-nio-8015-exec-11:org.hibernate.engine.jdbc.spi.SqlExceptionHelper):
      [org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions(SqlExceptionHelper.java:131)] 
      Unknown column 'masteraddr0_.city' in 'field list'

INFO  2018-05-13 17:42:41,340 84333  (http-nio-8015-exec-11:com.rasvek.cms.aspect.CmsLoggingAspect):
      [com.rasvek.cms.aspect.CmsLoggingAspect.afterReturing(CmsLoggingAspect.java:66)] 
      ====> in @AfterReturing: from return method MasterDao.getMasterAddressCountryList()

INFO  2018-05-13 17:42:41,340 84333  (http-nio-8015-exec-11:com.rasvek.cms.aspect.CmsLoggingAspect):
      [com.rasvek.cms.aspect.CmsLoggingAspect.afterReturing(CmsLoggingAspect.java:70)] 
      ===> result : null

INFO  2018-05-13 17:42:41,341 84334  (http-nio-8015-exec-11:com.rasvek.cms.aspect.CmsLoggingAspect):
      [com.rasvek.cms.aspect.CmsLoggingAspect.afterReturing(CmsLoggingAspect.java:66)] 
      ====> in @AfterReturing: from return method MasterServiceInter.getMasterAddressCountryList()

INFO  2018-05-13 17:42:41,342 84335  (http-nio-8015-exec-11:com.rasvek.cms.aspect.CmsLoggingAspect):
      [com.rasvek.cms.aspect.CmsLoggingAspect.afterReturing(CmsLoggingAspect.java:70)] 
      ===> result : null

0 个答案:

没有答案