后台环境搭建-ssm+maven多模块

1.maven多模块的创建

1.1 为什么需要进maven多模块的划分:

  • 如果要写一些公共的模块其他的项目都要使用 可以抽取出来
  • 随着项目的越来越大 pom.xml里面内容越来越大,也可以进行抽取到不同的模块里面
  • 编译build 变得越来越长,也要进行划分
  • 如果有些模块 不能被人修改,也可单独抽出

1.2 划分模块

maven模块名 放那些内容
basic-util 工具类:Ajaxresult PageList StringUtils
basic-core 基础核心:核心实现 baseMapper baseService baseDomain baseQuery …
crm-common 项目对应的公共东西,domain,query
crm-mapper 映射器,*Mapper.java *Mapper.xml
crm-service 业务模块
crm1-web web模块提供数据(接口层)

1.3 模块之间的引用关系

  • basic_core 引用 basic_util

  • crm_common 引用 basic_core

  • crm_common 引用 basic_core 间接引用 basic_util

  • crm_mapper 引用 crm_common

  • crm_service 引用 crm_mapper

  • crm_web 引用 crm_service

1.4 配置文件

  • web.xml
  • applicationContext-mvc.xml 写在 crm_web模块
  • applicationContext.xml 写在 crm_service模块

2.新建一个Maven项目(crm-parent)

后台环境搭建-ssm+maven多模块

2.1配置pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>cn.wxy</groupId>
    <artifactId>crm_parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>basic_util</module>
        <module>basic_core</module>
        <module>crm_common</module>
        <module>crm_mapper</module>
        <module>crm_service</module>
        <module>crm_web</module>
        <module>crm_web</module>
        <module>crm_web</module>
    </modules>

    <!-- 公共的jar包 其他的模块都可以引用-->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <!-- spring版本号 -->
        <spring.version>4.1.2.RELEASE</spring.version>
        <!-- mybatis版本号 -->
        <mybatis.version>3.2.1</mybatis.version>
        <!-- log4j日志文件管理包版本 -->
        <slf4j.version>1.7.2</slf4j.version>
        <log4j.version>1.2.17</log4j.version>
        <!-- jackson包版本 -->
        <jackson.version>2.5.0</jackson.version>
        <!-- swagger版本-->
        <springfox.version>2.4.0</springfox.version>
    </properties>

    <dependencies>
        <!--Spring核心-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>

        <!--aop依赖包-->
        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.6.8</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.10</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>cn.wxy</groupId>
            <artifactId>crm_service</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>


    </dependencies>


</project>

2.2 创建子模块

后台环境搭建-ssm+maven多模块

2.3 basic_util模块

  • 用于响应ajax请求信息
package cn.wxy.crm.util;

import lombok.Data;

@Data
public class AjaxResult {
    private Boolean success = true;
    private String message = "操作成功!!!";


    //默认成功
    public AjaxResult() {
    }
    //失败调用
    public AjaxResult(String message) {
        this.success = false;
        this.message = message;
    }

}
  • 用于分页
package cn.wxy.crm.util;

import lombok.Data;

@Data
public class AjaxResult {
    private Boolean success = true;
    private String message = "操作成功!!!";


    //默认成功
    public AjaxResult() {
    }
    //失败调用
    public AjaxResult(String message) {
        this.success = false;
        this.message = message;
    }

}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>crm_parent</artifactId>
        <groupId>cn.wxy</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>basic_util</artifactId>


</project>

2.4 basic_core模块

  • BaseDomain
package cn.wxy.crm.basedomain;

import lombok.Data;

@Data
public class BaseDomain {
    public Long id;
}

  • BaseMapper
package cn.wxy.crm.basemapper;

import java.io.Serializable;
import java.util.List;

public interface BaseMapper<T> {
    //查询所有
    public List<T> findAll();

    //新增
    public void save(T t);

    //删除
    public void delete(Serializable id);

    //修改
    public void update(T t);

    //查询一个
    public T findOne(Serializable id);


}

  • BaseQuery
package cn.wxy.crm.basequery;

public class BaseQuery {
    private Integer currentPage = 1;
    private Integer pageSize = 10;
    public Integer getCurrentPage() {
        return currentPage;
    }
    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }
    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }
}

  • IBaseService
