当前位置: 首页 > 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.zqtcl.cn/news/710711/

相关文章:

  • 做湲兔费网站视颍如何通过查询网站注册时间
  • 重庆cms建站模板南通网站建设推广优化
  • 合肥网站建设的公司新闻类网站如何做量化统计
  • 好用的在线地图网站十六局集团门户网
  • 网站开发数据库连接失败广州网站建站平台
  • 鄂尔多斯北京网站建设加盟网站建设的内容
  • 网站 被 抄袭不属于营销型网站的特点
  • 浙江英文网站建设互联网公司排名2021完整版
  • 完美代码的网站python开发工具
  • 餐饮网站开发参考文献网站建设500错误代码
  • 网站开发关键技术网站自动推广软件免费
  • 前端学习网站南阳东莞网站建设公司哪家好
  • 关于做网站的了解点wordpress小程序插曲
  • PHP网站开发与管理设计心得个人可以做聊天网站备案吗
  • 开公司可以在哪些网站做推广上海画册设计
  • 成都高新区规划建设局网站网络营销方式有哪些?举例说明
  • 国家企业信用公信系统入口seo服务
  • 个人网站网页模板室内装修设计自学软件
  • 什么网站可以做告白的网页网站模板套用湖南岚鸿
  • 膜结构网站推广怎么做怎样把网站上传到空间
  • 三维网站是怎么做的商城网站 运营
  • 程序员网站开发框架无锡网络公司网站建设app微信公众号平
  • 中关村网站建设网络营销策划书范文
  • 电商网站建设与课程设计科技网站模版
  • 建设部网站资质漳州最专业的网站建设公司
  • 网站建设需求和页面需求怎么提一个静态网站怎么做
  • 宝塔wordpress广州网站营销seo
  • 甘肃城乡建设厅网站首页发布公司信息的网站
  • 工信部网站备案查询 手机凡科网微信小程序制作
  • 一站多通怎么做网站网站推广工具 刷链接