添加默认常用的函数的实现

This commit is contained in:
Dftre 2024-05-06 01:19:10 +08:00
parent e499eff391
commit 0d214a5b78
3 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,30 @@
package com.ruoyi.mybatis.mapper;
import java.util.List;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.mybatis.utils.SQLUtil;
public interface JPAMapper<T extends BaseEntity> {
@SelectProvider(value = SQLUtil.class, method = "selectById")
public T selectById(T entity);
@SelectProvider(value = SQLUtil.class, method = "list")
public List<T> selectList(T entity);
@InsertProvider(value = SQLUtil.class, method = "insert")
@Options(useGeneratedKeys = true)
public int insert(T entity);
@UpdateProvider(value = SQLUtil.class, method = "update")
public int update(T entity);
@DeleteProvider(value = SQLUtil.class, method = "deleteById")
public int deleteById(T entity);
}

View File

@ -0,0 +1,18 @@
package com.ruoyi.mybatis.service;
import java.util.List;
import com.ruoyi.common.core.domain.BaseEntity;
public interface JPAService<T extends BaseEntity> {
public T get(T entity);
public List<T> list(T entity);
public int add(T entity);
public int update(T entity);
public int del(T entity);
}

View File

@ -0,0 +1,40 @@
package com.ruoyi.mybatis.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.mybatis.mapper.JPAMapper;
import com.ruoyi.mybatis.service.JPAService;
public class JPAServiceImpl<T extends BaseEntity> implements JPAService<T> {
@Autowired
private JPAMapper<T> mapper;
@Override
public T get(T entity) {
return mapper.selectById(entity);
};
@Override
public List<T> list(T entity) {
return mapper.selectList(entity);
}
@Override
public int add(T entity) {
return mapper.insert(entity);
}
@Override
public int update(T entity) {
return mapper.update(entity);
}
@Override
public int del(T entity) {
return mapper.deleteById(entity);
}
}