1. 程式人生 > 實用技巧 >qlexpress 另外一個表示式引擎

qlexpress 另外一個表示式引擎

1.新建一個springboot專案

1.1 寫一個介面,定義一個say方法

public class HelloService {
private HelloProperties helloProperties;

public HelloService(HelloProperties helloProperties) {
this.helloProperties = helloProperties;
}

public HelloProperties getHelloProperties() {
return helloProperties;
}

public void setHelloProperties(HelloProperties helloProperties) {
this.helloProperties = helloProperties;
}

public String say(){
return helloProperties.getName();
}
}
1.2 定義HelloProperties ,
@ConfigurationProperties(prefix = "com.zy")
public class HelloProperties {
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
1.3 主配置類 啟動proeperties
@Configuration
@ConditionalOnWebApplication
@EnableConfigurationProperties(HelloProperties.class)
public class HelloConfiguration {
@Autowired
private HelloProperties helloProperties;


@Bean
public HelloService helloService(){
return new HelloService(helloProperties);
}
}
1.4 在resources下新建METAfactories檔案,在裡面寫上
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.zy.HelloConfiguration

1.5 打包該專案 jar包

2.新建另一個springboot專案

2.1 匯入上面專案的maven
<dependency>
<groupId>org.example</groupId>
<artifactId>zy-spring-boot-starter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

2.2 application.properties中新增
com.zy.name=zhouyang

2.3新建一個HelloController

@RestController
public class HelloController {
@Resource
private HelloService helloService;
@RequestMapping("hello")
public String hello(){
return helloService.say();
}
}
2.4 測試