1. Create a server-side controller in Apex and use the @AuraEnabled annotation to enable access to the controller method.
public with sharing class SimpleServerSideController {
//Use @AuraEnabled to enable client- and server-side access to the method
@AuraEnabled
public static String serverEcho(String firstName) {
return ('Hello from the server, ' + firstName);
}
}
In addition to using the @AuraEnabled annotation, your Apex controller must follow these requirements. Methods must be static and marked public or global. Non-static methods aren’t supported. If a method returns an object, instance methods that retrieve the value of the object’s instance field must be public.
In addition to using the @AuraEnabled annotation, your Apex controller must follow these requirements.
Methods must be static and marked public or global. Non-static methods aren’t supported.
If a method returns an object, instance methods that retrieve the value of the object’s instance field must be public.
Refer this link for more info