IDEA gradle 搭建SSM框架(Mysql数据库)

SSM框架目前比较流行的web框架之一,学会搭建并熟悉其如何使用很有必要!!!

一.gradle配置

group 'domeTest'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'maven'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenLocal()
    maven { url "http://112.74.19.176:8081/repository/maven-central/" }
    mavenCentral()
    maven { url "http://repo.maven.apache.org/maven2" }
}
configurations {
    mybatisGenerator
}
dependencies {
    compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
    compileOnly group: 'javax.servlet.jsp', name: 'javax.servlet.jsp-api', version: '2.3.1'
    compileOnly group: 'javax', name: 'javaee-web-api', version: '6.0'
    compileOnly group: 'mysql', name: 'mysql-connector-java', version: '5.1.34'
    compileOnly group: 'com.rabbitmq', name: 'amqp-client', version: '3.6.0'
    compileOnly group: 'redis.clients', name: 'jedis', version: '2.6.0'
    compileOnly group: 'com.zaxxer', name: 'HikariCP', version: '2.5.1'
    compileOnly group: 'jstl', name: 'jstl', version: '1.2'
    compileOnly group: 'commons-codec', name: 'commons-codec', version: '1.10'
    compileOnly group: 'commons-io', name: 'commons-io', version: '2.2'
    compileOnly group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.1'
    compileOnly group: 'commons-logging', name: 'commons-logging', version: '1.2'
    compileOnly group: 'com.google.guava', name: 'guava', version: '16.0.1'
    compileOnly group: 'commons-lang', name: 'commons-lang', version: '2.6'
    compileOnly group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
    compileOnly group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.2'
    compileOnly group: 'org.springframework.data', name: 'spring-data-redis', version: '1.7.4.RELEASE'
    compileOnly group: 'org.springframework', name: 'spring-jdbc', version: '4.3.3.RELEASE'
    compileOnly group: 'org.springframework', name: 'spring-context', version: '4.3.3.RELEASE'
    compileOnly group: 'org.springframework', name: 'spring-context-support', version: '4.3.3.RELEASE'
    compileOnly group: 'org.springframework', name: 'spring-aop', version: '4.3.3.RELEASE'
    compile group: 'org.springframework', name: 'spring-webmvc', version: '4.3.3.RELEASE'
    compile group: 'org.springframework', name: 'spring-aspects', version: '4.3.3.RELEASE'
    compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.6.12'
    compile group: 'org.aspectj', name: 'aspectjrt', version: '1.6.10'
    compile group: 'aopalliance', name: 'aopalliance', version: '1.0'
    compileOnly group: 'log4j', name: 'log4j', version: '1.2.16'
    compileOnly fileTree(dir: 'libs', include: ['*.jar'])
    compile fileTree(dir: 'maven_install', include: ['*.jar'])
    compile group: 'net.sf.ezmorph', name: 'ezmorph', version: '1.0.6'
    compile group: 'net.sf.json-lib', name: 'json-lib', version: '2.4', classifier: 'jdk15'
    compile group: 'com.sun.codemodel', name: 'codemodel', version: '2.6'
    compile group: 'org.apache.commons', name: 'commons-math3', version: '3.5'
    compile group: 'com.google.zxing', name: 'javase', version: '3.1.0'
    compile group: 'org.jsoup', name: 'jsoup', version: '1.8.1'
    compile group: 'com.sun.jna', name: 'jna', version: '3.0.9'
    compile group: 'com.spatial4j', name: 'spatial4j', version: '0.5'
    compile group: 'junit', name: 'junit', version: '4.10'
    compile group: 'org.mybatis', name: 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在使用Java语言中的Idea集成开发环境连接MySQL数据库时,需要使用Java Database Connectivity(JDBC)技术。以下是连接MySQL数据库的步骤: 1.下载并安装MySQL数据库驱动程序。可以从官方网站下载MySQL Connector/J,或者使用Maven或Gradle等构建工具来获取驱动程序。 2.在Idea项目的classpath中添加MySQL数据库驱动程序。 3.编写Java代码来连接MySQL数据库。示例代码如下: ```java import java.sql.*; public class MysqlJdbcTest { public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/test"; String username = "root"; String password = "123456"; Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection(url, username, password); System.out.println("成功连接到数据库!"); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } } } ``` 在以上代码中,需要修改url、username和password变量的值以匹配实际的MySQL数据库连接信息。其中,url变量指定了MySQL服务器的地址和端口以及要连接的数据库名称。username和password变量则指定了连接数据库所需的用户名和密码。最后,使用Java中的JDBC技术连接MySQL数据库,并在控制台输出连接成功信息。 ### 回答2: idea使用jdbc连接mysql数据库非常简单,只需要按照以下步骤进行操作即可。 步骤一:在pom.xml文件中添加mysql驱动依赖项 ```xml <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.40</version><!--版本号根据实际情况而定--> </dependency> ``` 步骤二:编写代码连接mysql数据库,并执行操作 ```java public class JdbcTest { public static void main(String[] args) { String driver = "com.mysql.jdbc.Driver";//mysql驱动程序 String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8";//数据库连接地址 String username = "root";//用户名 String password = "root";//密码 Connection connection = null; Statement statement = null; ResultSet resultSet = null; try { Class.forName(driver);//加载mysql驱动程序 connection = DriverManager.getConnection(url, username, password);//获取连接 statement = connection.createStatement();//创建statement对象 String sql = "SELECT * FROM student";//sql语句 resultSet = statement.executeQuery(sql);//执行查询操作 while (resultSet.next()) {//遍历结果集 int id = resultSet.getInt("id"); String name = resultSet.getString("name"); String sex = resultSet.getString("sex"); System.out.println(id + "\t" + name + "\t" + sex); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if(resultSet!=null){ resultSet.close();//关闭结果集 } if(statement!=null){ statement.close();//关闭statement对象 } if(connection!=null){ connection.close();//关闭连接 } } catch (SQLException e) { e.printStackTrace(); } } } } ``` 以上代码中,通过jdbc连接mysql数据库,获取连接后,使用`Statement`对象创建sql语句,并通过`executeQuery()`方法执行查询操作。最后使用`ResultSet`对象遍历结果集,输出结果。 总的来说,idea使用jdbc连接mysql数据库步骤非常简单,只需要按照以上步骤进行编写即可,这也是编写Java Web开发的基础知识之一。 ### 回答3: Idea是一款流行的Java IDE,它提供了JDBC连接MySQL数据库的功能。JDBC是Java数据库连接的标准接口,它允许Java程序与各种各样的关系型数据库进行交互。MySQL是一款免费的开源数据库,在企业级应用和Web开发中广泛使用。 在Idea中连接MySQL数据库需要进行以下步骤: 1. 导入MySQL JDBC驱动 在项目的pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.22</version> </dependency> ``` 或者在Idea中的Modules Setting中的Dependencies选项卡中手动导入。 2. 创建数据库连接 在Java代码中使用以下代码创建数据库连接: ```java Class.forName("com.mysql.cj.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/DatabaseName?useSSL=false&serverTimezone=UTC", "username", "password"); ``` 其中,com.mysql.cj.jdbc.Driver是MySQL 8.0版本的驱动类,localhost:3306是数据库的IP地址和端口号,DatabaseName是要连接的数据库名称,username和password是数据库的用户名和密码。useSSL=false表示不使用SSL连接,serverTimezone=UTC表示使用UTC时区。 3. 使用SQL语句操作数据库 通过创建的Connection对象,可以使用Java代码执行SQL语句操作MySQL数据库,例如查询数据: ```java Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM TableName"); while (rs.next()) { int id = rs.getInt("id"); String name = rs.getString("name"); // ... } ``` 其中,TableName是要查询的表的名称,id和name是表中的列名。 4. 关闭连接 在使用完数据库后,需要关闭Connection、Statement和ResultSet对象,例如: ```java rs.close(); stmt.close(); conn.close(); ``` 通过以上步骤,就可以在Idea中使用JDBC连接MySQL数据库了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值