Spring练习,定义三个模块,使用<import>标签完成分模块配置开发,模拟实现学生借书和还书的过程,将结束输出到控制台。
2023-09-27 14:25:56 时间
实现要求
基于node.js开发的文章生成器(四、控制台版本的文章生成器) 持续创作,加速成长!这是我参与「掘金日新计划 10 月更文挑战」的第4天,[点击查看活动详情](https://juejin.cn/post/7147654075599978532 https://juejin.cn/post/7147654075599978532 ) 通过前面的学习,随机句子的选取,段落的生成,文章的生成,我们都已经学会了。接下来我们本次来学习控制台版的狗屁不通文章生成器。 # readline模块的学习与尝试 接下来我们来学习并练习使用readline模块。readline模块是node7之后便开始提供的模块。 接下来我们来详细说说这个模块
不提你可能不知道,spring定时任务的数字星期域不符合常规的cron定义 大家都知道,使用Spring的定时任务非常的简单方便,只需要在配置类上添加@EnableScheduling注解,同时在定时方法上添加@Scheduled(cron = * * 1 * * * )便可以设置一个每天1点定时跑的任务
在图书管理系统中 学生管理模块、书籍管理模块和借还书管理模块等其他模块 相互配合协作 促使系统的运行流畅。定义三个模块 使用 import 标签完成分模块配置开发 模拟实现学生借书和还书的过程 将结束输出到控制台。
要求如下
定义学生管理模块、书籍管理模块和借还书管理模块。使用 import 标签完成分模块配置开发在com.zn.demo.student包下创建Student类 添加stuId属性和stuName属性
package com.zn.mhys.demo.student; public class Student { private String stuId; private String stuName; public String getStuId() { return stuId; public void setStuId(String stuId) { this.stuId stuId; public String getStuName() { return stuName; public void setStuName(String stuName) { this.stuName stuName; }
在com.zn.demo.student包下创建applicationContext-student.xml配置文件 注册Student类到容器
?xml version 1.0 encoding UTF-8 ? beans xmlns:xsi http://www.w3.org/2001/XMLSchema-instance xmlns http://www.springframework.org/schema/beans xsi:schemaLocation http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd bean id student class com.zn.mhys.demo.student.Student /bean /beans
在com.zn.demo.book包下创建Book类 添加bookId属性和bookName属性
package com.zn.mhys.demo.book; public class Book { private String bookId; private String bookName; public String getBookId() { return bookId; public void setBookId(String bookId) { this.bookId bookId; public String getBookName() { return bookName; public void setBookName(String bookName) { this.bookName bookName; }
在com.zn.demo.book包下创建applicationContext-book.xml配置文件 注册Book类到容器。
?xml version 1.0 encoding UTF-8 ? beans xmlns:xsi http://www.w3.org/2001/XMLSchema-instance xmlns http://www.springframework.org/schema/beans xsi:schemaLocation http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd bean id book class com.zn.mhys.demo.book.Book /bean /beans
在com.zn.demo.service包下创建BorrowAndReturnService类 声明borrowBook()方法和returnBook()方法
package com.zn.mhys.demo.service; import com.zn.mhys.demo.book.Book; import com.zn.mhys.demo.student.Student; public class BorrowAndReturnService { public void borrowBook(Student student,Book book){ System.out.println( 学生编号 student.getStuId() 学生姓名 student.getStuName() 借阅书名 book.getBookName() 编号 book.getBookId() 的书名 public void returnBook(Student student,Book book){ System.out.println( 学生编号 student.getStuId() 学生姓名 student.getStuName() 归还书名 book.getBookName() 编号 book.getBookId() 的书名 }
在com.zn.demo.service包下创建applicationContext-service.xml配置文件 注册BorrowAndReturnService类到容器
?xml version 1.0 encoding UTF-8 ? beans xmlns:xsi http://www.w3.org/2001/XMLSchema-instance xmlns http://www.springframework.org/schema/beans xmlns:p http://www.springframework.org/schema/p xmlns:context http://www.springframework.org/schema/context xsi:schemaLocation http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd !-- 2.1.4 -- import resource com/zn/mhys/demo/book/applicationContext-book.xml / import resource com/zn/mhys/demo/student/applicationContext-student.xml / import resource com/zn/mhys/demo/service/applicationContext-service.xml / /beans
在src目录下创建applicationContext.xml配置文件 引入3个模块的配置文件 在com.zn.demo.test包下创建Test测试类
package com.zn.mhys.demo.test; import java.sql.Connection; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.ClassPathResource; import com.zn.mhys.demo.book.Book; import com.zn.mhys.demo.service.BorrowAndReturnService; import com.zn.mhys.demo.service.JdbcService; import com.zn.mhys.demo.student.Student; public class Test { public static void main(String[] args) { ClassPathResource resource new ClassPathResource( applicationContext.xml XmlBeanFactory context new XmlBeanFactory(resource); // 2.1.4 Student student (Student)context.getBean( student student.setStuId( 003 student.setStuName( 杨明金 Book book (Book)context.getBean( book book.setBookId( 130006 book.setBookName( spring企业级开发 BorrowAndReturnService bars (BorrowAndReturnService) context.getBean( service bars.borrowBook(student, book); bars.returnBook(student, book); }
基于node.js开发的文章生成器(四、控制台版本的文章生成器) 持续创作,加速成长!这是我参与「掘金日新计划 10 月更文挑战」的第4天,[点击查看活动详情](https://juejin.cn/post/7147654075599978532 https://juejin.cn/post/7147654075599978532 ) 通过前面的学习,随机句子的选取,段落的生成,文章的生成,我们都已经学会了。接下来我们本次来学习控制台版的狗屁不通文章生成器。 # readline模块的学习与尝试 接下来我们来学习并练习使用readline模块。readline模块是node7之后便开始提供的模块。 接下来我们来详细说说这个模块
不提你可能不知道,spring定时任务的数字星期域不符合常规的cron定义 大家都知道,使用Spring的定时任务非常的简单方便,只需要在配置类上添加@EnableScheduling注解,同时在定时方法上添加@Scheduled(cron = * * 1 * * * )便可以设置一个每天1点定时跑的任务
相关文章
- 在Spring、Hibernate中使用Ehcache缓存(2)
- Spring Boot 自动配置 源码分析
- Spring-Mybatis --- 配置SqlSessionFactoryBean,整合Spring-Mybatis
- 深入实践Spring Boot1.1.3 安装Apache Maven
- 《深入实践Spring Boot》一1.5 关于Spring Boot配置
- SpringMvc学习-4-Spring MVC 拦截器
- SpringMVC4 + Spring + MyBatis3 基于注解的最简配置
- 在eclipse中配置一个简单的spring入门项目
- spring配置c3p0
- Spring Security即将弃用WebSecurityConfigurerAdapter配置类
- Spring 官方出品应用监控度量指标门面类库Micrometer介绍
- Context hierarchy in Spring Web MVC
- 一些spring boot的配置
- spring aop中的propagation(传播属性)的7种配置的意思
- spring security的xml配置
- Spring JDBC框架操作mysql数据库
- Spring中xml文件配置也可以配置容器list、set、map
- 深入理解Spring源码之IOC 扩展原理BeanFactoryPostProcessor和事件监听ApplicationListener
- Spring Cloud Alibaba 微服务组件 Nacos 配置中心(六)
- Spring-Ioc-DI的三种注入方式:
- Spring MVC中前后台数据传输小结
- [转] Spring Boot 自动配置之@Enable* 与@Import注解
- spring beans源码解读之 ioc容器之始祖--DefaultListableBeanFactory
- 为什么要在resources下面的META-INF中配置spring.factories