文章目录
1 抽取Service层
public interface IBaseService <T,ID extends Serializable>{
//添加与修改数据
void save(T t);
//根据id删除一条数据
void delete(ID id);
//根据id查询到一条数据
T findOne(ID id);
//查询所有数据
List<T> findAll();
//根据Query拿到分页对象(分页)
Page findPageByQuery(BaseQuery baseQuery);
//根据Query拿到对应的所有数据(不分页)
List<T> findByQuery(BaseQuery baseQuery);
//根据jpql与对应的参数拿到数据
List findByJpql(String jpql, Object... values);
}
BaseServiceImpl -->实现IBaseService --》实现对应的方法
@Service
public class EmployeeServiceImpl extends BaseServiceImpl<Employee,Long> implements IEmployeeService {
}
2 集成SpringMVC
2.1 引入相应jar包
<!-- 引入web前端的支持 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
2.2 配置applicationContext-mvc.xml
2.3 配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
</web-app>
2.4 相应的配置
- 读取SpringMVC
- 启动Spring的监听器
- 配置解决中文乱码的问题
- 配置核心控制器
3 easyui的tree加载
easyui树型插件
$(function () {
$("#menuTree").tree({
url:'/json/menu.json',
onClick:function (node) {
//添加页签
addTabs(node.text,node.url)
}
});
tab选项卡
function addTabs(text,url) {
if (url) {
if (!$('#dataTab').tabs('exists', text)) {
var content = "<iframe frameborder=0 style='width:100%;height:100%' src='"+url+"'></iframe>";
$('#dataTab').tabs('add', {
method:'get',
title: text,
content: content,
closable: true,
});
} else {
//选中面板
$('#dataTab').tabs('select', text);
}
}
}
4 分页查询
4.1 公共的UiPage类
public class UiPage {
//总数
private Long total;
//每页数据
private List rows;
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
public List getRows() {
return rows;
}
public void setRows(List rows) {
this.rows = rows;
}
public UiPage(Page page) {
this.total = page.getTotalElements();
this.rows = page.getContent();
}
public UiPage() {
}
}
4.2 EmployeeQuery加入公共方法:接收前台传递过来数据 page (当前页)/rows(每页条数)
//添加两个方法 来接受数据
public void setPage(Integer page){
this.currentPage = page;
}
public void setRows(Integer rows){
this.pageSize = rows;
}
5 高级查询
页面准备form表单
加载数据
var itsource = {
search:function () {
var jsonObj = searchForm.serializeObject();
employeeGrid.datagrid('load',jsonObj);
},
add:function () {
alert("add")
},
edit:function () {
alert("edit")
},
remove:function () {
alert("remove")
}
}
5.1 EmployeeQuery里面方法
//抽取查询
@Override
public Specification createSpecification() {
Specification<Employee> specification = Specifications.<Employee>and()
.like(StringUtils.isNotBlank(username), "username","%"+username+"%")
.like(StringUtils.isNotBlank(email), "email","%"+email+"%")
.eq(departmentId !=null,"department.id",departmentId)
.gt(age !=null, "age", age)
.build();
return specification;
}