Commit 3d74dac9 authored by 郑杰's avatar 郑杰
Browse files

eladmin 1.0 版本发布

parents
package me.zhengjie.system.service.query;
import me.zhengjie.system.domain.Menu;
import me.zhengjie.system.repository.MenuRepository;
import me.zhengjie.system.service.mapper.MenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
/**
* @author jie
* @date 2018-12-17
*/
@Service
@CacheConfig(cacheNames = "menu")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class MenuQueryService {
@Autowired
private MenuRepository menuRepository;
@Autowired
private MenuMapper menuMapper;
/**
* 不分页
*/
@Cacheable(key = "'queryAll:'+#p0")
public List queryAll(String name){
return menuMapper.toDto(menuRepository.findAll(new Spec(name)));
}
class Spec implements Specification<Menu> {
private String name;
public Spec(String name) {
this.name = name;
}
@Override
public Predicate toPredicate(Root<Menu> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
List<Predicate> list = new ArrayList<Predicate>();
if(!ObjectUtils.isEmpty(name)){
/**
* 模糊
*/
list.add(cb.like(root.get("name").as(String.class),"%"+name+"%"));
}
Predicate[] p = new Predicate[list.size()];
return cb.and(list.toArray(p));
}
}
}
package me.zhengjie.system.service.query;
import me.zhengjie.system.domain.Permission;
import me.zhengjie.system.repository.PermissionRepository;
import me.zhengjie.system.service.mapper.PermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
/**
* @author jie
* @date 2018-12-03
*/
@Service
@CacheConfig(cacheNames = "permission")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class PermissionQueryService {
@Autowired
private PermissionRepository permissionRepository;
@Autowired
private PermissionMapper permissionMapper;
/**
* 不分页
*/
@Cacheable(key = "'queryAll:'+#p0")
public List queryAll(String name){
return permissionMapper.toDto(permissionRepository.findAll(new Spec(name)));
}
class Spec implements Specification<Permission> {
private String name;
public Spec(String name) {
this.name = name;
}
@Override
public Predicate toPredicate(Root<Permission> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
List<Predicate> list = new ArrayList<Predicate>();
if(!ObjectUtils.isEmpty(name)){
/**
* 模糊
*/
list.add(cb.like(root.get("name").as(String.class),"%"+name+"%"));
}
Predicate[] p = new Predicate[list.size()];
return cb.and(list.toArray(p));
}
}
}
This diff is collapsed.
# If you use SLF4J. First, you need to tell log4jdbc-log4j2 that you want to use the SLF4J logger
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
\ No newline at end of file
This diff is collapsed.
package me.zhengjie;
import me.zhengjie.monitor.domain.vo.RedisVo;
import me.zhengjie.monitor.service.RedisService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Calendar;
import java.util.Date;
@RunWith(SpringRunner.class)
@SpringBootTest
public class EladminApplicationTests {
@Autowired
private RedisService redisService;
@Test
public static void main(String[] args) {
String[] weekDays = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0){
w = 0;
}
System.out.println(weekDays[w]);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment