深圳开发网站的公司哪家好电商网站建设教学总结

张小明 2026/1/14 16:22:09
深圳开发网站的公司哪家好,电商网站建设教学总结,深圳龙岗网站建设哪家好公司,wordpress 插件 页面Spring Boot 整合 Redis 注解实现简单 CRUD 可以关注#xff1a;小坏说Java 公众号 零基础全栈开发Java微服务版本实战-后端-前端-运维-实战企业级三个实战项目 一、项目搭建 零基础全栈开发Java微服务版本实战-后端-前端-运维-实战企业级三个实战项目 1.1 添加依赖 小坏说Java 公众号零基础全栈开发Java微服务版本实战-后端-前端-运维-实战企业级三个实战项目一、项目搭建零基础全栈开发Java微服务版本实战-后端-前端-运维-实战企业级三个实战项目1.1 添加依赖!-- pom.xml --dependencies!-- Spring Boot Web --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency!-- Spring Boot Redis --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId/dependency!-- Lombok --dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependency/dependencies1.2 配置文件# application.ymlspring:redis:host:localhostport:6379database:0server:port:8080二、实体类零基础全栈开发Java微服务版本实战-后端-前端-运维-实战企业级三个实战项目packagecom.example.entity;importlombok.Data;importorg.springframework.data.annotation.Id;importorg.springframework.data.redis.core.RedisHash;importorg.springframework.data.redis.core.index.Indexed;importjava.io.Serializable;/** * RedisHash: 声明实体类value指定Redis中的key前缀 * 存储格式: user:{id} */DataRedisHash(user)publicclassUserimplementsSerializable{IdprivateLongid;// 主键IndexedprivateStringusername;// 创建索引可以按username查询privateStringemail;privateIntegerage;}三、Repository 接口packagecom.example.repository;importcom.example.entity.User;importorg.springframework.data.repository.CrudRepository;importorg.springframework.stereotype.Repository;importjava.util.List;importjava.util.Optional;/** * CrudRepository 提供基本的CRUD方法 * 可以根据方法名自动生成查询 */RepositorypublicinterfaceUserRepositoryextendsCrudRepositoryUser,Long{// 根据用户名查询精确匹配ListUserfindByUsername(Stringusername);// 根据邮箱查询OptionalUserfindByEmail(Stringemail);// 根据年龄范围查询ListUserfindByAgeBetween(IntegerminAge,IntegermaxAge);// 删除指定用户名的用户LongdeleteByUsername(Stringusername);}四、Service 层packagecom.example.service;importcom.example.entity.User;importcom.example.repository.UserRepository;importlombok.extern.slf4j.Slf4j;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.cache.annotation.*;importorg.springframework.stereotype.Service;importjava.util.List;importjava.util.Optional;Slf4jServiceCacheConfig(cacheNamesuser)// 类级别缓存配置publicclassUserService{AutowiredprivateUserRepositoryuserRepository;/** * Cacheable: 查询缓存 * 1. 先查缓存有则直接返回 * 2. 无则执行方法将结果存入缓存 */Cacheable(key#id)publicUserfindById(Longid){log.info(查询数据库用户ID: {},id);returnuserRepository.findById(id).orElse(null);}/** * 查询所有用户 */publicListUserfindAll(){return(ListUser)userRepository.findAll();}/** * 根据用户名查询 */publicListUserfindByUsername(Stringusername){returnuserRepository.findByUsername(username);}/** * CachePut: 更新缓存 * 每次都会执行方法并将结果更新到缓存 */CachePut(key#user.id)publicUsersave(Useruser){log.info(保存用户: {},user.getUsername());returnuserRepository.save(user);}/** * CacheEvict: 删除缓存 * 方法执行后删除指定key的缓存 */CacheEvict(key#id)publicvoiddeleteById(Longid){log.info(删除用户ID: {},id);userRepository.deleteById(id);}/** * 更新用户 */Caching(putCachePut(key#user.id),evictCacheEvict(keylist)// 清除列表缓存)publicUserupdate(Useruser){log.info(更新用户: {},user.getId());returnuserRepository.save(user);}/** * 缓存用户列表 */Cacheable(keylist)publicListUserfindAllWithCache(){log.info(查询所有用户带缓存);return(ListUser)userRepository.findAll();}}五、Controller 层零基础全栈开发Java微服务版本实战-后端-前端-运维-实战企业级三个实战项目packagecom.example.controller;importcom.example.entity.User;importcom.example.service.UserService;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.web.bind.annotation.*;importjava.util.List;RestControllerRequestMapping(/api/users)publicclassUserController{AutowiredprivateUserServiceuserService;// 新增用户PostMappingpublicUsercreateUser(RequestBodyUseruser){returnuserService.save(user);}// 根据ID查询用户GetMapping(/{id})publicUsergetUserById(PathVariableLongid){returnuserService.findById(id);}// 查询所有用户GetMappingpublicListUsergetAllUsers(){returnuserService.findAllWithCache();}// 根据用户名查询GetMapping(/search)publicListUsergetUserByUsername(RequestParamStringusername){returnuserService.findByUsername(username);}// 更新用户PutMapping(/{id})publicUserupdateUser(PathVariableLongid,RequestBodyUseruser){user.setId(id);returnuserService.update(user);}// 删除用户DeleteMapping(/{id})publicStringdeleteUser(PathVariableLongid){userService.deleteById(id);return删除成功;}}六、主启动类零基础全栈开发Java微服务版本实战-后端-前端-运维-实战企业级三个实战项目packagecom.example;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.SpringBootApplication;importorg.springframework.cache.annotation.EnableCaching;SpringBootApplicationEnableCaching// 开启缓存支持publicclassApplication{publicstaticvoidmain(String[]args){SpringApplication.run(Application.class,args);}}七、测试示例7.1 使用 Postman 测试1. 新增用户POST http://localhost:8080/api/users Content-Type: application/json { username: 张三, email: zhangsanexample.com, age: 25 }2. 查询用户GET http://localhost:8080/api/users/13. 查询所有用户GET http://localhost:8080/api/users4. 更新用户PUT http://localhost:8080/api/users/1 Content-Type: application/json { username: 张三, email: zhangsan_newexample.com, age: 26 }5. 删除用户DELETE http://localhost:8080/api/users/1八、注解总结注解作用示例RedisHash实体类映射到Redis HashRedisHash(user)Id标记主键字段Id private Long id;Indexed创建二级索引支持字段查询Indexed private String username;EnableCaching启用缓存主类上EnableCachingCacheable方法结果缓存Cacheable(key #id)CachePut更新缓存CachePut(key #user.id)CacheEvict删除缓存CacheEvict(key #id)Caching组合多个缓存操作见上面Service中的update方法九、运行效果零基础全栈开发Java微服务版本实战-后端-前端-运维-实战企业级三个实战项目第一次查询用户(1)控制台打印日志查询数据库第二次查询用户(1)直接从缓存返回不打印日志更新用户(1)更新数据库并更新缓存删除用户(1)删除数据库记录并清除缓存十、注意事项实体类必须实现Serializable接口缓存注解的方法必须是public的同一个类内部调用缓存注解的方法不会生效Redis 需要提前安装并启动这个示例包含了最基本的 Redis 注解 CRUD 操作可以直接运行使用。
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

