摘要:IoC (Inverse of Control) IoC ,也就是 控制反转。 对于软件来说,即某一接口具体实现类的选择控制权从调用类中移除,转交给第三方决定,即由Spring容器借由Bean配置来进行控制。 Martin Fowler提出了DI(Dependency Injection,依赖注入)
阅读全文
摘要:@Cacheable 注解的使用 开发中经常会使用Redis 缓存,可以使用 @Cacheable 相关的注解来操作缓存。 详情见:https://blog.csdn.net/sinat_32502451/article/details/134310654 CacheManager @Cacheab
阅读全文
摘要:使用场景 在开发中,需要使用缓存时,可以使用 @Cacheable 、 @CachePut 、@CacheEvict 注解。 注意: @Cacheable 、 @CachePut 、@CacheEvict 是基于 Aop 动态代理实现的。 因此,如果在同一个类里面,调用 @Cacheable 注解的
阅读全文
摘要:实践理解 Transactional 是否生效 示例: 新建一个订单表 tb_order_test 。 手动插入一条数据。 然后在代码中,根据 id 更新,如果更新成功,那么 update_time 会变化。 代码中执行 1/0; 由于 0不能做为除数,代码会抛异常。 通过 updateTime 观
阅读全文
摘要:### @PostConstruct 以Post为前缀的单词,指 在...之后。比如 postgraduate 就有大学毕业后的意思。 Construct 是构造方法。 @PostConstruct 是指在构造方法之后运行的意思。 ### 执行顺序: Constructor(构造方法) -> @Po
阅读全文
摘要:### @Configuration 和 @Bean * @Configuration 用于定义配置类,作用在类上。 * @Bean 用于定义 Bean对象,作用在方法上。 @Configration 注解类中可以声明一个或多个 @Bean 方法 ### User 类 ``` public clas
阅读全文
摘要:问题描述 Spring报错: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type '' available: expected at least
阅读全文
摘要:IDEA启动项目报错 Caused by: java.io.FileNotFoundException: class path resource [.properties] cannot be opened because it does not exist 解决方法: 1.检查文件的路径是否正确,
阅读全文
摘要:背景 有时我们需要在一些不属于Spring的类中,去调用Spring的Service类的方法。 比如,在Util类,或者main()方法中,去调用Service类的方法。 这时,可以使用 ApplicationContextAware接口 和 ApplicationContext接口 . Appli
阅读全文
摘要:Request(请求) 1.获取并打印request的body中的参数。 这种获取请求中代码,一般都会封装成工具类。 如果不封装,写起来比较麻烦,类似如下: JSONObject res = new JSONObject(); String postData = null; try { postDa
阅读全文
摘要:1.使用HttpServletResponse的sendRedirect()方法。 示例: 2.返回"redirect:"加上url。 注意:这种方式,不能使用@RestController和@ResponseBody,否则只会返回一堆字符串。 如下: 参考资料: https://blog.csdn
阅读全文
摘要:@PathVariable是占位符注解。可以把Url中变量的值传递到方法参数中。 示例如下: 当我们输入的Url类似于 localhost:8080/user/name/1时,Controller层对应方法getUserName的参数id就会赋值为1。 但是要注意: 1.控制层的Url占位符{}中的
阅读全文
摘要:Request method 'GET' not supported 错误原因: GET请求不被允许。 解决方法: 1.从客户端入手。假设浏览器中的js用了ajax发起异步请求GET,将GET改为POST。 2.从服务端入手。Controller层的 @RequestMapping( method
阅读全文
摘要:Required String parameter ' ' is not present 报错原因: url中的参数错误。 解决方法: 1.修正url中的参数的值。 2.在Controller层中的@RequestParamrequired = false 也就是 @RequestParam(val
阅读全文
摘要:错误1: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. 解决方案: http://www.c
阅读全文
摘要:摘自网络博客。 学会如何读一个JavaWeb项目源代码 步骤:表结构->web.xml->mvc->db->spring ioc->log->代码 1、先了解项目数据库的表结构,这个方面是最容易忘记的,有时候我们只顾着看每一个方法是怎么进行的,却没有去了解数据库之间的主外键关联。其实如果先了解数据库
阅读全文
摘要:今天在配置SpringMVC时,访问项目一直出现404,无法访问。 报错: The origin server did not find a current representation for the target resource or is not willing to disclose th
阅读全文
摘要:spring集成mybatis,配置多个数据源并自动切换。 spring-mybatis.xml如下: spring-mvc配置如下: Dao层如下: EsbTraceDao如下: WorkOrderDao如下: Service层的如下: EsbTraceServiceImpl.java如下: 注意
阅读全文
摘要:首先在Service层上面添加 @Service("myService") 然后,在main方法中调用,String[]中为配置文件,如下所示:
阅读全文
摘要:一、基本概念 在java中,可以通过Quatz框架来实现定时任务。 Quartz主要包括以下部分: 1.scheduler:调度器,可以把任务和触发器注册到任务调度器中,然后启动调度器。 2.Trigger :触发器,包括SimpleTrigger和CronTrigger。CronTrigger可以
阅读全文