新建项目与数据库搭建

news/2024/7/3 6:18:25
#新建项目与数据库配置
### 一、新建项目 ###
File——Gradle——JAVA+WEB——勾选1和2,选择use local gradle distribution

### 二。添加依赖,build.gradle ###

    dependencies {
    // Gson json
    compile 'com.google.code.gson:gson:2.8.0'
    // Guava java 类封装
    compile 'com.google.guava:guava:21.0'

    // Jersey 轻量级Restful接口框架
    compile 'org.glassfish.jersey.core:jersey-client:2.26-b03'
    compile 'org.glassfish.jersey.core:jersey-server:2.26-b03'
    compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.26-b03'
    // 也是一个 Json 解析库
    compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.26-b03'

    // 数据库操作框架
    // https://mvnrepository.com/artifact/org.hibernate/hibernate-core
    compile 'org.hibernate:hibernate-core:5.2.9.Final'
    // https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager
    compile 'org.hibernate:hibernate-entitymanager:5.2.9.Final'
    // https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0
    compile 'org.hibernate:hibernate-c3p0:5.2.9.Final'

    // MySQL 驱动库
    // https://mvnrepository.com/artifact/mysql/mysql-connector-java
    compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'

    testCompile group: 'junit', name: 'junit', version: '4.12'
    }

### 三。resources中的hibernate.cfg.xml中 ###

    <hibernate-configuration>
    <session-factory>
        <!-- 数据库链接驱动 -->
        <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
        <!--链接地址用户名密码 -->
        <property name="connection.url">jdbc:mysql://127.0.0.1:3306/DB_I_T_PUSH?serverTimezone=UTC&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>

        <!--<property name="connection.url">jdbc:mysql://qiujuer.net:6968/DB_I_T_PUSH?serverTimezone=UTC&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false</property>-->


        <!-- JDBC 链接池大小 -->
        <property name="connection.pool_size">5</property>

        <!-- SQL 方言 -->
        <property name="dialect">org.hibernate.dialect.MySQL55Dialect</property>

        <!-- Hibernate session 上下文为线程级别 -->
        <property name="current_session_context_class">thread</property>

        <!-- 配置C3P0缓存链接池  -->
        <property name="cache.provider_class">org.hibernate.c3p0.internal.C3P0ConnectionProvider</property>
        <!--在连接池中可用数据库连接的最小数目-->
        <property name="c3p0.min_size">6</property>
        <!--在连接池中所有数据库连接的最大数目-->
        <property name="c3p0.max_size">50</property>
        <!--设定数据库连接的超时时间-->
        <!--<property name="c3p0.time_out">1800</property>-->
        <property name="c3p0.timeout">100</property>
        <!--可以被缓存的PreparedStatement的最大数目-->
        <property name="c3p0.max_statement">50</property>
        <!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 -->
        <property name="c3p0.acquire_increment">1</property>
        <!-- 连接对象因该多长时间被自动校验的时间段,以秒为单位-->
        <property name="c3p0.idle_test_period">100</property> <!-- seconds -->
        <!--最多可以创建Statements对象的个数. . 就是可以执行SQL语句的对象的个数-->
        <property name="c3p0.max_statements">0</property>

        <!-- SQL语句输出 -->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>

        <!-- 自动更新数据库的级别 -->
        <property name="hbm2ddl.auto">update</property>
        <!--
        create:表示启动的时候先drop,再create
        create-drop: 也表示创建,只不过再系统关闭前执行一下drop
        update: 这个操作启动的时候会去检查schema是否一致,如果不一致会做scheme更新
        validate: 启动时验证现有schema与你配置的hibernate是否一致,如果不一致就抛出异常,并不做更新
        -->


        <!--<mapping package="net.qiujuer.web.italker.push.bean.db"-->
        <!--class="net.qiujuer.web.italker.push.bean.db.Group"/>-->
        <!--<mapping package="net.qiujuer.web.italker.push.bean.db"-->
        <!--class="net.qiujuer.web.italker.push.bean.db.GroupMember"/>-->
        <!--<mapping package="net.qiujuer.web.italker.push.bean.db"-->
        <!--class="net.qiujuer.web.italker.push.bean.db.User"/>-->
        <!--<mapping package="net.qiujuer.web.italker.push.bean.db"-->
        <!--class="net.qiujuer.web.italker.push.bean.db.UserFollow"/>-->
        <!--<mapping package="net.qiujuer.web.italker.push.bean.db"-->
        <!--class="net.qiujuer.web.italker.push.bean.db.Message"/>-->
        <!--<mapping package="net.qiujuer.web.italker.push.bean.db"-->
        <!--class="net.qiujuer.web.italker.push.bean.db.PushHistory"/>-->
        <!--<mapping package="net.qiujuer.web.italker.push.bean.db"-->
        <!--class="net.qiujuer.web.italker.push.bean.db.Apply"/>-->

    </session-factory>
    </hibernate-configuration>
