c#
- 字符串枚举
c#枚举一般只能用int,通过以下代码可以实现字符串枚举
//定义枚举
enum WARNING
{
[EnumDescription("输入范围为空!请输入")]
NULLWARNING_1
}
/// <summary>
///自定义属性
/// </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public sealed class EnumDescriptionAttribute : Attribute
{
private string description;
public string Description { get { return description; } }
public EnumDescriptionAttribute(string description)
: base()
{
this.description = description;
}
}
/// <summary>
/// 获取枚举字符串
/// </summary>
public static class EnumHelper
{
public static string GetDescription(Enum value)
{
if (value == null)
{
throw new ArgumentException("value");
}
string description = value.ToString();
var fieldInfo = value.GetType().GetField(description);
var attributes =
(EnumDescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(EnumDescriptionAttribute), false);
if (attributes != null && attributes.Length > 0)
{
description = attributes[0].Description;
}
return description;
}
}
sql
- 类型转换
字符串转INTEGER
`cast(start_no as INTEGER)`
- Oracle分层查询以及PGsql同样实现的方法
Oracle实现:
select * from sr_menu
start with id = 1
connect by prior id = parent;
PGsql实现:
WITH RECURSIVE a AS (
SELECT id, parent, title
FROM sr_menu
WHERE id = 1
UNION ALL
SELECT d.id, d.parent, d.title
FROM sr_menu d
JOIN a ON a.id = d.parent )
SELECT id, parent, title FROM a;
mybatis
- <if 标签使用
<if 标签使用时判断等于单个字符串时,不能用双引号来判断等于字符串,会判定char与string不匹配
错误示范 :
<if test="isStandard!='N'">
and is_standard= #{isStandard,jdbcType=VARCHAR}
</if>
正确代码:
<if test='isStandard!="N"'>
and is_standard= #{isStandard,jdbcType=VARCHAR}
</if>
Java
- stream流和lambda表达式