首页>代码>spring boot+mybatis+ehcache(缓存)整合的简单实例>/springboot-mybatis/src/main/java/com/singhand/service/UserService.java
package com.singhand.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import com.singhand.dao.test.UserDAO; import com.singhand.entity.UserEntity; /** ************************************************* * @ClassName: UserService * @Description: TODO(用户操作服务类) * @author mjy * @date 2018年6月2日 下午3:57:13 ************************************************ */ @Service public class UserService { @Autowired private UserDAO userDao; /** ********************************************************* * @method: getUser * @Description: TODO(@Cacheable注解为存入缓存中:缓存表为userCache;缓存可以为userId,测试:第一查询打印出从数据库中查询数据;执行第二次没有答应出来说明成功) * @Param userId * @return UserEntity * @author mjy ********************************************************* */ @Cacheable(value = "userCache", key = "#userId") public UserEntity getUser(String userId){ System.err.println("从数据库中查询数据。。。。。。。。"); UserEntity result = new UserEntity(); result = userDao.getUser(userId); return result; } /** ********************************************************* * @method: addUser * @Description: TODO(添加用户) * @Param user * @return void * @author mjy ********************************************************* */ @Cacheable(value = "userCache", key = "#user.id") public void addUser(UserEntity user){ userDao.addUser(user); } /** ********************************************************* * @method: updateUserById * @Description: TODO(更新用户是更新相应的缓存:@CachePut注解为更新缓存) * @Param user * @return void * @author mjy ********************************************************* */ @CachePut(value = "userCache", key = "#user.id") public UserEntity updateUserById(UserEntity user){ userDao.updateUserById(user); return user; } /** ********************************************************* * @method: deleteUserById * @Description: TODO(删除操作是直接删除缓存中的数据:@CacheEvict注解为删除缓存) * @Param @param id TODO(描述参数作用) * @return void * @throws * @author TODO ********************************************************* */ @CacheEvict(value = "userCache", key = "#id") public void deleteUserById(String id){ userDao.deleteUserById(id); } }

WXX1083402844 LV1
2021年12月3日
mudingc木钉 LV30
2021年6月16日
1798672867 LV21
2021年5月22日
912299793 LV21
2021年4月22日
欠踹de背影 LV25
2020年12月25日
wcy071213 LV27
2020年11月17日
sangyy LV10
2020年8月21日
zaizai21312 LV10
2020年6月12日
youwuzuichen LV11
2020年4月30日
海问香 LV6
2020年1月20日

woldxy LV12
2023年9月14日
hbsoft2008 LV16
2023年3月23日
xiaoyuer2 LV8
2022年11月20日
love8309287 LV4
2022年10月9日
wang512237140 LV20
2021年12月14日
WXX1083402844 LV1
2021年12月3日
尹恒yingying LV18
2021年10月28日
mudingc木钉 LV30
2021年6月16日
912299793 LV21
2021年4月22日
caojianlong1 LV6
2021年2月3日