反向代理服务器的工作原理

(一)概述

反向代理(Reverse Proxy)方式是指以代理服务器来接受Internet上的连接请求,然后将请求转发给内部网络上的服务器;并将从服务器上得到的结果返回给Internet上请求连接的客户端,此时代理服务器对外就表现为一个服务器。

MyBatis使用properties配置及类别名使用

(一)将连接数据库的配置单独放在一个properties文件中

可以直接将数据库的连接配置信息写在MyBatis的conf.xml文件中,如下:

MyBatis实现关联表查询

(一)一对一关联

1.1 提出需求

根据班级id查询班级信息(带老师信息)

Spring MVC @ModelAttribute Annotation Example

In this page we will learn how to use @ModelAttribute annotation in our spring MVC application. @ModelAttribute binds method parameter or the method response to a named model attribute. @ModelAttribute has an element as value. @ModelAttribute can be used at method level as well as parameter level. The use of @ModelAttribute at parameter level is to accept the value of form from the web request. The one use of @ModelAttribute at method level is assigning values to Model as default. This method will be created in the class annotated with @ModelAttribute. Here we will discuss both approach with example.

Spring MVC Exception Handling and Global Exception Example

Spring provides a robust exception handling framework. We can handle exceptions using @ResponseStatus, @ExceptionHandler, HandlerExceptionResolver and @ControllerAdvice. @ResponseStatus defines a status code for the given exception and can be used at custom exception class level and method level with @ExceptionHandler in controller. In controller class, we can define handler method using @ExceptionHandler and this will be controller specific. To handle exception globally, spring provides @ControllerAdvice that will be available for every controller. Define a class for global exception and annotate it with @ControllerAdvice and we need to define methods using @ExceptionHandler annotation within the class. Spring provides one more approach to handle exception. Use HandlerExceptionResolver in spring XML or java configuration where we can define mappings of exception type and view name. Find the complete example with description.

Spring MVC @ControllerAdvice Annotation Example

@ControllerAdvice annotation is a specialization of @Component. The classes annotated with @ControllerAdvice are auto detected by classpath scanning. The use of @ControllerAdvice is advising all or selected controllers for @ExceptionHandler, @InitBinder and @ModelAttribute. What we have to do is create a class annotated with @ControllerAdvice and create required method which will be annotated with @ExceptionHandler for global exception handling, @InitBinder for global init binding and @ModelAttribute for global model attributes addition. Whenever a request comes to controller and its method with @RequestMapping and if there is no locally defined @ExceptionHandler, @InitBinder and @ModelAttribute, the globally defined class annotated with @ControllerAdvice is served. 

Spring中集成RMI的方法

Spring提供了非常方便的RMI(远程方法调用)调用方式,本文介绍下如何在Spring中集成RMI。

使用Gulp作为Web开发服务器

构建工具Gulp.js最近正在变得越来越流行。我们可以用它做很多事,比如合并Javascript文件或者压缩图片。本文将向你介绍如何使用Gulp.js来作为本地Web服务器,而且是内置livereload支持的哦。

前端构建工具Gulp.js简单实例

在软件开发中使用自动化构建工具的好处是显而易见的。通过工具自动化运行大量单调乏味、重复性的任务,比如图像压缩、文件合并、代码压缩、单元测试等等,可以为开发者节约大量的时间,使我们能够专注于真正重要的、有意义的工作,比如设计业务逻辑,编写代码等等。

SpringMVC之Controller常用注解功能全解析

一、简介

在SpringMVC中,控制器Controller负责处理由DispatcherServlet分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model ,然后再把该Model返回给对应的View进行展示。在SpringMVC 中提供了一个非常简便的定义Controller 的方法,你无需继承特定的类或实现特定的接口,只需使用@Controller标记一个类是Controller,然后使用@RequestMapping和@RequestParam等一些注解用以定义URL 请求和Controller方法之间的映射,这样的Controller就能被外界访问到。此外Controller不会直接依赖于HttpServletRequest和HttpServletResponse等HttpServlet 对象,它们可以通过Controller的方法参数灵活的获取到。