Temporal networks provide a general framework to capture time-varying interactions of complex systems. The interevent time (IET), the time interval between two successive interactions, is a common statistic to characterize the structure of temporal networks. Previous findings support that burstiness, the IET distribution to be heavy-tailed, is ubiquitous in the activity of nodes and links on empirical temporal networks. However, an analytical method for generating such a non-trivial phenomenon is still lacking. Here we propose a spanningtree method to construct temporal networks with any consistent activity pattern, including bursty and Poissonian activity patterns. Specifically, our method theoretically ensures that the synthetic IET distribution of every single node/link can match with any targeted distribution fulfilling a consistency (necessary and sufficient) condition, and the underlying topology based on which our construction process is carried out can be either static or time-varying. Our method reproduces the observed burstiness in empirical datasets and uncovers the laws of temporal interactions, which is a key determinant to further study dynamical processes in real-world complex systems.