thanks for pointing out getblocktemplate.
In src/rpc/mining.cpp , i comment out these two lines:
//if (g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0)
// throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Bitcoin is not connected!");
and run one node only.
and getblocktemplate can work. and also cpuminer can work. So it is not necessary to have at least two nodes for mining.