package main
import"fmt"funcmain(){//字符串的比较
a :="hello"
b :="hello"
fmt.Println(a == b)// true//字符串的大小比较
c :="bello"
fmt.Println(a > c)//true,比较asic码的大小}
字符串的操作方法
package main
import("fmt""strings")funcmain(){//字符串的比较
a :="hello"
b :="hello"
fmt.Println(a == b)// true//字符串的大小比较
c :="bello"
fmt.Println(a > c)//true,比较asic码的大小//是否包含某字符串
name :="goland-工程师"
isContains := strings.Contains(name,"goland")
fmt.Println(isContains)//查询字串出现的次数
fmt.Println(strings.Count(name,"o"))//1//分割字符串
fmt.Println(strings.Split(name,"-"))//[goland 工程师]//字符串是否包含前缀 是否包含后缀
fmt.Println(strings.HasPrefix(name,"g"))//true
fmt.Println(strings.HasSuffix(name,"g"))//false//查询字串出现的位置
fmt.Println(strings.Index(name,"师"))//14 字节出现的位置//字串替换
fmt.Println(strings.Replace(name,"goland","java",1))//大小写转换
fmt.Println(strings.ToLower(name))
fmt.Println(strings.ToUpper(name))// GOLAND//去掉特殊字符串
fmt.Println(strings.Trim("hello go "," "))// hello go, 去掉的是左右的所有被指定的字符串}
条件判断与for循环
条件判断
package main
import"fmt"/* if bool表达式 {
逻辑
}
*/funcmain(){//条件判断
age :=22
country :="中国"if age <18&& country =="中国"{
fmt.Println("未成年人")}elseif age ==18{
fmt.Println("刚好是成年人")}else{
fmt.Println("成年人")}}
for循环
package main
import"fmt"funcmain(){/*
for循环
for init; condition; post {
逻辑
}
*/for i :=0; i <3; i++{
fmt.Println(i)}//打印九九乘法表for i :=1; i <=9; i++{for j :=1; j <= i; j++{
fmt.Printf("%d * %d = %d ", i, j, i*j)}
fmt.Println()}//for range,主要是对字符串、数组、切片、map、channel的遍历/**
for index, value := range 遍历的数据 {
}
1. 如果遍历的是字符串的话,key为字符串的索引,value字符串对应的缩影的字符的值的拷贝,如果不鞋key,返回的是索引
2. 数组: key为数组的索引,value为索引对应的值的拷贝
3. 切片: key为切片的索引,value为索引对应的值的拷贝
4. map: key为map的key, value为key对应的值的拷贝
5. channel: 无key, value为channel接收的数据
*/
name :="hello, go"for index, value :=range name {//fmt.Println(index, value)
fmt.Printf("%d %c\r\n", index, value)}//不想打印index,可以使用匿名变量
fmt.Println("----------------------------")for_, value :=range name {
fmt.Printf("%c\r\n", value)}
fmt.Println("----------------------------")for index :=range name {
fmt.Printf("%c\r\n", name[index])}}
goto
package main
import"fmt"/*
*
goto语句可以让我的代码跳到指定的代码块中运行
很少用
*/funcmain(){for i :=0; i <5; i++{for j :=0; j <4; j++{if j ==2{goto over
}
fmt.Println(i, j)}}
over:
fmt.Println("over")}
switch
package main
import"fmt"funcmain(){/*
switch val {
case val1:
...
case val2:
...
default:
...
}
*///中文的星期几,输出对应的英文
day :="周五"switch day {case"周一":
fmt.Println("Mongday")case"周五":
fmt.Println("Friday")case"周三":
fmt.Println("Wednesday")default:
fmt.Println("Saturday")}
score :=95switch{case score <60:
fmt.Println("E")case score >=60&& score <70:
fmt.Println("D")case score >=70&& score <80:
fmt.Println("C")case score >=80&& score <90:
fmt.Println("b")case score >=90&& score <=100:
fmt.Println("A")}switch score {case60,70,80:
fmt.Println("牛")default:
fmt.Println("牛牛")}}
Go语言的容器
数组、切片(slice)、map、list
Go–数组
package main
import"fmt"funcmain(){/*
go语言提供了哪些集合类型的数据结构
1、数组
2、切片(slice)
3、map
4、list
*/// 数组 定义: var name [count]intvar courses1 [3]string//courses1类型: 只有三个元素的数组类型var courses2 [4]string//courses2类型: 只有四个元素的数组类型
fmt.Printf("%T\r\n", courses1)
fmt.Printf("%T\r\n", courses2)
courses1[0]="go"
courses1[1]="grpc"
courses1[2]="gin"
fmt.Println(courses1)//对数组进行遍历,indexfor_, value :=range courses1 {
fmt.Println(value)}}
package main
import("container/list""fmt")funcmain(){var mylist = list.List{}
mylist.PushBack("go")
mylist.PushBack("grpc")
mylist.PushBack("gin")
fmt.Println(mylist)//遍历打印值,从头遍历for i := mylist.Front(); i !=nil; i = i.Next(){
fmt.Println(i.Value)}
fmt.Println("----------反向遍历----------")//反向遍历for i := mylist.Back(); i !=nil; i = i.Prev(){
fmt.Println(i.Value)}
fmt.Println("----------初始化list的方法----------")
newList := list.New()
newList.PushFront("mysql")for i := newList.Front(); i !=nil; i = i.Next(){
fmt.Println(i.Value)}//插入指定元素之前或者之后
fmt.Println("----------插入指定元素之前或者之后----------")
i := newList.Front()for; i !=nil; i = i.Next(){if i.Value.(string)=="mysql"{break}}
newList.InsertBefore("oracle", i)for i := newList.Front(); i !=nil; i = i.Next(){
fmt.Println(i.Value)}//list删除
fmt.Println("----------newList删除----------")
newList.Remove(i)for i := newList.Front(); i !=nil; i = i.Next(){
fmt.Println(i.Value)}}
在开发时,遇到mysql版本在5.7.X及以上版本时使用group by 语句会报以下的错误
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column business_typ…
The emulator process for AVD Pixel_2_API_29 was killed
报错描述:
第一次安装Android studio好不容易解决gradle启动模拟器又出现了以下错误
The emulator process for AVD Pixel_2_API_29 was killed原因一: 需要安装Intel x86 Emulator Acceleer…