package cn.wxy.crm.baseservice;

import java.io.Serializable;
import java.util.List;

public interface IBaseService<T> {
    //查询所有
    public List<T> findAll();

    //查询一个
    public T findOne(Serializable id);

    //新增
    public void save(T t);

    //删除
    public void delete(Serializable id);

    //修改
    public void update(T t);

}

  • BaseServiceImpl
package cn.wxy.crm.baseservice.impl;

import cn.wxy.crm.basemapper.BaseMapper;
import cn.wxy.crm.baseservice.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

//不需要加@Service,子类继承时添加
//类级别事务为读事务,分别在增删改的方法上面加写事务
//baseService 实现spring事务
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    public List<T> findAll() {
        return baseMapper.findAll();
    }

    public T findOne(Serializable id) {
        return baseMapper.findOne(id);
    }

    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Transactional
    public void delete(Serializable id) {
        baseMapper.delete(id);
    }

    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }
}

  • pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>crm_parent</artifactId>
        <groupId>cn.wxy</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>basic_core</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- 引用basic-->
        <dependency>
            <groupId>cn.wxy</groupId>
            <artifactId>basic_util</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

</project>

2.5 crm_common模块

  • pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>crm_parent</artifactId>
        <groupId>cn.wxy</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>crm_common</artifactId>

    <dependencies>
        <dependency>
            <groupId>cn.wxy</groupId>
            <artifactId>basic_core</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>


</project>
  • User
package cn.wxy.crm.domain;

import cn.wxy.crm.basedomain.BaseDomain;
import lombok.Data;

@Data
public class User extends BaseDomain {
    public String name;
}

2.6 crm_mapper模块

  • pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>crm_parent</artifactId>
        <groupId>cn.wxy</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>crm_mapper</artifactId>

    <dependencies>
        <dependency>
            <groupId>cn.wxy</groupId>
            <artifactId>crm_common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>


        <!--Mybatis集成-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.2.0</version>
        </dependency>
        <!--log4j-->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>

        <!--slf4j-->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
            <scope>test</scope>
        </dependency>

        <!--数据库连接驱动-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.46</version>
        </dependency>
        <!--数据库连接池-->
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.2.2</version>
        </dependency>
        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>1.5.3</version>
        </dependency>
        <dependency>
            <groupId>cn.wxy</groupId>
            <artifactId>basic_core</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>cn.wxy</groupId>
            <artifactId>basic_core</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

</project>
  • 在resources下创建 UserMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.wxy.crm.mapper.UserMapper">
    <select id="findAll" resultType="User">
        select * from t_user
    </select>
</mapper>
  • UserMapper
package cn.wxy.crm.mapper;

import cn.wxy.crm.basemapper.BaseMapper;
import cn.wxy.crm.common.domain.User;

public interface UserMapper extends BaseMapper<User> {

}

2.7 crm_service模块

  • pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>crm_parent</artifactId>
        <groupId>cn.wxy</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>crm_service</artifactId>

    <dependencies>
        <dependency>
            <groupId>cn.wxy</groupId>
            <artifactId>crm_mapper</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

</project>
  • IUserService
package cn.wxy.crm.service;

import cn.wxy.crm.baseservice.IBaseService;
import cn.wxy.crm.common.domain.User;

public interface IUserService extends IBaseService<User> {

}

  • UserServiceImpl
package cn.wxy.crm.service.impl;

import cn.wxy.crm.baseservice.impl.BaseServiceImpl;
import cn.wxy.crm.common.domain.User;
import cn.wxy.crm.mapper.UserMapper;
import cn.wxy.crm.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly =true)
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService {

    @Autowired
    private UserMapper userMapper;

    //这里也User要实现的方法,curd已经在父类里面实现了

}

  • resources文件中的配置文件(applicationContext.xml、db.properties、log4j.properties)

  • applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!--扫描的包-->
    <context:component-scan base-package="cn.wxy.crm.service"/>

    <!-- Jdbc配置文件 -->
    <context:property-placeholder location="classpath:db.properties" />

    <!-- 数据源dataSource -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

    <!--Mybatis核心对象-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 注入数据源 -->
        <property name="dataSource" ref="dataSource" />
        <!-- 配置mybatis (mapper)映射器路径 -->
        <property name="mapperLocations" value="classpath*:cn/wxy/crm/mapper/*Mapper.xml" />
        <!-- 配置mybatis 类型别名 -->
        <property name="typeAliasesPackage">
            <value>
                cn.wxy.crm.common.domain
                cn.wxy.crm.common.query
            </value>
        </property>
    </bean>

    <!--注入映射器,一劳永逸的做法-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.wxy.crm.mapper"></property>
    </bean>

    <!--事务管理-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!--以注解的方式进行事务管理-->
    <tx:annotation-driven transaction-manager="transactionManager"/>