### 四、webapp中添加新文件夹WEB-INF中新建web.xml ###

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app>

    <display-name>iTalker</display-name>

    <servlet>
        <servlet-name>ITalkerApiServlet</servlet-name>
        <!--容器-->
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <!--映射的包名,用于搜索处理类-->
            <param-value>net.qiujuer.web.italker.push.service</param-value>
        </init-param>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>net.qiujuer.web.italker.push.Application</param-value>
        </init-param>

        <load-on-startup>1</load-on-startup>
    </servlet>

    <!--映射-->
    <servlet-mapping>
        <servlet-name>ITalkerApiServlet</servlet-name>
        <!--访问路径-->
        <url-pattern>/api/*</url-pattern>
    </servlet-mapping>
    </web-app>

### 五、java下新建文件夹net.qiujuer.web.italker.push并在下面新建Application ###

    public class Application extends ResourceConfig{
    public Application(){
      
    }
    }


http://www.niftyadmin.cn/n/3649295.html

相关文章

[EntLib]在SR.Strings中使用中文字符串资源

编写者&#xff1a;郑昀UltraPower要想在SR.Strings中使用中文字符串资源&#xff0c;必须这样&#xff1a;把你的SR.Strings文件保存为UTF-8编码的(具体操作是&#xff1a;VS.Net2003->文件菜单-高级保存选项&#xff0c;选择“Unicode(UTF-8 带签名) - 代码页 65001”)&am…

浅谈Android客户端项目框架

写Android也有些时间了&#xff0c;一边工作&#xff0c;一边学习&#xff0c;一边积累&#xff0c;只有遇到问题了&#xff0c;花时间去研究&#xff0c;自己的能力才能提升&#xff0c;刀如果不用&#xff0c;慢慢的就会生锈应该也是这个道理吧&#xff01;上个月公司项目服务…

在JavaScript中建立倒数计时器

Countdown timers can serve many purposes. They can communicate to a user how long they’ve been doing something or how much time until some event happens, like the launch of your new website. 倒数计时器可以有多种用途。 他们可以与用户交流他们已经做了多长时间…

RxJava的简单使用(一)

一测试订阅 Test public void testSubscribe() {//观察者&#xff0f;订阅者final Subscriber<String> subscriber new Subscriber<String>() {Overridepublic void onCompleted() {System.out.println("onCompleted in tread:" Thread.currentThread().…

[EntLib]关于SR.Strings的使用办法

编写者&#xff1a;郑昀UltraPower下载附件。安装String Resource Generator 1[1].2.5&#xff0c;运行SRGenerator.msi。然后给自己的工程中添加SR.strings文件&#xff0c;通过VS.NET在现有的.RESX或SR.strings文件设置Custom tool属性为&#xff1a;StringResourceTool或SRC…

android开源项目和框架

特效&#xff1a; http://www.theultimateandroidlibrary.com/ 常用效果&#xff1a; 1. https://github.com/novoda/ImageLoader 异步加载图片&#xff0c;缓存&#xff0c;生成缩略图&#xff0c; 基本上每个应用都会需要这个lib。 android-query框架 2. https://githu…

prisma 风格设置_Prisma中的身份验证-第1部分:设置

prisma 风格设置Unless if you’re using something like Firebase to handle your authentication, it can be a bit tricky to handle it in a way that is both secure and easy to manage. In this three-part series, we’re going to be going over how to setup your Gr…

RxBus-mvp模式下对Rxjav的封装(一)

一、首先定义一个Presenter接口&#xff1a;DataBusSubscriber 用来接受数据 public interface DataBusSubscriber {void onEvent(Object data); }二、定义一个RxBus的封装类 public class RxBus {public static final String TAG "RxBus";private static volatile…