我正在学习 Spring Boot。ApplicationRunner 或任何运行器接口的典型用例是什么?
import org.junit.jupiter.api.Test;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class PersistencedemoApplicationTests implements ApplicationRunner {
@Test
void contextLoads() {
}
@Override
public void run(ApplicationArguments args) throws Exception {
// load initial data in test DB
}
}
Run Code Online (Sandbox Code Playgroud)
这是我知道的一个案例。还要别的吗?
def heapify(A):
for root in xrange(len(A)//2-1, -1, -1):
rootVal = A[root]
child = 2*root+1
while child < len(A):
if child+1 < len(A) and A[child] > A[child+1]:
child += 1
if rootVal <= A[child]:
break
A[child], A[(child-1)//2] = A[(child-1)//2], A[child]
child = child *2 + 1
Run Code Online (Sandbox Code Playgroud)
这是python heapq.heapify()的类似实现。据说在文档中此函数在O(n)中运行。但是,对于n / 2个元素,它似乎执行log(n)操作。为什么是O(n)?
class DockerEngine(Device):
def __init__(self):
super(DockerInfo, self).__init__()
self.docker_id = None
self.host_ip_address = None
self.total_containers = 0
self.running_containers = 0
self.paused_containers = 0
self.stopped_containers = 0
@property
def host_ip_address(self):
return self._host_ip_address
@host_ip_address.setter
def host_it_address(self, ip):
self._host_ip_address = ip
@property
def docker_id(self):
return self._docker_id
@docker_id.setter
def docker_id(self, id):
self._docker_id = id
Run Code Online (Sandbox Code Playgroud)
当我初始化一个 DockerEngine 对象时,它抱怨 in __init__ self.host_ip_address, can't set attribute。
python ×2
python-2.7 ×2
heap ×1
heapq ×1
java ×1
properties ×1
python-3.x ×1
setter ×1
spring ×1
spring-boot ×1