</beans>
  • db.properties
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///crm_parent?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456
  • log4j.properties
log4j.rootLogger=ERROR, stdout
#log4j.rootLogger=NONE
log4j.logger.cn.wxy=TRACE
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

2.8 crm_web模块

  • pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>crm_parent</artifactId>
        <groupId>cn.wxy</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>crm_web</artifactId>

    <dependencies>
        <dependency>
            <groupId>cn.wxy</groupId>
            <artifactId>crm_service</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <!--SpringMVC-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!--文件上传-->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.2</version>
        </dependency>
        <!--jackson-->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <!-- JSTL标签类 -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!--servlet-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

        <!-- swagger引入包-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${springfox.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${springfox.version}</version>
        </dependency>


    </dependencies>

</project>
  • UserController
package cn.wxy.crm.web.controller;


import cn.wxy.crm.common.domain.User;
import cn.wxy.crm.service.IUserService;
import cn.wxy.crm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/list")
    @ResponseBody
    public List<User> list() {
       return userService.findAll();
    }

    //POST方式 新增
    @RequestMapping(value="/update",method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult update(@RequestBody User user){
        System.out.println("修改调用...."+user);
        return new AjaxResult();
    }

    //PUT请求 新增 {name:"xxx"}
    @RequestMapping(value="/add",method = RequestMethod.PUT)
    @ResponseBody
    public AjaxResult add(@RequestBody  User user){
        System.out.println("新增调用...."+user);
        return new AjaxResult();
    }

    //delete 删除   delete  /user/123 springmvc
    @RequestMapping(value="/{id}",method = RequestMethod.DELETE)
    @ResponseBody
    public AjaxResult delete(@PathVariable("id") Long id){
        System.out.println("删除调用id...."+id);
        return new AjaxResult();
    }
    //get方式请求    get    /user/456
    @RequestMapping(value="/{id}",method = RequestMethod.GET)
    @ResponseBody
    public List<User> findAll(@PathVariable("id") Long id){
        System.out.println("查询参数的id:"+id);
        return userService.findAll();
    }


    @RequestMapping(value="/findAll",method = RequestMethod.PATCH)
    @ResponseBody
    public AjaxResult findAll(){
        System.out.println("删除调用....");
        return new AjaxResult();
    }

}

  • resources文件(applicationContext-mvc.xml)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
    <context:component-scan base-package="cn.wxy.crm.web.controller" />

    <!-- 启动SpringMVC的注解功能 -->
    <mvc:annotation-driven/>

    <!--静态资源放行-->
    <mvc:default-servlet-handler/>

    <!-- 定义跳转的文件的前后缀 ,视图解析器配置-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!-- 配置文件上传解析器 -->
    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 默认编码 -->
        <property name="defaultEncoding" value="utf-8" />
        <!-- 文件大小最大值 -->
        <property name="maxUploadSize" value="10485760000" />
    </bean>


</beans>
  • webapp下的web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
    <display-name>crm</display-name>
    <!-- Spring的配置文件 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <!--Spring监听器 ApplicationContext 载入 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Spring MVC 核心配置开始 -->
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- 编码过滤器 -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
后台环境搭建-ssm+maven多模块后台环境搭建-ssm+maven多模块 可乐不加冰哦 发布了7 篇原创文章 · 获赞 0 · 访问量 87 私信 关注
上一篇:论文:Elastic Scheduling for Microservice Applications in Clouds (云环境下微服务应用的弹性调度)


下一篇:Codeforces Round #771 (Div. 2)思路分享