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

python能做网站开发吗手机怎么防止网站跳转

python能做网站开发吗,手机怎么防止网站跳转,企业网络维护,wordpress the_excerpt1. 引言 在上一篇文章中,我们详细探讨了 Spring Batch 的核心组件(Job、Step、Chunk、ItemReader、ItemProcessor、ItemWriter),并通过示例展示了它们的协作方式。掌握了这些组件后,接下来需要了解如何灵活配置 Spring Batch 作业,并通过调度机制控制作业的执行时机。本…

1. 引言

在上一篇文章中,我们详细探讨了 Spring Batch 的核心组件(Job、Step、Chunk、ItemReader、ItemProcessor、ItemWriter),并通过示例展示了它们的协作方式。掌握了这些组件后,接下来需要了解如何灵活配置 Spring Batch 作业,并通过调度机制控制作业的执行时机。本文将聚焦以下内容:

  • Spring Batch 的配置方式:XML 配置和 Java 配置的对比与实现。
  • JobParameters 的定义和使用,用于动态传递运行时参数。
  • 调度 Spring Batch 作业:使用 Spring Scheduler、Quartz 或手动触发。
  • 通过代码示例和 Mermaid 图表展示配置和调度的完整流程。

通过本文,你将学会如何根据项目需求配置 Spring Batch 作业,并实现定时或手动触发,为生产环境部署奠定基础。

2. Spring Batch 配置方式

Spring Batch 支持两种主要配置方式:XML 配置Java 配置。Java 配置因其类型安全和现代化特性在 Spring Boot 项目中更常见,但 XML 配置在遗留系统或特定场景中仍有使用价值。以下分别介绍这两种方式。

2.1 Java 配置

Java 配置使用 Spring 的 @Configuration 注解和流式 API(如 JobBuilderStepBuilder)定义 Job 和 Step。上一篇文章的示例已展示了 Java 配置,这里回顾并扩展一个更复杂的配置。

示例:Java 配置多 Step 作业

package com.example.springbatchdemo.config;import com.example.springbatchdemo.entity.Product;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.item.database.JdbcBatchItemWriter;
import org.springframework.batch.item.database.builder.JdbcBatchItemWriterBuilder;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.transaction.PlatformTransactionManager;import javax.sql.DataSource;@Configuration
public class BatchConfiguration {@Beanpublic FlatFileItemReader<Product> reader() {return new FlatFileItemReaderBuilder<Product>().name("productReader").resource(new ClassPathResource("products.csv")).delimited().names("id", "name", "price").targetType(Product.class).build();}@Beanpublic ProductItemProcessor processor() {return new ProductItemProcessor();}@Beanpublic JdbcBatchItemWriter<Product> writer(DataSource dataSource) {return new JdbcBatchItemWriterBuilder<Product>().sql("INSERT INTO product (id, name, price) VALUES (:id, :name, :price)").dataSource(dataSource).beanMapped().build();}@Beanpublic Step importStep(JobRepository jobRepository, PlatformTransactionManager transactionManager) {return new StepBuilder("importStep", jobRepository).<Product, Product>chunk(10).reader(reader()).processor(processor()).writer(writer(dataSource)).transactionManager(transactionManager).build();}@Beanpublic Step logStep(JobRepository jobRepository, PlatformTransactionManager transactionManager) {return new StepBuilder("logStep", jobRepository).tasklet((contribution, chunkContext) -> {System.out.println("Job completed successfully!");return RepeatStatus.FINISHED;}).transactionManager(transactionManager).build();}@Beanpublic Job importProductsJob(JobRepository jobRepository, Step importStep, Step logStep) {return new JobBuilder("importProductsJob", jobRepository).start(importStep).next(logStep).build();}
}

Processor 实现(为完整性重复):

package com.example.springbatchdemo.config;import com.example.springbatchdemo.entity.Product;
import org.springframework.batch.item.ItemProcessor;public class ProductItemProcessor implements ItemProcessor<Product, Product> {private static final double EXCHANGE_RATE = 0.14;@Overridepublic Product process(Product item) {if (item.getPrice() <= 0) {return null;}item.setPrice(item.getPrice() * EXCHANGE_RATE);return item;}
}

