Laravel函数调用并在同一个控制器中返回

时间:2017-08-12 19:02:50

标签: php

我是laravel的新手。我怀疑如何在同一个控制器中调用其他函数并将处理后的值返回到调用它的函数。我尝试过这类似于C语言,但代码不起作用

<v-flex xs12 md6>
    <v-data-table :headers="headers" :items="homeTeam" hide-actions class="elevation-1 white">
        <template slot="items" scope="props">
            <td class="text-xs-right" v-model="gamesheet.number">{{ props.item.number }}</td>
            <td v-model="gamesheet.name">{{ props.item.name }}</td>
        </template>
    </v-data-table>
</v-flex>

<v-flex xs12 md6>
    <v-data-table :headers="headers" :items="awayTeam" hide-actions class="elevation-1 white">
        <template slot="items" scope="props">
            <td class="text-xs-right" v-model="gamesheet.number">{{ props.item.number }}</td>
            <td v-model="gamesheet.name">{{ props.item.name }}</td>
        </template>
    </v-data-table>
</v-flex>

1 个答案:

答案 0 :(得分:3)

在您的商店功能

import java.util.Scanner;
import java.io.Serializable;


/*  Class Node  */

class Employee implements Serializable{
    int ID;
    String name;
    String address;

    Employee(int emp_ID, String emp_name, String emp_address){
        ID = emp_ID;
        name = emp_name;
        address = emp_address;
    }
    public void print(){
        System.out.println(ID);
        System.out.println(name);
        System.out.println(address);

    }
    @Override
    public String toString() {
        return ID + "-" + name + "-" + address;
     } 
}

class Node 
{
    protected Employee emp;
    protected Node link;
    public Object name;
    public Node in;

    /*  Constructor  */
    public Node()
    {
        link = null;
        emp = null;
    }    
    /*  Constructor  */
    public Node(Employee e,Node n)
    {
        emp = e;
        link = n;
    }    
    /*  Function to set link to next Node  */
    public void setLink(Node n)
    {
        link = n;
    }    
    /*  Function to set data to current Node  */
    public void setData(Employee e)
    {
        emp = e;
    }    
    /*  Function to get link to next node  */
    public Node getLink()
    {
        return link;
    }    
    /*  Function to get data from current Node  */
    public Employee getData()
    {
        emp.print();
        return null;

    }
}



/* Class linkedList */
class linkedList
{
    protected Node start ;
    protected Node end ;
    public int size ;

    /* Constructor */
    public linkedList()
    {
        start = null;
        end = null;
        size = 0;
    }
    /* Function to check if list is empty */

    public boolean isEmpty()
    {
        return start == null;
    }
    /* Function to get size of the list */
    public int getSize()
    {
        return size;
    }
    /* Function to insert element at the begining */
    public void insertAtStart(Employee e)
    {
        Node nptr = new Node(e,null);    
        nptr.setLink(start);
        if(start == null)
        {            
            start = nptr;
            nptr.setLink(start);
            end = start;            
        }
        else
        {
            end.setLink(nptr);
            start = nptr;        
        }
        size++ ;
    }
    /* Function to insert element at end */
    public void insertAtEnd(Employee e)
    {
        Node nptr = new Node(e,null);    
        nptr.setLink(start);
        if(start == null)
        {            
            start = nptr;
            nptr.setLink(start);
            end = start;            
        }
        else
        {
            end.setLink(nptr);
            end = nptr;            
        }
        size++ ;
    }

    /* Function to insert element at position */
    public void insertAtPos(Employee e , int pos) 
    {
        Node nptr = new Node(e,null);                
        Node ptr = start;
        pos = pos - 1 ;
        for (int i = 1; i < size - 1; i++) 
        {
            if (i == pos) 
            {
                Node tmp = ptr.getLink() ;
                ptr.setLink( nptr );
                nptr.setLink(tmp);
                break;
            }
            ptr = ptr.getLink();
        }
        size++ ;
    }

    /* Function to delete element at position */

    public void searchByName(){

    }

    public void deleteByName(){

    }

    public void deleteAtPos(int pos)
    {    
        if (size == 1 && pos == 1)
        {
            start = null;
            end = null;
            size = 0;
            return ;
        }        
        if (pos == 1) 
        {
            start = start.getLink();
            end.setLink(start);
            size--; 
            return ;
        }
        if (pos == size) 
        {
            Node s = start;
            Node t = start;
            while (s != end)
            {
                t = s;
                s = s.getLink();
            }
            end = t;
            end.setLink(start);
            size --;
            return;
        }
        Node ptr = start;
        pos = pos - 1 ;
        for (int i = 1; i < size - 1; i++) 
        {
            if (i == pos) 
            {
                Node tmp = ptr.getLink();
                tmp = tmp.getLink();
                ptr.setLink(tmp);
                break;
            }
            ptr = ptr.getLink();
        }
        size-- ;
    }

