在讲解配置之前,请确保您已经安装了 ACTable,如果您尚未安装,请查看 安装 。
项目的properties配置文件(必备)
在您的web项目上创建个目录比如config下面创建个文件autoCreateTable.properties文件的内容如下:
# actable的配置信息
actable.table.auto=update
actable.model.pack=com.yours.model
actable.database.type=mysql
actable.index.prefix=自己定义的索引前缀#该配置项不设置默认使用actable_idx_
actable.unique.prefix=自己定义的唯一约束前缀#该配置项不设置默认使用actable_uni_
配置解析:
配置信息 | 可选值值信息 | 描述 |
---|---|---|
actable.table.auto |
none | 系统不做任何处理。 |
create | 系统启动后,会先将所有的表删除掉,然后根据model中配置的结构重新建表,该操作会破坏原有数据。 | |
update | 系统启动后,会自动判断哪些表是新建的,哪些字段要修改类型等,哪些字段要删除,哪些字段要新增,该操作不会破坏原有数据。 | |
add | 系统启动后,只做新增,比如新增表/新增字段/新增索引/新增唯一约束的功能,而不会去做修改和删除的操作 (只在版本1.0.9.RELEASE及以上支持)。 | |
actable.model.pack | - | 您的model包路径,多个路径可以用分号或者逗号隔开,会递归这个目录下的全部目录中的java对象,支持类似com.bz.**.entity |
actable.database.type | mysql | 这个是用来区别数据库的,预计会支持这四种数据库mysql/oracle/sqlserver/postgresql,但目前仅支持mysql |
spring的配置文件中需要做如下配置(必备)
1.配置actable需要使用的bean:”com.gitee.sunchenbin.mybatis.actable.manager.“
2.将上面新建的actable的autoCreateTable.properties配置文件读到spring中
3.配置mybatis的配置文件
classpath:com/gitee/sunchenbin/mybatis/actable/mapping//.xml
com.gitee.sunchenbin.mybatis.actable.dao.*
代码示例如下:
<!-- 自动扫描(自动注入mybatis-enhance-actable的Manager)必须要配置,否则扫描不到底层的mananger方法 -->
<context:component-scan base-package="com.gitee.sunchenbin.mybatis.actable.manager.*" />
<!-- 这是mybatis-enhance-actable的功能开关配置文件,其实就是将上面第2点说的autoCreateTable.properties文件注册到spring中,以便底层的mybatis-enhance-actable的方法能够获取到-->
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:config/autoCreateTable.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties" />
</bean>
<!-- myBatis文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
<property name="mapperLocations">
<array>
<value>classpath*:自己的mappring.xml没有可不填</value>
<value>classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml</value>
</array>
</property>
<property name="typeAliasesPackage" value="您自己的model.*没有可不填" />
</bean>
<!-- 如果不使用tk.mybatis需要使用这个bean成如下: -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.gitee.sunchenbin.mybatis.actable.dao.*;您自己的dao.*没有可不填" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>