CRM项目总结

CRM项目总结

1.项目内容:

Crm项目是一款客户关系管理系统,主要实现的功能模块有:登录和登出模块,市场活动模块,线索模块,客户模块,联系人模块,交易模块,统计图表中扇形数据图的实现等。项目基于spring, springMVC, Mybatis 三大后端框架,结合前端bootstrap,js,jquery,插件模块技术完成页面功能。

2.项目收获

从代码层面:
掌握了整个web项目后端开发流程:
第一步:从前端分析,在前端的那个组件触发事件,需要传递什么参数,发送的是同步请求还是异步请求,返回的数据需要什么类型,发给哪个controller,发什么请求等等。

第二步:Controller收集参数,需要分析前端传过来的数据是要封装成一个实体类对象,还是一个map集合等等,如果前端需要的数据是json,Controller层需要@Responsebody注解,则返回的数据,前端会以json对象传递,如返回对象,则前端解析的会是{key=value, key=calue,…}的形式,如果返回list集合,前端解析的会是【{key=value, key=calue,…},{key=value, key=calue,…},{key=value, key=calue,…}…】的形式等等,controller需要明确调用service哪个方法。

第三步:Service需要根据需求,调用相关的mapper; 一般简单业务直接mapper,结果就是符合需求的;复杂业务,一般需要调多个mapper,让mapper返回的结果,作为另外一些mapper的输入,共同协调完成业务;

第四步:mapper根据需求,写好相关的sql代码,操作相关的表。Mapper这里需要注意接口id不要写错,一般运行起来不会给你报错,很容易犯这种低级错误。

编写代码一般从前往后分析,但是编写代码需从后往前编写。

技术层面:学会了一些前端插件的使用,一般跟业务无关,实现复杂的功能,往往可以寻求插件的帮助。
前端插件的使用:
1.首先看懂插件的使用文档,他需要传回什么参数,具体怎么使用需要根据使用文档完成
本次学习使用的是jquery相关的插件,所以前端一般步骤:
A.引入插件链接,B.配合jquery文件使用,C.确定该插件需不需要容器,D.通过该容器调用相关插件的触发方法。

Ssm项目整合中配置文件
ApplicationContext.xml文件
扫描注解:service层

<?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:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:task="http://www.springframework.org/schema/task"
       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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 加载系统配置文件
<context:property-placeholder location="classpath:*.properties" />-->
    <!-- 扫描注解 -->
    <context:component-scan base-package="com.bjpowernode.crm.settings.service" />
    <context:component-scan base-package="com.bjpowernode.crm.workbench.service" />
    <!-- 导入数据相关配置 -->
    <import resource="applicationContext-datasource.xml" />
</beans>

applicationContext-datasource.xml文件
配置相关数据源
配置mapper注解扫描器配置
给一些方法添加事务

<?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:aop="http://www.springframework.org/schema/aop"
       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-4.3.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
   <!-- 配置数据源 -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
      <property name="username" value="root"/>
      <property name="password" value="123456"/>
      <property name="url" value="jdbc:mysql://localhost:3306/crm2008?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
   </bean>
    <!-- 配置SqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
      <!-- 必须注入属性dataSource -->
        <property name="dataSource" ref="dataSource"/>
        <!-- 如果mybatis没有特殊的配置(比如别名等),configLocation可以省去 ;否则,不能省略-->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
   </bean>
    <!-- mapper注解扫描器配置,扫描@MapperScan注解,自动生成代码对象 -->
    <bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.bjpowernode.crm.settings.mapper,
                                            com.bjpowernode.crm.workbench.mapper"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>

    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="dataSource"/>
   </bean>
    <!-- 配置事务 -->
    <aop:config>
      <aop:pointcut expression="execution(* com.bjpowernode.crm..service.*.*(..))" id="allMethodPointcut"/>
      <aop:advisor advice-ref="txAdvice" pointcut-ref="allMethodPointcut"/>
   </aop:config>
   <tx:advice id="txAdvice" transaction-manager="transactionManager">
      <tx:attributes>
         <tx:method name="add*" propagation="REQUIRED" rollback-for="Exception"/>
         <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/>
         <tx:method name="edit*" propagation="REQUIRED" rollback-for="Exception"/>
         <tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/>
         <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception"/>
         <tx:method name="do*" propagation="REQUIRED" rollback-for="Exception"/>
         <tx:method name="*" propagation="REQUIRED" read-only="true"/>
      </tx:attributes>
   </tx:advice>
</beans>

applicationContext_mvc文件
spring mvc 扫描包下的controller
配置注解驱动
配置视图解析器
配置拦截的请求:什么请求需要拦截,一般是针对用户权限
配置文件上传解析器

<?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:p="http://www.springframework.org/schema/p"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<!-- dispatcherServlet截获所有URL请求 -->
    <mvc:default-servlet-handler />
    <!-- spring mvc 扫描包下的controller -->
    <context:component-scan base-package="com.bjpowernode.crm.web.controller"/>
    <context:component-scan base-package="com.bjpowernode.crm.settings.web.controller"/>
    <context:component-scan base-package="com.bjpowernode.crm.workbench.web.controller"/>
    <!-- 配置注解驱动 -->
    <mvc:annotation-driven/>
    <!-- 配置视图解析器 -->
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
    <mvc:interceptors>
        <mvc:interceptor>
            <!--配置拦截的请求-->
            <mvc:mapping path="/settings/**"/>
            <mvc:mapping path="/workbench/**"/>
            <!--配置排除拦截的请求(优先级高)-->
            <mvc:exclude-mapping path="/settings/qx/user/toLogin.do"/>
            <mvc:exclude-mapping path="/settings/qx/user/login.do"/>
            <!--拦截器类-->
            <bean class="com.bjpowernode.crm.settings.web.interceptor.LoginInterceptor"/>
        </mvc:interceptor>
    </mvc:interceptors>
    <!-- 配置文件上传解析器 id:必须是multipartResolver-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="#{1024*1024*80}"/>
        <property name="defaultEncoding" value="utf-8"/>
    </bean>
</beans>

Mybatis_config.xml
配置了一些数据库日志文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
    <setting name="logImpl" value="STDOUT_LOGGING"/>
</settings>
    <typeAliases>
        <package name="com.bjpowernode.crm.model"/>
    </typeAliases>
    <mappers>
        <package name="com.bjpowernode.crm.mapper"/>
    </mappers>
</configuration>

常见错误问题:

1.一般将项目部署到服务器后,在测试过程中,点击某一组件没有反应,代码控制台那里也没有报错,这个时候可以在浏览器的检查功能下进行调试,看浏览器给你什么反应,一般会反馈相关错误,根据相关反馈解决问题。

2.使用maven搭建项目时,有时clean之后再进行部署发现部署不起来,说找不到相关配置文件,是因为此时构建出来的项目的target文件没有获取到相关配置文件,只需要clean之后,继续点击compile之后就能实现部署了。

3.项目搭建的目录要有一定规范,在维护过程中才不容易出错。
如:业务模块按业务模块构建好相关的domain实体类包,mapper包,service包,controller包,系统模块按系统构建好相关的domain实体类包,mapper包,service包,controller包。整个项目普遍用到的功能可以定义一个工具类放相关方法,和数据。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值