    /* Function to display contents */
    public void display()
    {
       System.out.print("\nEmployee Management= ");
        Node ptr = start;
        if (size == 0) 
        {
            System.out.print("empty\n");
            return;
        }
        if (start.getLink() == start) 
        {
            System.out.print(start.getData()+ "\n");
            return;
        }
        System.out.print(start.getData()+ "" + "\n");
        ptr = start.getLink();
        while (ptr.getLink() != start) 
        {
            System.out.print(ptr.getData()+ "" + "\n");
            ptr = ptr.getLink();
        }

        System.out.print(ptr.getData()+ "\n");
    }
}



/* Class CircularSinglyLinkedList */
public class CurrilarLinkedList
{    
    public static void main(String[] args)
    {    


        int ID = 0;
        String name = null;
        String address = null;
        Employee emp = null;
        Scanner scan = new Scanner(System.in);
        /* Creating object of linkedList */
        linkedList list = new linkedList(); 
        System.out.println("Circular Singly Linked List Test\n");          
        char ch;
        /*  Perform list operations  */
        do
        {
            System.out.println("\nCircular Singly Linked List Operations\n");
            System.out.println("1. insert at begining");
            System.out.println("2. insert at end");
            System.out.println("3. insert at position");
            System.out.println("4. delete at position");
            System.out.println("5. check empty");
            System.out.println("6. get size");
            System.out.println("7. delete by name");
            System.out.println("8. search by name");
            int choice = scan.nextInt(); 

            switch (choice)
            {
            case 1 : 
                System.out.print("Please input an Employee \n");
                Scanner myScanner = new Scanner(System.in);
                System.out.println("Please input an Employee ID");
                ID = myScanner.nextInt();
                myScanner.nextLine();
                System.out.println("Please input an Employee Name");
                name = myScanner.nextLine();
                System.out.println("Please input an Employee Address");
                address = myScanner.nextLine();
                emp = new Employee(ID,name,address);
                list.insertAtStart(emp);                     
                break;                          
            case 2 : 
                System.out.print("Please input an Employee \n");
                myScanner = new Scanner(System.in);
                System.out.println("Please input an Employee ID");
                ID = myScanner.nextInt();
                myScanner.nextLine();
                System.out.println("Please input an Employee Name");
                name = myScanner.nextLine();
                System.out.println("Please input an Employee Address");
                address = myScanner.nextLine();
                emp = new Employee(ID,name,address);
                list.insertAtEnd(emp);                       
                break;                         
            case 3 : 
                System.out.println("Enter position");
                int pos = scan.nextInt() ;
                System.out.print("Please input an Employee \n");
                myScanner = new Scanner(System.in);
                System.out.println("Please input an Employee ID");
                ID = myScanner.nextInt();
                myScanner.nextLine();
                System.out.println("Please input an Employee Name");
                name = myScanner.nextLine();
                System.out.println("Please input an Employee Address");
                address = myScanner.nextLine();
                emp = new Employee(ID,name,address);

                if (pos <= 1 || pos > list.getSize() )
                    System.out.println("Invalid position\n");
                else

                    list.insertAtPos(emp, pos);
                break;                                          
            case 4 : 
                System.out.println("Enter position");
                int p = scan.nextInt() ;
                if (p < 1 || p > list.getSize() )
                    System.out.println("Invalid position\n");
                else
                    list.deleteAtPos(p);
                break;
            case 5 : 
                list.isEmpty();

            case 6 : 
                System.out.println("Size = "+ list.getSize() +" \n");
                break;   
            case 7:
                System.out.println("Enter the name of employee you want to delete:");
                myScanner = new Scanner(System.in);
                name = myScanner.nextLine();

            case 8:
                System.out.println("Enter the name of employee you want to search:");
                myScanner = new Scanner(System.in);
                name = myScanner.nextLine();

            default : 
                System.out.println("Wrong Entry \n ");
                break;   
            }


            /*  Display List  */ 
            list.display();
            System.out.println("\nDo you want to continue (Type y or n) \n");
            ch = scan.next().charAt(0);            
        } while (ch == 'Y'|| ch == 'y');                    
    }

}

就是这样。