博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何创建一个完整的CRM工程
阅读量:6990 次
发布时间:2019-06-27

本文共 12384 字,大约阅读时间需要 41 分钟。

CRM包括很多功能模块,如登录,分页,新建,客户销售机会管理等,在这里zh
00_jar包
antlr-2.7.7.jar
c3p0-0.9.2.1.jar
com.springsource.net.sf.cglib-2.2.0.jar
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
commons-logging-1.1.3.jar
dom4j-1.6.1.jar
ehcache-core-2.4.3.jar
hibernate-c3p0-4.2.4.Final.jar
hibernate-commons-annotations-4.0.2.Final.jar
hibernate-core-4.2.4.Final.jar
hibernate-ehcache-4.2.4.Final.jar
hibernate-entitymanager-4.2.4.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
javassist-3.15.0-GA.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.1.Final.jar
mchange-commons-java-0.2.3.4.jar
ojdbc14.jar
slf4j-api-1.6.1.jar
spring-aop-4.0.0.RELEASE.jar
spring-aspects-4.0.0.RELEASE.jar
spring-beans-4.0.0.RELEASE.jar
spring-context-4.0.0.RELEASE.jar
spring-core-4.0.0.RELEASE.jar
spring-data-commons-1.6.2.RELEASE.jar
spring-data-jpa-1.4.2.RELEASE.jar
spring-expression-4.0.0.RELEASE.jar
spring-jdbc-4.0.0.RELEASE.jar
spring-orm-4.0.0.RELEASE.jar
spring-tx-4.0.0.RELEASE.jar
spring-web-4.0.0.RELEASE.jar
spring-webmvc-4.0.0.RELEASE.jar
 
 
01_配web.xml
<
context-param
>
          
<
param-name
>
contextConfigLocation
</
param-name
>
          
<
param-value
>
classpath:applicationContext*.xml
</
param-value
>
     
</
context-param
>
 
     
<
listener
>
          
<
listener-class
>
org.springframework.web.context.ContextLoaderListener
</
listener-class
>
     
</
listener
>
     
     
<!-- 配置 OpenEntityManagerInViewFilter. 解决 JPA 懒加载问题的 Filter -->
     
<
filter
>
          
<
filter-name
>
OpenEntityManagerInViewFilter
</
filter-name
>
          
<
filter-class
>
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
</
filter-class
>
     
</
filter
>
     
     
<
filter-mapping
>
          
<
filter-name
>
OpenEntityManagerInViewFilter
</
filter-name
>
          
