项目总结 Mapper

MSG生成mapper后之有基本增删改查操作
若添加动态条件查询,还需要另外编写动态查询语句
如下代码为例

1. 注释方式

CrawlerWebsiteSqlProvider.java

public String selectFilterSelective(String websiteName, String websiteStatus, String websiteType, String createTimeStart ,String createTimeEnd) {
            SQL sql = new SQL();
            sql.SELECT("*");
            sql.FROM("crawler_website");
            if (websiteName != null&&websiteName != "") {
                sql.WHERE("WEBSITE_NAME = '"+websiteName+"'");
            }           
            if (websiteType != null&&websiteType != "") {
                sql.WHERE("WEBSITE_TYPE = '"+websiteType+"'");
            }
            if (websiteStatus != null&&websiteStatus != "") {
                sql.WHERE("WEBSITE_STATUS = "+websiteStatus);
            }     
            if (createTimeStart != null&&createTimeEnd!=null) {
                sql.WHERE("CREATE_TIME >= '"+createTimeStart+"'");
                sql.AND();
                sql.WHERE("CREATE_TIME <= '"+createTimeEnd+"'");
            }
            System.out.println(sql.toString());
            return sql.toString();
        }

CrawlerWebsiteMapper.java

@SelectProvider(method="selectFilterSelective",type=CrawlerWebsiteSqlProvider.class)                        
    @Results({                                                     
        @Result(column =  "WEBSITE_ID", property = "websiteId",javaType=String.class, jdbcType=JdbcType.VARCHAR, id=true),
         @Result(column =  "WEBSITE_NAME", property = "websiteName"),
         @Result(column =  "WEBSITE_TYPE", property = "websiteType"),
         ...
    })   
    List getFilterAll(String websiteName, String websiteStatus, String websiteType, String createTimeStart ,String createTimeEnd );

2. XML方式

  

你可能感兴趣的:(项目总结 Mapper)