You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							95 lines
						
					
					
						
							2.7 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							95 lines
						
					
					
						
							2.7 KiB
						
					
					
				| = 平台扩展 | |
| == 添加自定义应用启动器 | |
| 所谓应用启动器就是指当应用启动成功后需要进行的附加操作,例如系统初始化检查等,具体实现步骤如下: | |
| 
 | |
| === 编写启动器类 | |
| [source,java] | |
| ---- | |
| package io.sc.platform.security.jpa.initializer; | |
| 
 | |
| import io.sc.platform.core.initializer.ApplicationInitializer; | |
| import org.springframework.context.ApplicationContext; | |
| import org.springframework.jdbc.core.JdbcTemplate; | |
| 
 | |
| public class AdministratorRoleAndUserInitializer implements ApplicationInitializer { <1> | |
| 	private JdbcTemplate jdbcTemplate; | |
| 
 | |
| 	@Override | |
| 	public void init(ApplicationContext applicationContext) {                       <2> | |
| 		this.jdbcTemplate =applicationContext.getBean(JdbcTemplate.class); | |
| 	} | |
| 
 | |
| 	@Override | |
| 	public void execute() throws Exception {                                        <3> | |
| 
 | |
| 	} | |
| } | |
| ---- | |
| <1> 启动器类必须实现 ApplicationInitializer 接口 | |
| <2> 启动器初始化,由平台自动调用,并将 spring application context 作为参数传入 | |
| <3> 启动器初始化的具体操作 | |
| 
 | |
| === 添加 SPI 服务实现文件 | |
| image::platform-extension/001.png[,80%] | |
| 
 | |
| == 添加自定义安装项 | |
| 所谓安装项就是指当应用启动安装程序后,安装程序向导中的某一步,具体实现步骤如下: | |
| 
 | |
| === 编写安装项类 | |
| [source,java] | |
| ---- | |
| package io.sc.platform.security.jpa.installer; | |
| 
 | |
| import io.sc.platform.installer.InstallerItem; | |
| import io.sc.platform.installer.InstallerProgress; | |
| import io.sc.platform.jdbc.service.DatasourceService; | |
| import org.springframework.context.ApplicationContext; | |
| import org.springframework.core.Ordered; | |
| 
 | |
| import java.util.*; | |
| 
 | |
| public class AdministratorInstallerItem implements InstallerItem { <1> | |
| 	@Override | |
| 	public int getOrder() { return 2000; }      <2> | |
| 
 | |
| 	@Override | |
| 	public String getTemplateLoaction() { | |
| 		return "io/sc/platform/security/jpa/view/installer_administrator.html"; | |
| 	} | |
| 
 | |
| 	@Override | |
| 	public void install(Map<String, String> config, InstallerProgress installerProgress, ApplicationContext applicationContext) throws Exception { | |
| 		......  <3> | |
| 	} | |
| } | |
| ---- | |
| <1> 每个安装器都需要实现 InstallerItem 接口 | |
| <2> 返回安装器的顺序 | |
| <3> 具体安装时的操作 | |
| 
 | |
| === 添加 SPI 服务实现文件 | |
| image::platform-extension/002.png[,80%] | |
| 
 | |
| == Restful API 返回结果 | |
| === 格式 | |
| [source,json] | |
| ---- | |
| { | |
|   "code" : 200,                 <1> | |
|   "messageI18nKey" : "success", <2> | |
|   "message" : "success",        <3> | |
|   "data" : {                    <4> | |
|   } | |
| } | |
| ---- | |
| <1> 返回状态码, 不同于 http 状态码 | |
| <2> 消息多语言消息键 | |
| <3> 消息多语言消息 | |
| <4> 数据体 | |
| 
 | |
| === 返回码说明 | |
| |=== | |
| | 代码       | 说明                 | 示例 | |
| | 200       | 成功                | | |
| | 1001      | 数据验证错误         | | |
| |=== |