Mybatis之@Select注解

Mybatis之@Select注解

@Select注解基本用法
@Select注解的目的是为了取代xml中的select标签,只作用于方法上面。
抛弃了传统的xml形式

例如(简单的sql)

public interface UserMapper {
    @Select("SELECT id, name, age FROM user WHERE id = #{userId}")
    User getUserById(int userId);
}

如果要想实现复杂的逻辑判断(比如if判断、for循环),则必须需要使用内不能用>、<=、<、<=等判断语句要用gt;和lt;等转义字符,
具体字符自行百度查看。
以下使用的@Results是为了做出参的映射(xml形式里面也是有这个操作的)

//查询的例子
@Select({""})
    @Results({
            @Result(column = "UNID", property = "unid"),
            @Result(column = "HOLDER_UNID", property = "holderUnid"),
            @Result(column = "CATALOG_CODE", property = "catalogCode"),
            @Result(column = "CATALOG_NAME", property = "catalogName"),
            @Result(column = "PROJ_ID", property = "projId"),
            @Result(column = "SERVICE_UNID", property = "serviceUnid"),
            @Result(column = "SERVICE_CODE", property = "serviceCode"),
            @Result(column = "MATERIAL_SRC_TYPE", property = "materialSrcType"),
            @Result(column = "MATERIAL_NAME", property = "materialName"),
            @Result(column = "MATERIAL_TYPE", property = "materialType"),
            @Result(column = "VALID_TERM", property = "validTerm"),
            @Result(column = "FILE_UNID", property = "fileUnid"),
            @Result(column = "STATUS", property = "status"),
            @Result(column = "BIZ_FROM_SYSTEM_CODE", property = "bizFromSystemCode"),
            @Result(column = "BIZ_FROM_SYSTEM", property = "bizFromSystem"),
            @Result(column = "BIZ_AREA", property = "bizArea"),
            @Result(column = "RESOURCE_DIR_CODE", property = "resourceDirCode"),
            @Result(column = "APPLY_ROLE", property = "applyRole"),
            @Result(column = "REUSE_ENABLE_FLAG", property = "reuseEnableFlag"),
            @Result(column = "MATERIAL_UNID", property = "materialUnid"),
            @Result(column = "INSTANCE_MATERIAL_UNID", property = "instanceMaterialUnid"),
            @Result(column = "HOLDER_TYPE", property = "holderType"),
            @Result(column = "HOLDER_ID_TYPE", property = "holderIdType"),
            @Result(column = "HOLDER_ID", property = "holderId"),
            @Result(column = "HOLDER_NAME", property = "holderName"),
            @Result(column = "LEGAL_REPRESENTATIVE", property = "legalRepresentative"),
            @Result(column = "CONTACT_ID", property = "contactId"),
            @Result(column = "CONTACT_NAME", property = "contactName"),
            @Result(column = "CONTACT_PHONE", property = "contactPhone"),
            @Result(column = "LEVEL", property = "level"),
            @Result(column = "labels", property = "labels"),
            @Result(column = "CREATE_TIME", property = "createTime"),
            @Result(column = "RECEIVE_TIME", property = "receiveTime"),
            @Result(column = "SERVICE_NAME", property = "serviceName"),
            @Result(column = "MTC_SOURCE_ID", property = "mtcSourceId"),
            @Result(column = "MATERIAL_FORM", property = "materialForm"),
            @Result(column = "LABELS", property = "labels"),
            @Result(column = "EXPAND1", property = "expand1"),
            @Result(column = "EXPAND2", property = "expand2"),
            @Result(column = "EXPAND3", property = "expand3"),
            @Result(column = "EXPAND4", property = "expand4"),
            @Result(column = "EXPAND5", property = "expand5"),
    })
    List<MaterialInstanceCfgFoshanDO> queryForConfig(Map<String, Object> params);
//插入的例子
@Insert({""})
    int insertInstance(@Param("params") MaterialInstanceFoshanDO params);

参考
【1】
https://blog.csdn.net/qq_23126581/article/details/127995866?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-4-127995866-blog-106617681.235v39pc_relevant_yljh&spm=1001.2101.3001.4242.3&utm_relevant_index=7
【2】
https://blog.csdn.net/qq_34134299/article/details/117651500?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-117651500-blog-124945028.235%5Ev39%5Epc_relevant_yljh&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-117651500-blog-124945028.235%5Ev39%5Epc_relevant_yljh&utm_relevant_index=2

你可能感兴趣的:(mybatis,java,数据库)