继初步了解iris后
文章目录
- 获取url路径
 - 获取数据
 - get请求
 - post请求
 - 获取JSON数据格式
 - JSON返回值
 - 获取XML数据格式
 - XML返回值
 
获取url路径
package main
  
import "github.com/kataras/iris/v12"
func main(){
  app := iris.New()
  app.Get("/hello",func(ctx iris.Context){
    path := context.Path()
    app.Logger().Info(path)
    context.WriteString("请求路径",path)
  })
  app.Listen(":82")
}
 

获取数据
get请求
app.Get("/userinfo",func(ctx iris.Context){
    //path := ctx.Path()
    userName := ctx.URLParam("username")
    pwd := ctx.URLParam("pwd")
    if(userName=="admin"&&pwd=="123456"){
      ctx.HTML("<h1>"+userName+"  welcome" + "</h1>")
    }else{
      ctx.HTML("<h1>"+"plase register again"+"</h1>")
	}
})
 
post请求
app.Post("/postLogin",func(ctx iris.Context){
    name := ctx.PostValue("name")
    pwd := ctx.PostValue("pwd")
    app.Logger().Info(name,"   ",pwd)
    ctx.HTML(name)
})
 

获取JSON数据格式
iris.Context.ReadJSON() //用来读取
 
JSON返回值
iris.Context.JSON()
 
获取XML数据格式
iris.Context.ReadXML()
 
XML返回值
iris.Context.XML()
                









![[Volo.Abp升级笔记]使用旧版Api规则替换RESTful Api以兼容老程序](https://img-blog.csdnimg.cn/c857144b47a2486996a4b3476ca8b2d3.png)