说明

  • 使用 @Bean 定义 Reader、Processor、Writer、Step 和 Job。
  • JobBuilderStepBuilder 提供流式 API,清晰定义作业结构。
  • 支持条件流(如 .on("COMPLETED").to(nextStep)),后续文章会深入。

优点

  • 类型安全,编译期检查错误。
  • 与 Spring Boot 集成紧密,易于调试。
  • 代码清晰,适合现代开发。

2.2 XML 配置

XML 配置使用 Spring 的 XML 配置文件定义 Job 和 Step,常见于早期 Spring 项目。以下是将上述 Java 配置转换为 XML 的等效实现。

示例:XML 配置

创建 batch-config.xml(放置在 src/main/resources):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:batch

文章转载自:

http://6beO3Wq9.yhrrL.cn
http://lvlU12Fu.yhrrL.cn
http://IFH0tTbW.yhrrL.cn
http://1zQU8msD.yhrrL.cn
http://jaSdiLxS.yhrrL.cn
http://0q1Q7HFf.yhrrL.cn
http://hlqEQbop.yhrrL.cn
http://dQRvGmcb.yhrrL.cn
http://VK4PJLbY.yhrrL.cn
http://17fECJd4.yhrrL.cn
http://ABXrW6WR.yhrrL.cn
http://J9ntT36M.yhrrL.cn
http://NB8F96v5.yhrrL.cn
http://5uTWgP3H.yhrrL.cn
http://0zsWeO9N.yhrrL.cn
http://da8soqW7.yhrrL.cn
http://YWTk0KLq.yhrrL.cn
http://Z32adGNJ.yhrrL.cn
http://nArRdKRT.yhrrL.cn
http://ZtYChooR.yhrrL.cn
http://yTKGGKxO.yhrrL.cn
http://32OewPR9.yhrrL.cn
http://0VtOXuOO.yhrrL.cn
http://iMNDU7yi.yhrrL.cn
http://MeUy6XhJ.yhrrL.cn
http://Sov07SW2.yhrrL.cn
http://89w8IShK.yhrrL.cn
http://o2YYsVd3.yhrrL.cn
http://yHm0giu9.yhrrL.cn
http://bchFJwtn.yhrrL.cn
http://www.dtcms.com/wzjs/667568.html

相关文章:

  • 免费网站在线观看人数在哪直播少儿编程收费价目表
  • 网站差异吉林智能网站建设价格
  • 哪种网站开发最简单宁波高质量品牌网站设计厂家
  • 织梦可以做论坛网站用代码做网站
  • 网络公司网站建设方案书wordpress后台无法变中文
  • 萍乡做网站好的室内设计网站推荐
  • 金牛区建设审批网站最好的销售管理系统
  • 新乡商城网站建设哪家优惠红鱼洞水库建设管理局网站
  • 网站建设属于哪一类商标网站页脚有什么作用
  • 网站视频做背景试分析网站推广和优化的原因
  • 我的世界怎么做赞助网站合肥网站设计机构
  • 国外比较有名的设计工作室网站wordpress文章分栏
  • 怎么呢搜到自己建设的网站添加网站栏目的步骤
  • 网站注册域名查询推广软文怎么写
  • 门源县住房和城乡建设局网站潍坊大宇网络网站建设
  • 专业做家居的网站湖南省建设监理协会网站
  • 站长工具ip查询手机端网站开发
  • 网站后台密码文件柳州房地产网站建设
  • 引导式网站wordpress分类文章排序
  • 金华网站建设制作ps中怎样做网站轮播图片
  • 网站安全建设方案网上推广引流的有用吗?
  • 网站怎么上传模板wordpress商业版
  • 网站备案幕布大小贵州网站建设维护
  • 一个网站项目开发流程厦门谷歌seo
  • 网站建设数据安全的意义你在四川省建设安全与质量监督网站
  • 高端建站平台设计风格出众拍卖网站建设公司
  • php做直播类型的网站手机免费网站建设
  • 如何进行网站运营与规划wordpress插件汉化下载
  • 公司网站建设内容二手建筑铝模板哪里有卖
  • 上海高端网站建设wordpress空间满