gradle工程

一、gradle中grovvy语言简单学习

//介绍grovvy编程语言
println("holloWorld");
//grovvy可以省略句末分号
println("holloWorld")
//grovvy可以省略括号
println"holloWorld"

//grovvy中如何定义变量
//def是弱类型的,grovvy根据具体情况自动赋类型
def i =18;
println i
def s = "小米"
println s
//定义一个集合类型
def list = ['a','b']
//list中添加元素
list << 'c'
//取出list中第三个元素
println list.get(2)
//定义一个map
def map = ['phone1':'apple','phone2':'huawei']
//向map中添加键值对
map.phone3='OPPO'
//取出map中的值
println map.get('phone3')

//grovvy中的闭包
//什么是闭包? 闭包:一段代码块;grovvy中,闭包当参数来使用
//定义一个闭包
def b1 = {
    println "闭包b1"
}
//定义一个方法,方法里面需要闭包类型的参数
def method1(Closure closure){
    closure()
}
//接下来调用方法
method1(b1)
method1 b1

//定义一个带有参数的闭包
def b2 = {
    value ->
        println "闭包b2中的参数: ${value}"
}
//定义一个方法,方法里面需要闭包类型的参数
def method2(Closure closure){
    closure("VOVO")
}
method2(b2)

二 、创建gradle工程的java工程
在这里插入图片描述
在这里插入图片描述
选择自动导包,使用本地安装gradle
![在这里插入图片描述](https://img-blog.csdnimg.cn/20191030104138245.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDczNjk2OA==,size_16,color_FFFFFF,t_70在这里插入图片描述
在这里插入图片描述
项目结构:
在这里插入图片描述
三 、build.gradle配置文件

//工程运行环境
plugins {
    id 'java'
}
//本工程信息
group 'com.whfc'
version '1.0-SNAPSHOT'
//java开发环境
sourceCompatibility = 1.8

/* 指定所使用的的仓库
* mavenCentral()代表中央仓库
*/
repositories {
    //优先从本地仓库加载依赖,没有再从中中央仓库下
    mavenLocal();
    mavenCentral()
}
/*
 * gradle所有jar包的坐标都在dependencies{}中
*  每一个jar包坐标都有三个基本元素组成:
*  (1)group :组织   (2)name :jar包名   (3)version :版本号
*  testCompile 表示该jar包在测试时候起作用,为该jar包的作用域
*   我们在添加jar包时要带上jar包的作用域
* */
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    // https://mvnrepository.com/artifact/org.springframework/spring-context-support
    compile group: 'org.springframework', name: 'spring-context-support', version: '5.0.2.RELEASE'
    // https://mvnrepository.com/artifact/org.springframework/spring-test
    testCompile group: 'org.springframework', name: 'spring-test', version: '5.0.2.RELEASE'
}

如何找gradle坐标?
搜索maven仓库,寻找maven坐标,切换到gradle坐标
在这里插入图片描述
四、测试

public class AccountDaoImpl implements AccountDao {
    @Override
    public List findAll() {
        System.out.println("List print success!!!");
        return null;
    }
}

resource/bean.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-4.2.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-4.2.xsd ">
       
    <bean id="accountDao" class="com.whfc.dao.impl.AccountDaoImpl"/>
    </beans>

测试代码

@Test
    public void testAccountDao(){
        //得到Spring容器
        ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
        //
        //从容器中获得 AcountDao 对象
        AccountDao accountDao = ac.getBean(AccountDao.class);
        accountDao.findAll();

    }

打包生成工具:
在这里插入图片描述
四:构建web工程
java工程秒变web工程
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值