当前位置: 首页 > news >正文

万网定制网站怎么样重生做网站的小说

万网定制网站怎么样,重生做网站的小说,layui做的网站,新手学做网站要花钱么Spring Framework入门指南#xff1a;从零开始构建企业级应用 #x1f680; #x1f3af; 掌握Spring框架#xff0c;助你成为Java企业级开发高手#xff01; 在上一篇文章中#xff0c;我们学习了Java入门系列的最后一篇文章–Java反射机制。今天开始#xff0c;让我们…Spring Framework入门指南从零开始构建企业级应用 掌握Spring框架助你成为Java企业级开发高手 在上一篇文章中我们学习了Java入门系列的最后一篇文章–Java反射机制。今天开始让我们一起深入探索Spring框架这个Java领域最受欢迎的企业级开发框架 考虑到相关内容较多咱们这个系列分为四个部分进行更新 废话不多说开始第一部分 1. Spring框架简介 1.1 什么是Spring Framework Spring Framework是一个轻量级的开源应用框架它为开发Java应用提供了全面的基础设施支持。Spring的核心特性是依赖注入DI和面向切面编程AOP。 1.2 为什么选择Spring 模块化设计按需使用 松耦合易于测试 强大的生态系统 活跃的社区支持 广泛的企业应用 1.3 Spring的核心模块 spring-core ├── spring-beans # Bean容器和依赖注入 ├── spring-context # 应用上下文邮件定时任务等 ├── spring-aop # 面向切面编程 ├── spring-jdbc # 数据库访问 ├── spring-orm # 对象关系映射 ├── spring-web # Web开发基础 └── spring-webmvc # Web MVC框架2. 快速开始 2.1 环境准备 首先在Maven项目中添加Spring依赖 dependencies!-- Spring核心依赖 --dependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion5.3.23/version/dependency!-- Spring Web MVC --dependencygroupIdorg.springframework/groupIdartifactIdspring-webmvc/artifactIdversion5.3.23/version/dependency!-- 数据库相关 --dependencygroupIdorg.springframework/groupIdartifactIdspring-jdbc/artifactIdversion5.3.23/version/dependency!-- Lombok可选 --dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdversion1.18.24/versionscopeprovided/scope/dependency /dependencies2.2 第一个Spring应用 创建一个简单的Spring应用展示依赖注入的基本用法 // 用户实体 Data AllArgsConstructor public class User {private Long id;private String username;private String email; }// 用户服务接口 public interface UserService {User getUserById(Long id);void createUser(User user); }// 用户服务实现 Service Slf4j public class UserServiceImpl implements UserService {Autowiredprivate UserRepository userRepository;Overridepublic User getUserById(Long id) {log.info(获取用户信息: {}, id);return userRepository.findById(id);}Overridepublic void createUser(User user) {log.info(创建用户: {}, user);userRepository.save(user);} }// 应用配置类 Configuration ComponentScan(com.example.demo) public class AppConfig {Beanpublic UserRepository userRepository() {return new UserRepositoryImpl();} }// 主类 public class MainApplication {public static void main(String[] args) {ApplicationContext context new AnnotationConfigApplicationContext(AppConfig.class);UserService userService context.getBean(UserService.class);User user new User(1L, 张三, zhangsanexample.com);userService.createUser(user);User foundUser userService.getUserById(1L);System.out.println(找到用户 foundUser);} }3. Spring核心特性详解 3.1 依赖注入DI Spring提供了多种依赖注入方式 // 1. 构造器注入推荐 Service public class OrderService {private final UserService userService;private final PaymentService paymentService;Autowiredpublic OrderService(UserService userService, PaymentService paymentService) {this.userService userService;this.paymentService paymentService;} }// 2. Setter注入 Service public class ProductService {private InventoryService inventoryService;Autowiredpublic void setInventoryService(InventoryService inventoryService) {this.inventoryService inventoryService;} }// 3. 字段注入不推荐 Service public class CartService {Autowiredprivate ProductService productService; }3.2 面向切面编程AOP AOP允许我们将横切关注点如日志、事务从业务逻辑中分离出来 // 日志切面 Aspect Component Slf4j public class LoggingAspect {Around(annotation(LogExecutionTime))public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {long startTime System.currentTimeMillis();Object result joinPoint.proceed();long endTime System.currentTimeMillis();log.info(方法 {} 执行耗时: {}ms,joinPoint.getSignature().getName(),(endTime - startTime));return result;}AfterThrowing(pointcut execution(* com.example.demo.service.*.*(..)),throwing ex)public void logError(JoinPoint joinPoint, Exception ex) {log.error(方法 {} 执行异常: {},joinPoint.getSignature().getName(),ex.getMessage());} }// 自定义注解 Target(ElementType.METHOD) Retention(RetentionPolicy.RUNTIME) public interface LogExecutionTime { }// 使用示例 Service public class UserService {LogExecutionTimepublic User findById(Long id) {// 业务逻辑} }系列的第一部分到此暂告一段落内容包含了Spring的基础介绍和核心特性。 如果你觉得这篇文章有帮助欢迎点赞转发也期待在评论区看到你的想法和建议 咱们下一期见
http://www.pierceye.com/news/710711/

相关文章:

  • 阳西县建设局网站.net网站项目有哪些
  • 门户网站优化网站建立软件
  • 贵阳网站建设在哪里陕西省住房城乡建设部门户网站
  • 深圳网站建设799元起全包域名企业网站分为哪四类
  • 潍坊网站建设公司商城网站建设建站系统
  • 苏州区网站建设网站前台乱码
  • 网站设计公司企业邮箱青岛网站制作工具
  • 网站建设 html5wordpress 关注公众号
  • 自建公司网站利用网站文件下载做推广
  • 酒店网站素材软件开发合同范本大全
  • 安康市住房和城乡建设局网站网站建设广告宣传素材
  • 没有网站怎么做链接视频网上哪里给公司做网站
  • 广告网站制作报价网站开发环境怎么写
  • 网站开发总结与收获智慧团建登录官网
  • 旅游电子商务网站的建设建设局网站项目负责人资质要求
  • 设计响应式网站多少钱网站建设行业新闻动态
  • 一般做外单的有哪些网站太原市网站制作公司
  • wordpress 文章内seo代码优化工具
  • 做网站用的笔记本配置网络科技公司骗术
  • 在线建设网站江苏中南建设集团网站是多少
  • 中国建设银行官网站陕西西安网站建设域名怎么用
  • 佛山高端网站制作公司自己做的网站怎么发布到百度
  • 网站建设空间选择的重要性wordpress菲插件关键词
  • 基于wap的企业网站设计与实现洛阳霞光seo网络公司
  • 在家做的手工活哪里有网站网站开发与运营方向和企业管理方向
  • 厦门网站建设厦门南京宣传片公司有哪些
  • 专门做问卷的网站南宁做网站公司
  • 鹰潭做网站公司网站模板及素材
  • dw网站引导页怎么做wordpress 福利
  • PS网站设计网站每年都要备案吗