网站网上商城制作免费制作桥架app

过去20年,软件工程一直在新技术的赋能下经历着快速迭代。直到今天,Agentic AI才为行业带来了真正的颠覆性变革。 软件的存在,一方面是把人类手动的操作步骤信息化,另一方面是把业务流程自动化。所以在一定程度上,软件…

张小明 2026/1/13 11:52:37 网站建设

苏小小移动网站腾讯会议收费

巴西语足球赛事激情解说生成 在短视频平台每分钟都在诞生千万级播放量的今天,一场没有“灵魂”的体育内容注定难以突围。而真正的灵魂,往往来自那一声撕裂空气的呐喊:“Gol do Brasil!”——这不仅是进球宣告,更是一种…

张小明 2026/1/13 12:39:07 网站建设

安康网站制作公司长沙高校网站制作公司

理论基础:注意:1. 策略的输出要加对数,因此net输出必须softmax,将输出限制为正数。2. 这里选择action不是greedy地选择最优action,而是按照概率分布选择action->exploration。3. 策略更新使用的是梯度上升&#xff…

张小明 2026/1/14 6:47:39 网站建设

wordpress建站公司wordpress 数据库 地址

✅作者简介:热爱科研的Matlab仿真开发者,擅长数据处理、建模仿真、程序设计、完整代码获取、论文复现及科研仿真。 🍎 往期回顾关注个人主页:Matlab科研工作室 👇 关注我领取海量matlab电子书和数学建模资料 &#x1…

张小明 2026/1/14 9:35:46 网站建设

2017学脚本语言做网站那个网站做图片好

解锁创意边界:当乐高遇见3D建模的数字魔法 【免费下载链接】ImportLDraw A Blender plug-in for importing LDraw file format Lego models and parts. 项目地址: https://gitcode.com/gh_mirrors/im/ImportLDraw 你是否曾经想象过,将儿时那些色彩…

张小明 2026/1/12 21:34:36 网站建设

吉安建站公司免费ftp服务器申请网站

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容: 开发一个GitTortoise与传统Git命令行操作的效率对比工具,功能包括:1. 记录并分析常见Git任务的完成时间;2. 可视化展示操作步骤简化情况&#xf…

张小明 2026/1/13 10:22:13 网站建设