<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.0modelVersion>
<groupId>cn.itsource.crmgroupId>
<artifactId>crmartifactId>
<version>1.0-SNAPSHOTversion>
<packaging>warpackaging>
<name>crm Maven Webappname>
<url>http://www.example.comurl>
<properties>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
<maven.compiler.source>1.8maven.compiler.source>
<maven.compiler.target>1.8maven.compiler.target>
<org.springframework.version>4.2.5.RELEASEorg.springframework.version>
<org.hibernate.version>4.3.8.Finalorg.hibernate.version>
<spring-data-jpa.version>1.9.0.RELEASEspring-data-jpa.version>
<com.fasterxml.jackson.version>2.5.0com.fasterxml.jackson.version>
properties>
<dependencies>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-coreartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-contextartifactId>
<version>4.2.5.RELEASEversion>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-txartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-jdbcartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-ormartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-aopartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-testartifactId>
<version>${org.springframework.version}version>
<scope>testscope>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webmvcartifactId>
<version>${org.springframework.version}version>
dependency>
<dependency>
<groupId>org.apache.commonsgroupId>
<artifactId>commons-ioartifactId>
<version>1.3.2version>
dependency>
<dependency>
<groupId>commons-fileuploadgroupId>
<artifactId>commons-fileuploadartifactId>
<version>1.2.2version>
dependency>
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-coreartifactId>
<version>${com.fasterxml.jackson.version}version>
dependency>
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-annotationsartifactId>
<version>${com.fasterxml.jackson.version}version>
dependency>
<dependency>
<groupId>com.fasterxml.jackson.coregroupId>
<artifactId>jackson-databindartifactId>
<version>${com.fasterxml.jackson.version}version>
dependency>
<dependency>
<groupId>commons-dbcpgroupId>
<artifactId>commons-dbcpartifactId>
<version>1.2.2version>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>5.1.6version>
dependency>
<dependency>
<groupId>org.apache.commonsgroupId>
<artifactId>commons-lang3artifactId>
<version>3.5version>
dependency>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.12version>
<scope>testscope>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>javax.servlet-apiartifactId>
<version>3.1.0version>
<scope>providedscope>
dependency>
<dependency>
<groupId>commons-logginggroupId>
<artifactId>commons-loggingartifactId>
<version>1.2version>
dependency>
<dependency>
<groupId>org.mybatisgroupId>
<artifactId>mybatisartifactId>
<version>3.2.1version>
dependency>
<dependency>
<groupId>org.mybatisgroupId>
<artifactId>mybatis-springartifactId>
<version>1.2.0version>
dependency>
<dependency>
<groupId>log4jgroupId>
<artifactId>log4jartifactId>
<version>1.2.17version>
dependency>
<dependency>
<groupId>org.slf4jgroupId>
<artifactId>slf4j-apiartifactId>
<version>1.7.2version>
dependency>
<dependency>
<groupId>org.slf4jgroupId>
<artifactId>slf4j-log4j12artifactId>
<version>1.7.2version>
dependency>
<dependency>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-coreartifactId>
<version>1.3.5version>
dependency>
<dependency>
<groupId>com.github.pagehelpergroupId>
<artifactId>pagehelperartifactId>
<version>5.0.1version>
dependency>
dependencies>
<build>
<finalName>crmfinalName>
<plugins>
<plugin>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-maven-pluginartifactId>
<version>1.3.2version>
<configuration>
<verbose>falseverbose>
<overwrite>trueoverwrite>
configuration>
plugin>
<plugin>
<artifactId>maven-clean-pluginartifactId>
<version>3.1.0version>
plugin>
<plugin>
<artifactId>maven-resources-pluginartifactId>
<version>3.0.2version>
plugin>
<plugin>
<artifactId>maven-compiler-pluginartifactId>
<version>3.8.0version>
plugin>
<plugin>
<artifactId>maven-surefire-pluginartifactId>
<version>2.22.1version>
plugin>
<plugin>
<artifactId>maven-war-pluginartifactId>
<version>3.2.2version>
plugin>
<plugin>
<artifactId>maven-install-pluginartifactId>
<version>2.5.2version>
plugin>
<plugin>
<artifactId>maven-deploy-pluginartifactId>
<version>2.8.2version>
plugin>
plugins>
build>
project>
xml中的SQL是代码生成器生成的(自己写也可以)!
public interface BaseMapper<T> {
int deleteByPrimaryKey(Long id);
int insert(T record);
T selectByPrimaryKey(Long id);
List<T> selectAll();
int updateByPrimaryKey(T record);
}
public interface DepartmentMapper extends BaseMapper<Department> {
}
public interface IBaseService<T> {
void save(T t);
void update(T t);
void delete(Long id);
T findOne(Long id);
List<T> findAll();
}
package cn.itsource.crm.service.impl;
import cn.itsource.crm.mapper.BaseMapper;
import cn.itsource.crm.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
@Autowired
private BaseMapper<T> mapper;
@Override
@Transactional
public void save(T t) {
mapper.insert(t);
}
@Override
@Transactional
public void update(T t) {
mapper.updateByPrimaryKey(t);
}
@Override
@Transactional
public void delete(Long id) {
mapper.deleteByPrimaryKey(id);
}
@Override
public T findOne(Long id) {
return mapper.selectByPrimaryKey(id);
}
@Override
public List<T> findAll() {
return mapper.selectAll();
}
}
public interface IDepartmentService extends IBaseService<Department> {
}
@Service
public class DepartmentServiceImpl extends BaseServiceImpl<Department>
implements IDepartmentService {
}
${pageContext.request.contextPath}
<%
String path = request.getContextPath();
// http://localhost:80/crm/
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%--所有访问前都会访问这个--%>
<base href="<%=basePath %>">
pom.xml中引入jar包
<dependency>
<groupId>com.github.pagehelpergroupId>
<artifactId>pagehelperartifactId>
<version>5.0.1version>
dependency>
applicationContext中加上插件
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="cn.itsource.crm.domain" />
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<value>helperDialect=mysqlvalue>
property>
bean>
array>
property>
<property name="mapperLocations" value="classpath:cn/itsource/crm/mapper/*.xml" />
bean>
在
query
包中
public class BaseQuery {
//这两个名称是easyui支持的名称
private int page = 1; //当前页
private int rows = 10; //每页条数
//省略getter,setter
}
public class DepartmentQuery extends BaseQuery {
//查询条件
}
在
util
包中
/**
* Easyui需要的分页结果
* @param
*/
public class PageResult<T> {
private long total; //总条数
private List<T> rows; //数据
public PageResult() {}
public PageResult(int total, List<T> rows) {
this.total = total;
this.rows = rows;
}
//省略getter,setter
}
List findByQuery(BaseQuery query);
<select id="findByQuery" parameterType="cn.itsource.crm.query.DepartmentQuery" resultMap="BaseResultMap" >
select id, sn, name, dirPath, state, manager_id, parent_id
from t_department
select>
PageResult<T> findByQuery(BaseQuery query);
@Override
public PageResult findByQuery(BaseQuery query) {
PageHelper.startPage(query.getPage(), query.getRows());
//拿到所有数据
Page page = (Page) mapper.selectAll();
//创建一个easyui能认识的分页对象
PageResult pageResult = new PageResult();
pageResult.setTotal(page.getTotal());
pageResult.setRows(page.getResult());
return pageResult;
}