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-scanbase-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.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">
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();
}
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>
</td>
<td>
<img onclick="document.forms[0].submit();" style="cursor: hand;"
src="${cp}/static/images/login/login_button.jpg" width="73" height="25">
</td>
</tr>
<th>
密码
</th>
<td>
<input type="password" name="password" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<img onclick="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;
}
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")
@Table(name="USERS")
public class User extends IdEntity{
private String name;
private String password;
private String password;
private int enabled ;
//盐值, 进行密码加密
private String salt;
//该用户拥有的角色
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() {
@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;
}
@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;
}
}