项目springMVC&spring$springdatajpa_Day01

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 相应的配置

  1. 读取SpringMVC
  2. 启动Spring的监听器
  3. 配置解决中文乱码的问题
  4. 配置核心控制器

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值