maven创建多模块项目fREemark+springMVC+mybatis+mybatis 自动生成

来源:互联网 发布:动画演示制作软件 编辑:程序博客网 时间:2024/06/02 02:15

本文参照  http://blog.csdn.net/chendaoqiu/article/details/46554139 ;

搭建过程,以及碰到的问题 + mybatis自动生成


代码下载地址:http://download.csdn.net/detail/u010634066/9641212


shushang-project
    |—-pom.xml 
    |—-shuang-project-utils 
        |—-pom.xml 
    |—-shuang-project-domain 
        |—-pom.xml 
    |—-shuang-project-dao 
        |—-pom.xml 
    |—-shuang-project-service 
        |—-pom.xml 
    |—-shuang-project-web 
        |—-pom.xml 

|—-shuang-project-web-backend

|—-pom.xml 


创建项目 :省略

结构图:



我主要说明一下需要注意的地方 + mybatis 自动生成


①   因为是多模块;我们的配置文件是放在  shuang-project-web-backend 里面的

如果扫描mapper.xml 的配置

<property name="mapperLocations" value="classpath:com/mote/mapper/*.xml"></property>


  会出现找不到的情况;

 解决一:

classpath*:

classpath  和  classpath* 的区别

classpath 和 classpath* 区别: 
classpath:只会到你的class路径中查找找文件; 
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找.

按照上面的修改之后  还是扫描不到.xml文件;

后发现:



.xml文件一定要放在resource文件夹下面;  否则要加上上图中的代码才能找到;

 <!--下面这段一定要加  因为在字段扫描xml文件的时候 不能扫描resource之外的文件,除非自己指定 --><!-- <build>     <resources>         <resource>             <directory>src/main/java</directory>         </resource>     </resources> </build>-->

问题  二 :事务不生效

原因:在扫描Controller 的时候将services 层也扫描进来了;  除去Services   或者只扫描Controller


<!-- 把标记了@Controller注解的类转换为bean --><!-- 下面一点要将services 注解的规避掉;不能扫描services 否则事务不生效--><context:component-scan base-package="com.mote">   <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/></context:component-scan>

问题  三 :.NoClassDefFoundError: org/springframework/ui/freemarker/FreeMarkerConfigurationFactory



缺少jar
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>4.1.6.RELEASE</version>
</dependency>








自动生成 




看项目里面的配置





0 0
原创粉丝点击