- 启动应用
- Web 控制器
- 业务服务
package example;
import net.hasor.boot.Boot;
import net.hasor.boot.BootApplication;
import net.hasor.web.WebApiBinder;
import net.hasor.web.WebModule;
public class Application implements WebModule {
public static void main(String[] args) throws Exception {
try (BootApplication app = Boot.run(args, Application.class)) {
app.join();
}
}
// Serve static files from the classpath under /app/.
@Override
public void loadModule(WebApiBinder binder) {
binder.addClasspathResource("/app/**", "home");
}
}
package example;
import java.util.Collections;
import java.util.Map;
import net.hasor.core.Inject;
import net.hasor.web.annotation.Get;
import net.hasor.web.annotation.MappingTo;
@MappingTo("/hello")
public class HelloController {
@Inject
private HelloService service;
@Get
public Map<String, String> hello() {
return Collections.singletonMap("message", service.greet());
}
}
package example;
import net.hasor.config.Bean;
@Bean
public class HelloService {
public String greet() {
return "Hello, Hasor!";
}
}
