mybatis a field pass two values and date comparison yyyy-mm-dd

Recently changed jobs, today encountered two problems at work, such as the title of the (mybatis frame). The former is a direct Baidu copy over. Then copy the code here:

service layer:

List<String> years = new ArrayList();
years.add(currentYear);
years.add(lastYear);
List<XXXEntity> XXXList = XXXDAO.selectTime(type,years);

dao layer:

public List<XXXEntity> selectTime(
@Param("type") Long type,List<String> yearsList);

mapper:

<select id="selectTime" parameterType="java.util.List" resultMap="entity">
        select * from table where
        type = 1
        and year in
        <foreach Item = "Item" Collection = "yearsList" Separator = "," = Open "(" use Close = ")" index = "">            
            # {Item, jdbcType = VARCHAR}
 <-! I put a list String value type, so jdbcType = VARCHAR, note that the value of the parameter list dao layer collection object name consistent. >
        </foreach>
</select>

Well, this is a field method pass two values, use the list package, xml file copy place last note of the change just fine.

 

The second question: I want to get a time to determine whether it is in a period of time. Time and time value of yyyy-mm-dd, to determine the exact date, not when every minute, online check some information that he tried to change to change the test finally realized, the code is as follows:

public  Boolean isEffectiveDate(Date currentTime, Date startTime, Date endTime) {

        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
        String current=sd.format(currentTime);
        String start=sd.format(startTime);
        String end=sd.format(endTime);
        if(java.sql.Date.valueOf(current).after(java.sql.Date.valueOf(start)) &
                java.sql.Date.valueOf(current).before(java.sql.Date.valueOf(end))){
            return true;
        }else{
            return false;
        }
    }

Not looking at a few lines, get a long time, not really familiar with the type of Date, repeatedly modify this code, debugging, optimizing, you can directly copy the past with (note value Date format is yyyy-mm-dd).

It is a summary of their work experience, but also want to contribute their part to help more people. thank.

 

Guess you like

Origin www.cnblogs.com/caihouzi/p/11689441.html