BindQuery和shouldBindQuery的区别

BindQuery

BindQuery在请求过程中, 如果参数错误会直接抛异常 返回400状态

// BindQuery is a shortcut for c.MustBindWith(obj, binding.Query).
func (c *Context) BindQuery(obj interface{}) error {
	return c.MustBindWith(obj, binding.Query)
}

// MustBindWith binds the passed struct pointer using the specified binding engine.
// It will abort the request with HTTP 400 if any error ocurrs.
// See the binding package.
func (c *Context) MustBindWith(obj interface{}, b binding.Binding) (err error) {
	if err = c.ShouldBindWith(obj, b); err != nil {
		c.AbortWithError(http.StatusBadRequest, err).SetType(ErrorTypeBind)
	}
	return
}

ShouldBindQuery

ShouldBindQuery 在请求过程中,对参数检测不做处理

// ShouldBindQuery is a shortcut for c.ShouldBindWith(obj, binding.Query).
func (c *Context) ShouldBindQuery(obj interface{}) error {
	return c.ShouldBindWith(obj, binding.Query)
}
// ShouldBindWith binds the passed struct pointer using the specified binding engine.
// See the binding package.
func (c *Context) ShouldBindWith(obj interface{}, b binding.Binding) error {
	return b.Bind(c.Request, obj)
}
Diboot是一个面向开发人员的低代码开发平台,将重复性的工作自动化,提高质量、效率、可维护性。 diboot主要有diboot-core和diboot-devtools组成,diboot-core又为springboot专门封装了diboot-core-spring-boot-starter组件,diboot-devtools也以starter提供。 diboot特点: 1、专门为springboot开发,引入依赖,配置好相对路径即可使用; 2、并且支持较为常用的五种数据库(MySQL,ORACLE,SQLServer,PostgreSQL,MariaDB); 3、代码自动生成到项目相应的目录下; 4、数据库表结构更改后,可以同步更改对应文件的代码,而不影响到你自己写的代码; 5、基础框架中依靠注解实现的数据关联(一对一、一对多、多对多、数据字典关联等),将关联问题简单化了; 6、对数据关联设置简单,代码生成与更新也可以自动支持一对一、一对多、多对多、数据字典关联; 7、支持开发以及维护过程中对数据库相关表的数据结构更改进行记录,并写入到对应的数据库更改日志文件中; 8、支持启用lombok的代码形式; 9、支持启用swagger的项目; 10、依赖少、简便轻量、灵活性高。   Diboot轻代码开发平台 更新日志: v2.2.1 新增: @BindQuery注解新增strategy参数,支持空值处理策略(默认忽略空字符串) 基于Spring的内存缓存实现(BaseCacheManager),并优化绑定缓存实现 SqlFileInitializer新增executeMultipleUpdateSqlsWithTransaction,支持事务的多SQL更新 BaseService新增IService的getMap(queryWrapper)等接口 @CollectThisApi注解,自动提取注解对应的rest接口 工具类 S.splitToList,D.formatDurationLabel等 优化: 关联绑定的实现中字段名列名的转换由规则转换改为精确转换 支持BindField&BindDict组合使用 BeanUtils.convertValueToFieldType支持LocalDateTime转换 修复: 修复@BindQuery查询不支持自定义逻辑删除字段的问题 升级依赖jar至最新(spring boot 2.4.5, mybatis-plus 3.4.2等)
以下是一个简单的微信小程序项目实例,可以实现一个简单的天气查询功能: 1. 在微信开发者工具中创建一个新的小程序项目。 2. 在 `app.json` 文件中配置小程序的基本信息,例如小程序的名称、appid、界面风格等。 3. 在 `pages` 目录下创建一个名为 `index` 的页面,用于显示天气信息。 4. 在 `index.wxml` 文件中编写页面的结构,例如一个输入框用于输入城市名称、一个按钮用于查询、一个显示天气信息的区域等。 5. 在 `index.js` 文件中编写页面的逻辑代码,实现用户输入城市名称后查询天气信息,并将结果显示在页面中。 6. 使用微信提供的天气查询API,获取天气信息。示例代码如下: ```javascript Page({ data: { city: '', weather: '' }, // 查询天气信息 queryWeather: function () { var that = this; wx.request({ url: 'https://api.seniverse.com/v3/weather/now.json?key=yourkey&location=' + that.data.city, success: function (res) { var data = res.data; if (data.results.length > 0) { that.setData({ weather: data.results[0].now.text }); } } }) }, // 输入框输入事件 bindInput: function (e) { this.setData({ city: e.detail.value }); }, // 查询按钮点击事件 bindQuery: function () { this.queryWeather(); } }) ``` 其中 `yourkey` 是你在心知天气平台申请的天气查询API的key值,`location` 是用户输入的城市名称。 7. 在 `app.js` 文件中注册小程序,并设置 appid 和 secret 等信息。示例代码如下: ```javascript App({ globalData: { // 小程序的appid和secret appId: 'yourappid', appSecret: 'yourappsecret' } }) ``` 其中 `yourappid` 和 `yourappsecret` 需要替换为你自己的小程序的 appid 和 secret。 8. 在微信小程序管理后台中设置小程序的服务器域名和 request 合法域名,以便小程序可以访问天气查询API。 以上就是一个简单的微信小程序项目实例,可以实现一个简单的天气查询功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值