Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

exception - Cannot get property 'show' on null object in grails

I am getting:

Cannot get property 'show' on null object in my grails project

Here is my code

package com.djamware

class TestController {

    EmployeeService employeeService
 
    def secondaryDataSourceTemplate

    def mainDataSourceTemplate
 
    def testService
    static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]

    def index() {
        render  testService.show
    }

     def show() {
 
         Employee employee=new Employee();
         employee.setName("Gaurav chauhan")
         employee.setEmail("[email protected]")
         employee.setPosition("Java Devloper")
         employee.setSalary(new Double(15000.0))
         String sqlQuery = "SELECT name FROM Employee";
         def counti=new Integer(1);
         try {
            def result = secondaryDataSourceTemplate.queryForList(sqlQuery)
    
            println "result of Query is =====>"+result.name
            println "Size of Result ========> "+result.size();
            counti=result.size();
    
         }
    
         catch (Exception e) {
             e.printStackTrace();
             counti=new Integer(10);
         }
         employeeService.save(employee)
         render  counti;
    }
}
question from:https://stackoverflow.com/questions/65888725/cannot-get-property-show-on-null-object-in-grails

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try including into your static methods the definition for show


static allowedMethods = [show: "GET", save: "POST", update: "PUT", delete: "DELETE"]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...