使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API

栏目: Hibernate · 发布时间: 7年前

内容简介:介绍通过 Intellij IDEA 来创建一个 RESETful API 项目,该项目适用于基于 JavaWEB 后端技术的项目,相关技术包含 Maven、Jersey、Hibernate 等,这里不对这些技术进行过多的详细介绍,只是创建一个简单的入门项目用于学习附上破解教程

介绍通过 Intellij IDEA 来创建一个 RESETful API 项目,该项目适用于基于 JavaWEB 后端技术的项目,相关技术包含 Maven、Jersey、Hibernate 等,这里不对这些技术进行过多的详细介绍,只是创建一个简单的入门项目用于学习

Intellij IDEA

Intellij IDEA 官网

附上破解教程 IntelliJ IDEA 2017.3.2永久破解版

JDK 和 Tomcat

10.*
9.*

这里就不介绍如何安装 JDK 和 Tomcat

创建 Web Application 项目

Java JDK 将其配置成安装的版本,Tomcat 服务器也一样配置成最新的版本

使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API

点击 Next 进入一下,配置一下项目名

使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API

点击 Finish 完成,在项目名上右键 -> Add Frameworks Support 把 maven 项目的支持引入

使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API 使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API

配置 pom.xml

将以下 XML 代码复制到项目的 pom.xml 文件中,注意Intellij IDEA 生成的 pom.xml 文件无须更改,只需要将以下代码复制到 project 标签以内即可

<properties>
    <maven.compiler.source>10.0.1</maven.compiler.source>
    <maven.compiler.target>10.0.1</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jersey.version>2.27</jersey.version>
</properties>

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.containers/jersey-container-servlet -->
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-server -->
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client -->
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-json-jackson -->
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-moxy -->
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-multipart -->
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-multipart</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.glassfish.jersey.inject/jersey-hk2 -->
    <dependency>
        <groupId>org.glassfish.jersey.inject</groupId>
        <artifactId>jersey-hk2</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-json -->
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.19.4</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>javax.ws.rs-api</artifactId>
        <version>2.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt</artifactId>
        <version>0.9.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.glassfish.hk2/hk2 -->
    <dependency>
        <groupId>org.glassfish.hk2</groupId>
        <artifactId>hk2</artifactId>
        <version>2.5.0-b61</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl -->
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.3.0.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>2.3.0.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.activation/activation -->
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.11</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.3.3.Final</version>
    </dependency>
</dependencies>

保存文件之后,会弹出以下提示界面,点击 Enable Auto-Import 即可将会为你自动下载依赖

使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API

在项目中引入依赖

点击右侧的 Maven Pjojects 检查依赖包是否全部下载完整,当然如果是第一次下载的话是需要些时间,耐心等待即可,如果长时间没有下载完整,则需手动点击 Reimport All Maven Pjojects 或者 Download Sourse and/or Documentation ,未完成下载表现为 pom.xml 中有红色字体出现,或者以下界面的依赖包会有红色的波浪线

使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API

按下快捷键 Ctrl++Alt+Shift+S 呼出项目配置,将 Maven 引入的 jar 包放到 lib 文件夹下

使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API

Hello Wolrd 测试

src/main/java 中创建包 com.API.actions 用来保存测试类文件

新建 Hello.java ,将以下代码复制进去即可

package com.API.actions;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("hello")

public class Hello {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String sayHello() {
        return "Hello,I am text!";
    }

}

配置 web.xml

<servlet>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.API.actions</param-value>
        <!-- 这里的配置包路经必须是与之间创立用于存储测试类的包路径一致 -->
    </init-param>

    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

点击启动 Tomcat 服务,稍等片刻

使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API

在浏览器中输入 http://127.0.0.1:8080/api/hello 即可看到结果

使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API

PostMan 里也可以获取结果

使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API

Intellij IDEA 集成 JRebel

setting 中添加 JRebel 插件,这里已经安装过则显示 uninstall

使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API

附上 JRebel 破解通过包及其教程

JRebel.rar


以上所述就是小编给大家介绍的《使用 Intellij IDEA 创建基于 Jersey 和 Hibernate 的 RESETful API》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

人工智能

人工智能

李开复、王咏刚 / 文化发展出版社 / 2017-5-10 / CNY 55.00

人工智能已经来了,它就在我们身边,几乎无处不在。 人工智能技术正在彻底改变人类的认知,重建人机相互协作的关系。史无前例的自动驾驶正在重构我们头脑中的出行地图和人类生活图景,今天的人工智能技术也正在翻译、写作、绘画等人文和艺术领域进行大胆的尝试。 我们真的知道什么是人工智能吗? 我们真的准备好与人工智能共同发展了吗? 我们该如何在心理上将人和机器摆在正确的位置? 我们该......一起来看看 《人工智能》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

在线进制转换器
在线进制转换器

各进制数互转换器

MD5 加密
MD5 加密

MD5 加密工具