Jersey是JAX-RS(JavaAPI for RESTful Service)标准的一个实现,用于开发RESTful Web Application。可以参考JAX-RS的介绍(http://www.cnblogs.com/pixy/p/4838268.html),其中的用法适用于JAX-RS标准的所有实现版本。

本文只介绍Jersey MVC的使用。

Jersey定义了一个Viewable的类,当资源方法返回的是Viewable对象时,就代表我们想要把结果转换成视图(MVC模式)。也就是说资源方法可以当成Controller,根据请求生成Model,再分发到View去做呈现。如果想选择一个轻量级的MVC框架,有不想用Servlet当作Controller,Jersey也是一个好的选择。

传统的MVC模式

Jersery用作MVC的模式

使用Jersey MVC

1.添加依赖

Jersey目前提供了JSP和FreeMarker两种模板引擎。Maven中配置如下依赖

<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-mvc</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-mvc-jsp</artifactId>
<version>2.5</version>
</dependency>

2.配置Web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Jersey MVC Sample</display-name> <!-- Jersey -->
   <servlet>
    <servlet-name>Jersey Web Application</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>javax.ws.rs.Application</param-name>
      <param-value>com.pwrd.mobileqa.assist.config.MyApplication</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
      <servlet-name>Jersey Web Application</servlet-name>
      <url-pattern>/api/*</url-pattern>
   </servlet-mapping>
</web-app>

有文章说需要以filter的方式配置Jersery才能集成MVC,不过我按servlet的方式配置也没有遇到问题。

3.自定义Application类,添加有关MVC的设置

JspMvcFeatrue用来描述要使用Jersey MVC特性,并且使用的是JSP模板引擎。JspMvcFeatrue.TEMPLATES_BASE_PATH配置了JSP的root路径,构建Viewable视图时会该路径中查找template。

package tw.com.codedata.jersey;

import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.mvc.jsp.JspMvcFeature; public class MyApplication extends ResourceConfig{
public MyApplication(){
packages("tw.com.codedata.jersey.controller");
register(JspMvcFeature.class);
property(JspMvcFeature.TEMPLATES_BASE_PATH, "/WEB-INF/jsp");
}
}

4.然后就是实现资源方法(返回Viewable对象)和实现JSP页

@Path("/hello")
public class HelloController {
@GET
public Viewable sayHello(@QueryParam("name") @DefaultValue("World") String name) {
HashMap model = new HashMap();
model.put("name", name);
return new Viewable("/hello", model);
}   //使用Template注解的方式
  @GET
  @Template(name="/index.jsp")
  @Produces("text/html")
  public String[] list() {
String[] macs= new String[]{"aaaa","bbbb"} ;
}
}
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
  <head>
  </head>
  <body>
    Hello, <c:out value="${it.name}" />
  </body>
</html>

参考资料

  http://www.codedata.tw/java/java-restful-3-jersey-mvc/

  https://jersey.java.net/documentation/latest/user-guide.html#mvc

下面附上官方文档中的详细讲解

----------------------------

Chapter 20. MVC Templates

Jersey provides an extension to support the Model-View-Controller (MVC) design pattern. In the context of Jersey components, the Controller from the MVC pattern corresponds to a resource class or method, the View to a template bound to the resource class or method, and the model to a Java object (or a Java bean) returned from a resource method (Controller).

Note

Some of the passages/examples from this chapter have been taken from MVCJ blog article written by Paul Sandoz.

In Jersey 2, the base MVC API consists of two classes (org.glassfish.jersey.server.mvc package) that can be used to bind model to view (template), namely Viewable and@Template. These classes determine which approach (explicit/implicit) you would be taking when working with Jersey MVC templating support.

20.1. Viewable

In this approach a resource method explicitly returns a reference to a view template and the data model to be used. For this purpose the Viewable class has been introduced in Jersey 1 and is also present (under a different package) in Jersey 2. A simple example of usage can be seen in Example 20.1, “Using Viewable in a resource class”.

Example 20.1. Using Viewable in a resource class

1
2
3
4
5
6
7
8
9
10
package com.example;
 
@Path("foo")
public class Foo {
 
    @GET
    public Viewable get() {
        return new Viewable("index.foo", "FOO");
    }
}

In this example, the Foo JAX-RS resource class is the controller and the Viewable instance encapsulates the provided data model (FOO string) and a named reference to the associated view template (index.foo).

Tip

All HTTP methods may return Viewable instances. Thus a POST method may return a template reference to a template that produces a view as a result of processing an HTML Form.

20.2. @Template

20.2.1. Annotating Resource methods

There is no need to use Viewable every time you want to bind a model to a template. To make the resource method more readable (and to avoid verbose wrapping of a template reference and model into Viewable) you can simply annotate a resource method with @Template annotation. An updated example, using @Template, from previous section is shown in Example 20.2, “Using @Template on a resource method” example.

Example 20.2. Using @Template on a resource method

1
2
3
4
5
6
7
8
9
10
11
package com.example;
 
@Path("foo")
public class Foo {
 
    @GET
    @Template("index.foo")
    public String get() {
        return "FOO";
    }
}

In this example, the Foo JAX-RS resource class is still the controller as in previous section but the MVC model is now represented by the return value of annotated resource method.

The processing of such a method is then essentially the same as if the return type of the method was an instance of the Viewable class. If a method is annotated with@Template and is also returning a Viewable instance then the values from the Viewable instance take precedence over those defined in the annotation. Producible media types are for both cases, Viewable and @Template, determined by the method or class level @Produces annotation.

20.2.2. Annotating Resource classes

A resource class can have templates implicitly associated with it via @Template annotation. For example, take a look at the resource class listing in Example 20.3, “Using@Template on a resource class”.

Example 20.3. Using @Template on a resource class

1
2
3
4
5
6
7
8
@Path("foo")
@Template
public class Foo {
 
    public String getFoo() {
        return "FOO";
    }
}

The example relies on Jersey MVC conventions a lot and requires more explanation as such. First of all, you may have noticed that there is no resource method defined in this JAX-RS resource. Also, there is no template reference defined. In this case, since the @Template annotation placed on the resource class does not contain any information, the default relative template reference index will be used (for more on this topic see Section 20.3, “Absolute vs. Relative template reference”). As for the missing resource methods, a default @GET method will be automatically generated by Jersey for the Foo resource (which is the MVC Controller now). The implementation of the generated resource method performs the equivalent of the following explicit resource method:

1
2
3
4
@GET
public Viewable get() {
    return new Viewable("index", this);
}

You can see that the resource class serves in this case also as the model. Producible media types are determined based on the @Produces annotation declared on the resource class, if any.

Note

In case of "resource class"-based implicit MVC view templates, the controller is also the model. In such case the template reference index is special, it is the template reference associated with the controller instance itself.

In the following example, the MVC controller represented by a JAX-RS @GET sub-resource method, is also generated in the resource class annotated with @Template:

1
2
3
4
5
@GET
@Path("{implicit-view-path-parameter}")
public Viewable get(@PathParameter("{implicit-view-path-parameter}") String template) {
    return new Viewable(template, this);
}

This allows Jersey to support also implicit sub-resource templates. For example, a JAX-RS resource at path foo/bar will try to use relative template reference bar that resolves to an absolute template reference /com/foo/Foo/bar.

In other words, a HTTP GET request to a /foo/bar would be handled by this auto-generated method in the Foo resource and would delegate the request to a registered template processor supports processing of the absolute template reference /com/foo/Foo/bar, where the model is still an instance of the same JAX-RS resource class Foo.

20.3. Absolute vs. Relative template reference

As discussed in the previous section, both @Template and Viewable provide means to define a reference to a template. We will now discuss how these values are interpreted and how the concrete template is found.

20.3.1. Relative template reference

Relative reference is any path that does not start with a leading '/' (slash) character (i.e. index.foo). This kind of references is resolved into absolute ones by pre-pending a given value with a fully qualified name of the last matched resource.

Consider the Example 20.3, “Using @Template on a resource class” from the previous section, the template name reference index is a relative value that Jersey will resolve to its absolute template reference using a fully qualified class name of Foo (more on resolving relative template name to the absolute one can be found in the JavaDoc ofViewable class), which, in our case, is:

"/com/foo/Foo/index"

Jersey will then search all the registered template processors (see Section 20.7, “Writing Custom Templating Engines”) to find a template processor that can resolve the absolute template reference further to a "processable" template reference. If a template processor is found then the "processable" template is processed using the supplied data model.

Note

If none or empty template reference is provided (either in Viewable or via @Template) then the index reference is assumed and all further processing is done for this value.

20.3.2. Absolute template reference

Let's change the resource GET method in our Foo resource a little:

Example 20.4. Using absolute path to template in Viewable

1
2
3
4
@GET
public Viewable get() {
    return new Viewable("/index", "FOO");
}

In this case, since the template reference begins with "/", Jersey will consider the reference to be absolute already and will not attempt to absolutize it again. The reference will be used "as is" when resolving it to a "processable" template reference as described earlier.

Absolute template references start with leading '/' (i.e. /com/example/index.foo) character and are not further resolved (with respect to the resolving resource class) which means that the template is looked for at the provided path directly.

Note, however, that template processors for custom templating engines may modify (and the supported ones do) absolute template reference by pre-pending 'base template path' (if defined) and appending template suffix (i.e. foo) if the suffix is not provided in the reference.

For example assume that we want to use Mustache templates for our views and we have defined 'base template path' as pages. For the absolute template reference/com/example/Foo/index the template processor will transform the reference into the following path: /pages/com/example/Foo/index.mustache.

20.4. Handling errors with MVC

In addition to @Template a @ErrorTemplate annotation has been introduced in Jersey 2.3. The purpose of this annotation is to bind the model to an error view in case an exception has been raised during processing of a request. This is true for any exception thrown after the resource matching phase (i.e. this not only applies to JAX-RS resources but providers and even Jersey runtime as well). The model in this case is the thrown exception itself.

Example 20.5, “Using @ErrorTemplate on a resource method” shows how to use @ErrorTemplate on a resource method. If all goes well with the method processing, then the /short-link template is used to as page sent to the user. Otherwise if an exception is raised then the /error-form template is shown to the user.

Example 20.5. Using @ErrorTemplate on a resource method

1
2
3
4
5
6
7
8
@POST
@Produces({"text/html”})
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Template(name = "/short-link")
@ErrorTemplate(name = "/error-form")
public ShortenedLink createLink(@FormParam("link") final String link) {
    // ...
}

Note that @ErrorTemplate can be used on a resource class or a resource method to merely handle error states. There is no need to use @Template or Viewable with it.

The annotation is handled by custom ExceptionMapper<E extends Throwable> which creates an instance of Viewable that is further processed by Jersey. This exception mapper is registered automatically with a MvcFeature.

20.4.1. MVC & Bean Validation

@ErrorTemplate can be used in also with Bean Validation to display specific error pages in case the validation of input/output values fails for some reason. Everything works as described above except the model is not the thrown exception but rather a list of ValidationErrors. This list can be iterated in the template and all the validation errors can be shown to the user in a desirable way.

Example 20.6. Using @ErrorTemplate with Bean Validation

1
2
3
4
5
6
7
8
@POST
@Produces({"text/html”})
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Template(name = "/short-link”) @ErrorTemplate(name = "/error-form")
@Valid
public ShortenedLink createLink(@NotEmpty @FormParam("link") final String link) {
    // ...
}

Example 20.7. Iterating through ValidationError in JSP

1
2
3
<c:forEach items="${model}" var="error">
    ${error.message} "<strong>${error.invalidValue}</strong>"<br/>
</c:forEach>

Support for Bean Validation in Jersey MVC Templates is provided by a jersey-mvc-bean-validation extension module. The JAX-RS Feature provided by this module (MvcBeanValidationFeature) has to be registered in order to use this functionality (see Section 20.5, “Registration and Configuration”).

Maven users can find this module at coordinates

1
2
3
4
5
<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-mvc-bean-validation</artifactId>
    <version>2.22</version>
</dependency>

and for non-Maven users the list of dependencies is available at jersey-mvc-bean-validation.

20.5. Registration and Configuration

To use the capabilities of Jersey MVC templating support in your JAX-RS/Jersey application you need to register specific JAX-RS Features provided by the MVC modules. Forjersey-mvc module it is MvcFeature for others it could be, for example, FreemarkerMvcFeature (jersey-mvc-freemarker).

Example 20.8. Registering MvcFeature

1
2
3
4
new ResourceConfig()
    .register(org.glassfish.jersey.server.mvc.MvcFeature.class)
    // Further configuration of ResourceConfig.
    .register( ... );

Example 20.9. Registering FreemarkerMvcFeature

1
2
3
4
new ResourceConfig()
    .register(org.glassfish.jersey.server.mvc.freemarker.FreemarkerMvcFeature.class)
    // Further configuration of ResourceConfig.
    .register( ... );

Note

Modules that uses capabilities of the base Jersey MVC module register MvcFeature automatically, so you don't need to register this feature explicitly in your code.

Almost all of the MVC modules are further configurable and either contain a *Properties (e.g. FreemarkerMvcProperties) class describing all the available properties which could be set in a JAX-RS Application / ResourceConfig. Alternatively, the properties are listed directly in the module *Feature class.

Example 20.10. Setting MvcFeature.TEMPLATE_BASE_PATH value in ResourceConfig

1
2
3
4
5
new ResourceConfig()
    .property(MvcFeature.TEMPLATE_BASE_PATH, "templates")
    .register(MvcFeature.class)
    // Further configuration of ResourceConfig.
    .register( ... );

Example 20.11. Setting FreemarkerMvcProperties.TEMPLATE_BASE_PATH value in web.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
<servlet>
    <servlet-name>org.glassfish.jersey.examples.freemarker.MyApplication</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>org.glassfish.jersey.examples.freemarker.MyApplication</param-value>
    </init-param>
    <init-param>
        <param-name>jersey.config.server.mvc.templateBasePath.freemarker</param-name>
        <param-value>freemarker</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

20.6. Supported templating engines

Jersey provides extension modules that enable support for several templating engines. This section lists all the supported engines and their modules as well as discusses any module-specific details.

20.6.1. Mustache

An integration module for Mustache-based templating engine.

Mustache template processor resolves absolute template references to processable template references represented as Mustache templates as follows:

Procedure 20.1. Resolving Mustache template reference

  1. if the absolute template reference does not end in .mustache append this suffix to the reference; and

  2. if ServletContext.getResourceClass.getResource or File.existsreturns a non-null value for the reference then return the reference as the processable template reference otherwise return null (to indicate the absolute reference has not been resolved by the Mustache template processor).

Thus the absolute template reference /com/foo/Foo/index would be resolved as /com/foo/Foo/index.mustache, provided there exists a /com/foo/Foo/index.mustacheMustache template in the application.

Available configuration properties:

  • MustacheMvcFeature.TEMPLATE_BASE_PATH - jersey.config.server.mvc.templateBasePath.mustache

    The base path where Mustache templates are located.

  • MustacheMvcFeature.CACHE_TEMPLATES - jersey.config.server.mvc.caching.mustache

    Enables caching of Mustache templates to avoid multiple compilation.

  • MustacheMvcFeature.TEMPLATE_OBJECT_FACTORY - jersey.config.server.mvc.factory.mustache

    Property used to pass user-configured MustacheFactory.

  • MustacheMvcFeature.ENCODING - jersey.config.server.mvc.encoding.mustache

    Property used to configure a default encoding that will be used if none is specified in @Produces annotation. If property is not defined the UTF-8 encoding will be used as a default value.

Maven users can find this module at coordinates

1
2
3
4
5
<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-mvc-mustache</artifactId>
    <version>2.22</version>
</dependency>

and for non-Maven users the list of dependencies is available at jersey-mvc-mustache.

20.6.2. Freemarker

An integration module for Freemarker-based templating engine.

Freemarker template processor resolves absolute template references to processable template references represented as Freemarker templates as follows:

Procedure 20.2. Resolving Freemarker template reference

  1. if the absolute template reference does not end in .ftl append this suffix to the reference; and

  2. if ServletContext.getResourceClass.getResource or File.existsreturns a non-null value for the reference then return the reference as the processable template reference otherwise return null (to indicate the absolute reference has not been resolved by the Freemarker template processor).

Thus the absolute template reference /com/foo/Foo/index would be resolved to /com/foo/Foo/index.ftl, provided there exists a /com/foo/Foo/index.ftl Freemarker template in the application.

Jersey will assign the model instance to an attribute named model. So it is possible to reference the foo key from the provided Map (MVC Model) resource from the Freemarker template as follows:

<h1>${model.foo}</h1>

Available configuration properties:

  • FreemarkerMvcFeature.TEMPLATE_BASE_PATH - jersey.config.server.mvc.templateBasePath.freemarker

    The base path where Freemarker templates are located.

  • FreemarkerMvcFeature.CACHE_TEMPLATES - jersey.config.server.mvc.caching.freemarker

    Enables caching of Freemarker templates to avoid multiple compilation.

  • FreemarkerMvcFeature.TEMPLATE_OBJECT_FACTORY - jersey.config.server.mvc.factory.freemarker

    Property used to pass user-configured FreemarkerFactory.

  • FreemarkerMvcFeature.ENCODING - jersey.config.server.mvc.encoding.freemarker

    Property used to configure a default encoding that will be used if none is specified in @Produces annotation. If property is not defined the UTF-8 encoding will be used as a default value.

Maven users can find this module at coordinates

1
2
3
4
5
<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-mvc-freemarker</artifactId>
    <version>2.22</version>
</dependency>

and for non-Maven users the list of dependencies is available at jersey-mvc-freemarker.

20.6.3. JSP

An integration module for JSP-based templating engine.

Limitations of Jersey JSP MVC Templates

Jersey web applications that want to use JSP templating support should be registered as Servlet filters rather than Servlets in the application's web.xml. Theweb.xml-less deployment style introduced in Servlet 3.0 is not supported at the moment for web applications that require use of Jersey MVC templating support.

JSP template processor resolves absolute template references to processable template references represented as JSP pages as follows:

Procedure 20.3. Resolving JSP template reference

  1. if the absolute template reference does not end in .jsp append this suffix to the reference; and

  2. if ServletContext.getResource returns a non-null value for the reference then return the reference as the processable template reference otherwise return null(to indicate the absolute reference has not been resolved by the JSP template processor).

Thus the absolute template reference /com/foo/Foo/index would be resolved to /com/foo/Foo/index.jsp, provided there exists a /com/foo/Foo/index.jsp JSP page in the web application.

Jersey will assign the model instance to the attribute named model or it. So it is possible to reference the foo property on the Foo resource from the JSP template as follows:

<h1>${model.foo}</h1>

or

<h1>${it.foo}</h1>

To include another JSP page in the currently processed one a custom include tag can be used. Mandatory parameter page represents a relative template name which would be absolutized using the same resolving resource class as the parent JSP page template.

Example 20.12. Including JSP page into JSP page

1
2
3
4
5
6
7
8
9
10
11
12
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
 
<%@taglib prefix="rbt" uri="urn:org:glassfish:jersey:servlet:mvc" %>
 
<html>
    <body>
 
    <rbt:include page="include.jsp"/>
 
    </body>
</html>

Available configuration properties:

  • JspMvcFeature.TEMPLATE_BASE_PATH - jersey.config.server.mvc.templateBasePath.jsp

    The base path where JSP templates are located.

Maven users can find this module at coordinates

1
2
3
4
5
<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-mvc-jsp</artifactId>
    <version>2.22</version>
</dependency>

and for non-Maven users the list of dependencies is available at jersey-mvc-jsp.

20.7. Writing Custom Templating Engines

To add support for other (custom) templating engines into Jersey MVC Templating facility, you need to implement the TemplateProcessor and register this class into your application.

Tip

When writing template processors it is recommend that you use an appropriate unique suffix for the processable template references, in which case it is then possible to easily support mixing of multiple templating engines in a single application without conflicts.

Example 20.13. Custom TemplateProcessor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@Provider
class MyTemplateProcessor implements TemplateProcessor<String> {
 
    @Override
    public String resolve(String path, final MediaType mediaType) {
        final String extension = ".testp";
 
        if (!path.endsWith(extension)) {
            path = path + extension;
        }
 
        final URL u = this.getClass().getResource(path);
        return u == null ? null : path;
    }
 
    @Override
    public void writeTo(String templateReference,
                        Viewable viewable,
                        MediaType mediaType,
                        OutputStream out) throws IOException {
        final PrintStream ps = new PrintStream(out);
        ps.print("path=");
        ps.print(templateReference);
        ps.println();
        ps.print("model=");
        ps.print(viewable.getModel().toString());
        ps.println();
    }
 
}

Example 20.14. Registering custom TemplateProcessor

1
2
3
4
new ResourceConfig()
    .register(MyTemplateProcessor.class)
    // Further configuration of ResourceConfig.
    .register( ... );

Note

In a typical set-up projects using the Jersey MVC templating support would depend on the base module that provides the API and SPI and a single templating engine module for the templating engine of your choice. These modules need to be mentioned explicitly in your pom.xml file.

If you want to use just templating API infrastructure provided by Jersey for the MVC templating support in order to implement your custom support for a templating engine other than the ones provided by Jersey, you will need to add the base jersey-mvc module into the list of your dependencies:

1
2
3
4
5
<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-mvc</artifactId>
    <version>2.22</version>
</dependency>

20.8. Other Examples

To see an example of MVC (JSP) templating support in Jersey refer to the MVC (Bookstore) Example.

Jersey MVC的更多相关文章

  1. Java实现Restful框架Jersey学习

    Java与REST的邂逅(一):浅谈Jersey及JAX-RS Java与REST的邂逅(二):JAX-RS核心Annotation Java与REST的邂逅(三):浅谈Jersey MVC

  2. (原创)spring mvc和jersey rest 组合使用时单例对像实例化两次的BUG及解决办法

    项目中没用spring 的restTemplate 而是采用 jersey来做rest 的实现,一直用着,也没发现有什么不对,后来加入了,以quartz用硬编码方式实现,结果启动项目的时候报错 ,具体 ...

  3. Beyond REST: How to build a HATEOAS API in Java with Spring MVC, Jersey (JAX-RS) and VRaptor

    http://zeroturnaround.com/rebellabs/beyond-rest-how-to-build-a-hateoas-api-in-java-with-spring-mvc-j ...

  4. JAX-RS(基于Jersey) + Spring 4.x + MyBatis构建REST服务架构

    0. 大背景 众所周知,REST架构已经成为现代服务端的趋势. 很多公司,已经采用REST作为App, H5以及其它客户端的服务端架构. 1. 什么是JAX-RS? JAX-RS是JAVA EE6 引 ...

  5. Restful、Jersey和JAX-RS

     一:MVC与SpringMVC MVC:是一种思想,是一种设计模式 SpringMVC:是一个框架,实现了MVC这种思想. 之前:写JSP页面,比较繁琐.eg:在页面显示用户列表,我们会在JSP页面 ...

  6. Jersey VS Django-Rest

    在对Restful服务框架做对比前,主要先说说Restful设计的三大主要元素:以资源为核心的资源方法.资源状态.关系链接超媒体表述. 辅助的有内容协商.安全.版本化设计等. Jersey作为Java ...

  7. 关于使用spring mvc或者resteasy构建restful服务的差别与比较

    resteasy 是 jboss的一个开源java api for restful service(JSR 311,sun 2008年发布,最新GA版本是2.0, JAX-RS 2.0 (JSR-33 ...

  8. SpringBoot配置属性之MVC

    SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...

  9. 【jersey】 spring 整合jersey 实现RESTful webservice

         Jersey是一个RESTFUL请求服务JAVA框架,与常规的JAVA编程使用的struts框架类似,它主要用于处理业务逻辑层.与Struts类似,它同样可以和hibernate,sprin ...

随机推荐

  1. CSS鼠标样式整理

    鼠标样式的标签: cursor:*;  //该属性定义了鼠标指针放在一个元素边界范围内时所用的光标形状: 鼠标样式: 值 描述 url 需使用的自定义光标的 URL. 注释:请在此列表的末端始终定义一 ...

  2. icon上添加数字提醒

    使用viewbadger包: package com.jingle.vierbagerstudy; import android.app.Activity; import android.os.Bun ...

  3. Git Fast-forward提交

    多人协同开发,使用Git经常会看到警告信息包含术语:Fast-forward, 这是何义? 简单来说就是提交到远程中心仓库的代码必须是按照时间顺序的. 比如A从中心仓库拿到代码后,对文件f进行了修改. ...

  4. Java hour 52 Weather

    采用jetty 后,默认的welcome-file-list 配置失效了,直接跳转到了struts2 的control 中去了. <welcome-file-list> <welco ...

  5. Java Hour 9

    有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. 本文作者Java 现经验约为7 Hour,请各位不吝赐教. Hour 9 方法 ...

  6. JNDI 是什么

    转自:http://blog.csdn.net/zhaosg198312/article/details/3979435 JNDI是 Java 命名与目录接口(Java Naming and Dire ...

  7. BEGIN TRAN...COMMIT TRAN 意思与用法

    BEGIN TRAN标记事务开始 COMMIT TRAN 提交事务 一般把DML语句(select ,delete,update,insert语句)放在BEGIN TRAN...COMMIT TRAN ...

  8. Android 编程下的 Secret Code

    我们很多人应该都做过这样的操作,打开拨号键盘输入 *#*#4636#*#* 等字符就会弹出一个界面显示手机相关的一些信息,这个功能在 Android 中被称为 Android Secret Code, ...

  9. .Net AppDomain.CurrentDomain.AppendPrivatePath(@"Libs");

    今天就说说.Net中通过反射取得某个类型时,我们怎么知道这个类型在硬盘上的哪个角落?比如说,假如我们需要要求服务端动态载入某个数据源,那服务端怎么知道数据源在哪?网上大部分的教程都写着,可以使用Ass ...

  10. Sql 字符串替换

    (1) 字符串替换 Update SongADD_EMH0055 SET songno = REPLACE(songno, '231', '233') where songno like '%1022 ...