<
url-pattern
>
/*
</
url-pattern
>
     
</
filter-mapping
>
     
     
<!-- 配置字符编码过滤器 -->
     
<
filter
>
          
<
filter-name
>
CharacterEncodingFilter
</
filter-name
>
          
<
filter-class
>
org.springframework.web.filter.CharacterEncodingFilter
</
filter-class
>
     
</
filter
>
     
     
<
filter-mapping
>
          
<
filter-name
>
CharacterEncodingFilter
</
filter-name
>
          
<
url-pattern
>
/*
</
url-pattern
>
     
</
filter-mapping
>
     
     
<!--
     配置可以把 POST 请求解析为 PUT 或 DELETE 请求的 Filter.
  注意: 该 Filter 必须配置在 CharacterEncodingFilter 的后面
     否则会导致 CharacterEncodingFilter 无效.
     -->
     
<
filter
>
          
<
filter-name
>
HiddenHttpMethodFilter
</
filter-name
>
          
<
filter-class
>
org.springframework.web.filter.HiddenHttpMethodFilter
</
filter-class
>
     
</
filter
>
     
     
<
filter-mapping
>
          
<
filter-name
>
HiddenHttpMethodFilter
</
filter-name
>
          
<
url-pattern
>
/*
</
url-pattern
>
     
</
filter-mapping
>
     
     
     
<
servlet
>
          
<
servlet-name
>
springDispatcherServlet
</
servlet-name
>
          
<
servlet-class
>
org.springframework.web.servlet.DispatcherServlet
</
servlet-class
>
          
<
load-on-startup
>
1
</
load-on-startup
>
     
</
servlet
>
 
     
<
servlet-mapping
>
          
<
servlet-name
>
springDispatcherServlet
</
servlet-name
>
          
<
url-pattern
>
/
</
url-pattern
>
     
</
servlet-mapping
>
02_配置springDispatcherServlet-sevlet.xml
  
<!-- 配置自动扫描的包: 注意. 只扫描 @Controller 和 @ControllerAdivce 的 bean -->
<
context:component-scan
base-package
=
"com.atuigu.crm"
use-default-filters
=
"false"
>
 
<
context:include-filter
type
=
"annotation"
expression
=
"org.springframework.stereotype.Controller"
/>
 
          
<
context:include-filter
type
=
"annotation"
expression
=
"org.springframework.web.bind.annotation.ControllerAdvice"
/>
     
</
context:component-scan
>
     
     
<!-- 配置视图解析器 -->
<
bean
class
=
"org.springframework.web.servlet.view.InternalResourceViewResolver"
>
          
<
property
name
=
"prefix"
value
=
"/WEB-INF/views/"
></
property
>
          
<
property
name
=
"suffix"
value
=
".jsp"
></
property
>
 
</
bean
>
 
     
<!-- 配置能够解析静态 -->
     
<
mvc:default-servlet-handler
/>
     
     
<!-- 配置 mvc:annotation-driven -->
     
<
mvc:annotation-driven
></
mvc:annotation-driven
>
     
03_配置applicationContext.xml
<description>Spring 公共配置</description>
     <!-- 配置自动扫描的包: 注意不扫描 @Controller 注解和 @ControllerAdvice 注解的 bean -->
     <context:component-scan base-package="com.atguigu.crm">
          <context:exclude-filter type="annotation"
               expression="org.springframework.stereotype.Controller" />
          <context:exclude-filter type="annotation"
               expression="org.springframework.web.bind.annotation.ControllerAdvice" />
     </context:component-scan>
    
     <!-- 配置 C3P0 数据源 -->
     <!-- 导入资源文件 -->
     <context:property-placeholder location="classpath:application.properties"/>
     <!-- 配置数据库连接池 -->
     <bean id="dataSource"
          class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
          <property name="driverClass" value="${jdbc.driver}" />
          <property name="url" value="${jdbc.url}" />
          <property name="username" value="${jdbc.username}" />
          <property name="password" value="${jdbc.password}" />
     </bean>
    
     <!-- 整合 JPA: 配置 JPA 的 EntityManagerFactory -->
     <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
          <property name="dataSource" ref="dataSource"></property>
          <property name="jpaVendorAdapter">
               <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
          </property>
          <property name="packagesToScan" value="com.atguigu.crm"></property>
          <property name="jpaProperties">
               <props>
                    <!-- 二级缓存相关 -->
                    <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
                    <prop key="net.sf.ehcache.configurationResourceName">ehcache-hibernate.xml</prop>
                   
                    <!-- 生成的数据表的列的映射策略 -->
                    <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
                   
                    <!-- hibernate 基本属性 -->
                    <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.format_sql">true</prop>
                    <prop key="hibernate.hbm2ddl.auto">update</prop>
               </props>
          </property>
     </bean>
     <!-- 配置事务管理器 -->
     <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
          <property name="entityManagerFactory" ref="entityManagerFactory"></property>
     </bean>
    
     <!-- 配置支持基于注解的事务 -->
     <tx:annotation-driven transaction-manager="transactionManager"/>
    
     <!-- 配置 SpringData -->
     <jpa:repositories base-package="com.atguigu.crm"
          entity-manager-factory-ref="entityManagerFactory"></jpa:repositories>
</beans>
 
 
 
04_配置application.properties
 
#jdbc.driver=com.mysql.jdbc.Driver
#jdbc.url=jdbc:mysql:///crm5?useUnicode=true&characterEncoding=utf-8
#jdbc.username=root
#jdbc.password=1230
jdbc.driver=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
jdbc.username=atguigu
jdbc.password=atguigu
jdbc.pool.maxIdle=5
jdbc.pool.maxActive=40
 
05_配置ehcache-hibernate.xml
<ehcache updateCheck="false" name="hibernateCache">
     <diskStore path="java.io.tmpdir/ehcache/crm/hibernate" />
     <!-- DefaultCache setting. -->
     <defaultCache
          maxElementsInMemory="10000"
          eternal="false"
          timeToIdleSeconds="300"
          timeToLiveSeconds="600"
          overflowToDisk="true" />
    
     <!-- 
     <cache
          name="com.atguigu.crm.entity.User"
          maxElementsInMemory="1000"
          eternal="true"
          overflowToDisk="true" />
     -->
         
</ehcache>
 
06_配置i18n.proerties
user.login.disabled=\u7528\u6237\u88AB\u9501\u5B9A!
 
07_完成登录操作(jsp页面)
 
[1].在index.jsp里面
 
<jsp:forward page="/WEB-INF/views/login.jsp"></jsp:forward> 
 
【2】.login.jsp 
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/commons/common.jsp" %>
   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<HEAD>
     <TITLE>客户关系管理系统</TITLE>
     <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=GB2312">
    
     <script>
          function doSubmit(){
               document.forms[0].submit();
          }
     </script>
 
<table width="100%">
                              <tr>  <th>
                                        用户名
                                   </th>     <td>
                                        <input type="text" name="name" value="${name }" />
                                   </td>                   </tr>
                              <tr>
                                   <th>
                                        密码
                                   </th>
                                   <td>
                                        <input type="password" name="password" />
                                   </td>
                              </tr>
                             
                              <tr>
                                   <td>
                                        &nbsp;&nbsp;&nbsp;
                                   </td>
                                   <td>
                                        <img οnclick="document.forms[0].submit();" style="cursor: hand;"
                                             src="${cp}/static/images/login/login_button.jpg" width="73" height="25">
                                   </td>
                              </tr>
                         </table>
 
 
 
08—完成登录操作功能模块(entity类)
[0]超级类
@MappedSuperclass
public abstract class
IdEntity {
     protected Long id;
     @Id
     @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="CRM_SEQ")
     @SequenceGenerator(name="CRM_SEQ", sequenceName="CRM_SEQ", allocationSize=1)
     public Long getId() {
          return id;
     }
     public void setId(Long id) {
          this.id = id;
     }
    
}
 
 
【1】.User类
 
@Entity
@Table(name="
USERS")
public class
User extends IdEntity{
     private String name;
     private String password;
     private int enabled ;    
     //盐值, 进行密码加密
     private String salt;
     //该用户拥有的角色
     private Role role;
     public User() {
          // TODO Auto-generated constructor stub     }
    
     public User(Long id) {
          this.id = id;     }
 
     public String getName() {
         return name;     }
     public void setName(String name) {
          this.name = name;     }
     public String getPassword() {
          return password;     }
     public void setPassword(String password) {
          this.password = password;     }
     public int getEnabled() {
          return enabled;     }
     public void setEnabled(int enabled) {
          this.enabled = enabled;
     }
    
     public String getSalt() {
          return salt;     }
     public void setSalt(String salt) {
          this.salt = salt;     }
     @ManyToOne
     @JoinColumn(name="ROLE_ID")
     public Role getRole() {
          return role;     }
 
     public void setRole(Role role) {
          this.role = role;     }
     @Transient
     public Collection<String> getRoleList() {
          Collection<String> roles =  new ArrayList<>();
         
          if(role != null){
               for(Authority authority: role.getAuthorities()){
                    roles.add(authority.getName());   }        }         
          return roles;     }}
 
【2】Roles类
 
@Table(name="
ROLES")
@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class
Role extends IdEntity {
     // 角色名称
     private String name;
     // 角色描述
     private String description;
     // 角色状态: 角色是否可用
     private boolean enabled;
     // 角色拥有的权限
     private List<Authority> authorities = new ArrayList<>();
     //该角色分配给了哪些用户
     private Set<User> users = new HashSet<>();
     public String getName() {
          return name;
     }
     public void setName(String name) {
          this.name = name;
     }
     public String getDescription() {
          return description;     }
     public void setDescription(String description) {
          this.description = description;     }
     public boolean isEnabled() {
          return enabled;     }
     public void setEnabled(boolean enabled) {
          this.enabled = enabled;     }
     @ManyToMany
     @JoinTable(
          name="ROLE_AUTHORITY",
          joinColumns={@JoinColumn(name="ROLE_ID")},
          inverseJoinColumns={@JoinColumn(name="AUTHORITY_ID")}
     )
     @Fetch(FetchMode.JOIN)
     @OrderBy("ID")
     @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
     public List<Authority> getAuthorities() {
          return authorities;     }
     public void setAuthorities(List<Authority> authorities) {
          this.authorities = authorities;     }
    
     public void setAuthorities2(List<String> authorities){
          this.authorities.clear();
          for(String authorityId: authorities){
               this.authorities.add(new Authority(Long.parseLong(authorityId)));         }     }
    
     @Transient
     public List<String> getAuthorities2(){
          List<String> authorites = new ArrayList<>();
          for(Authority authority:this.authorities){
               authorites.add("" + authority.getId());         }
         
          return authorites;     }
     @OneToMany(mappedBy="role")
     public Set<User> getUsers() {
          return users;    }
     public void setUsers(Set<User> users) {
          this.users = users;
     }}
 
 
【3】、Authority类;(权限管理)
@Table(name="
AUTHORITIES")
@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class
Authority extends IdEntity{
     //权限的名字, 用于显示
     private String displayName;
     //权限的名字: 用于配置 Shiro
     private String name;
     //权限允许的行为: 即权限的具体内容.
     private String permissions;
     //父权限
     private Authority parentAuthority;
     //URL 地址
     private String url;
     //子权限
     private List<Authority> subAuthorities = new ArrayList<>();
    
     public Authority(Long id) {
          this.id = id;
     }
    
     public Authority() {
          // TODO Auto-generated constructor stub
     }
    
     public String getDisplayName() {
          return displayName;
     }
     public void setDisplayName(String displayName) {
          this.displayName = displayName;
     }
     public String getName() {
          return name;
     }
     public void setName(String name) {
          this.name = name;
     }
     public String getPermissions() {
          return permissions;
     }
     public void setPermissions(String permissions) {
          this.permissions = permissions;
     }
    
     @ManyToOne
     @JoinColumn(name="PARENT_AUTHORITY_ID")
     public Authority getParentAuthority() {
          return parentAuthority;
     }
     public void setParentAuthority(Authority parentAuthority) {
          this.parentAuthority = parentAuthority;
     }
     @OneToMany(mappedBy="parentAuthority")
     public List<Authority> getSubAuthorities() {
          return subAuthorities;
     }
     public void setSubAuthorities(List<Authority> subAuthorities) {
          this.subAuthorities = subAuthorities;
     }
     @Transient
     public List<String> getPermissionList(){
          return Arrays.asList(permissions.split(","));
     }
    
     public String getUrl() {
          return url;
     }
     public void setUrl(String url) {
          this.url = url;
     }
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

转载于:https://www.cnblogs.com/panchanghong/p/4698548.html

你可能感兴趣的文章
log4j xml 配置 自定义使用版
查看>>
Spring中@Transactional(rollbackFor = Throwable.class)的作用
查看>>
Java 8 Lambda : Comparator 示例
查看>>
css几个重要属性的介绍
查看>>
联想linux高级工程师面试题(年薪10w~12w)
查看>>
SCCM2012 R2实战系列之十一:解决OSD分发Windows7 系统盘盘符为’D’问题
查看>>
The MySQL Query Cache 说明
查看>>
3D图形向量基础
查看>>
桥接模式
查看>>
mongodb分布式集群架构
查看>>
一段有意思的程序【十全十美】
查看>>
滑动窗口协议
查看>>
iOS 关于获取沙盒文件的一些总结
查看>>
女生心情不好时怎么办
查看>>
互联网后端架构 - 2018年总结
查看>>
云桌面平台
查看>>
GNS3 配置GRE
查看>>
root用户无法登录
查看>>
Linux开机启动自动执行某个脚本
查看>>
JSP 中 pageEncoding charset 的区别
查看>>