代码结构
如何将mapper.xml文件打入jar包
在项目的pom.xml文件中包含如下代码即可:
<build>
<finalName>项目名</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
如何方便别的系统引入并使用
- 写一个配置类:
@ComponentScan({"需要扫描的包目录"})
@MapperScan("需要扫描的mapper文件目录(xxMapper.java文件的目录)")
public class XxAutoConfiguration {
public XxAutoConfiguration() {
}
}
- 写一个快速引用类:
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Import({XxAutoConfiguration.class})
@Documented
@Inherited
public @interface EnableXx {
}
打jar包
mvn clean package -Dmaven.test.skip=true
引入并使用该jar包
- 在主项目的pom.xml文件中引入该jar包
- 在主文件(XxApplication.java)中的相应位置写
@EnableXx