1. 程式人生 > >動態sql語句 Java類寫sql

動態sql語句 Java類寫sql

StockMarketMapper.java

package com.oliver.mapper.inter;

import java.util.List;

import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import com.oliver.db.sql.StockMarketProvider;
import com.oliver.models.StockMarket;

public interface IStockMarketMapper {

@InsertProvider(type=StockMarketProvider.class,method="insertStockMarketSql")
@SelectKey(keyProperty="id",keyColumn="id", before = false, resultType = int.class, statement = { "SELECT LAST_INSERT_ID() AS ID" })
public void insertStockMarket(StockMarket stockMarket);

@SelectProvider(type=StockMarketProvider.class,method="selectByStockIdSql")
@Results(value={
        @Result(id=true,property="id",column="id"),
        @Result(property="dqj",column="dqj"),
        @Result(property="bhz",column="bhz"),
        @Result(property="bhl",column="bhl"),
        @Result(property="jkp",column="jkp"),
        @Result(property="zsp",column="zsp"),
        @Result(property="zgj",column="zgj"),
        @Result(property="zdj",column="zdj"),
        @Result(property="ztj",column="ztj"),
        @Result(property="dtj",column="dtj"),
        @Result(property="hsl",column="hsl"),
        @Result(property="zf",column="zf"),
        @Result(property="syl",column="syl"),
        @Result(property="sjl",column="sjl"),
        @Result(property="cjl",column="cjl"),
        @Result(property="cje",column="cje"),
        @Result(property="zsz",column="zsz"),
        @Result(property="ltsz",column="ltsz"),
        @Result(property="mr1",column="mr1"),
        @Result(property="mr2",column="mr2"),
        @Result(property="mr3",column="mr3"),
        @Result(property="mr4",column="mr4"),
        @Result(property="mr5",column="mr5"),
        @Result(property="mc1",column="mc1"),
        @Result(property="mc2",column="mc2"),
        @Result(property="mc3",column="mc3"),
        @Result(property="mc4",column="mc4"),
        @Result(property="mc5",column="mc5"),
        @Result(property="mr1Num",column="mr1_num"),
        @Result(property="mr2Num",column="mr2_num"),
        @Result(property="mr3Num",column="mr3_num"),
        @Result(property="mr4Num",column="mr4_num"),
        @Result(property="mr5Num",column="mr5_num"),
        @Result(property="mc1Num",column="mc1_num"),
        @Result(property="mc2Num",column="mc2_num"),
        @Result(property="mc3Num",column="mc3_num"),
        @Result(property="mc4Num",column="mc4_num"),
        @Result(property="mc5Num",column="mc5_num"),
        @Result(property="status",column="status"),
        @Result(property="stockId",column="stock_id")
})
public StockMarket selectByStockId(int stockId);

@UpdateProvider(type=StockMarketProvider.class,method="updateByStockIdSql")
public void update(StockMarket stockMarket);

@SelectProvider(type=StockMarketProvider.class,method="selectByOrderAtLimitSql")
@Results(value={
        @Result(id=true,property="id",column="id"),
        @Result(property="dqj",column="dqj"),
        @Result(property="bhz",column="bhz"),
        @Result(property="bhl",column="bhl"),
        @Result(property="jkp",column="jkp"),
        @Result(property="zsp",column="zsp"),
        @Result(property="zgj",column="zgj"),
        @Result(property="zdj",column="zdj"),
        @Result(property="ztj",column="ztj"),
        @Result(property="dtj",column="dtj"),
        @Result(property="hsl",column="hsl"),
        @Result(property="zf",column="zf"),
        @Result(property="syl",column="syl"),
        @Result(property="sjl",column="sjl"),
        @Result(property="cjl",column="cjl"),
        @Result(property="cje",column="cje"),
        @Result(property="zsz",column="zsz"),
        @Result(property="ltsz",column="ltsz"),
        @Result(property="mr1",column="mr1"),
        @Result(property="mr2",column="mr2"),
        @Result(property="mr3",column="mr3"),
        @Result(property="mr4",column="mr4"),
        @Result(property="mr5",column="mr5"),
        @Result(property="mc1",column="mc1"),
        @Result(property="mc2",column="mc2"),
        @Result(property="mc3",column="mc3"),
        @Result(property="mc4",column="mc4"),
        @Result(property="mc5",column="mc5"),
        @Result(property="mr1Num",column="mr1_num"),
        @Result(property="mr2Num",column="mr2_num"),
        @Result(property="mr3Num",column="mr3_num"),
        @Result(property="mr4Num",column="mr4_num"),
        @Result(property="mr5Num",column="mr5_num"),
        @Result(property="mc1Num",column="mc1_num"),
        @Result(property="mc2Num",column="mc2_num"),
        @Result(property="mc3Num",column="mc3_num"),
        @Result(property="mc4Num",column="mc4_num"),
        @Result(property="mc5Num",column="mc5_num"),
        @Result(property="status",column="status"),
        @Result(property="stockId",column="stock_id")
})
public List<StockMarket> selectByOrderAtLimit(@Param("orderby")String orderBy, @Param("limit")int limit);

@SelectProvider(type=StockMarketProvider.class,method="selectDiefuListSql")
   @Results(value={
           @Result(id=true,property="id",column="id"),
           @Result(property="dqj",column="dqj"),
           @Result(property="bhz",column="bhz"),
           @Result(property="bhl",column="bhl"),
           @Result(property="jkp",column="jkp"),
           @Result(property="zsp",column="zsp"),
           @Result(property="zgj",column="zgj"),
           @Result(property="zdj",column="zdj"),
           @Result(property="ztj",column="ztj"),
           @Result(property="dtj",column="dtj"),
           @Result(property="hsl",column="hsl"),
           @Result(property="zf",column="zf"),
           @Result(property="syl",column="syl"),
           @Result(property="sjl",column="sjl"),
           @Result(property="cjl",column="cjl"),
           @Result(property="cje",column="cje"),
           @Result(property="zsz",column="zsz"),
           @Result(property="ltsz",column="ltsz"),
           @Result(property="mr1",column="mr1"),
           @Result(property="mr2",column="mr2"),
           @Result(property="mr3",column="mr3"),
           @Result(property="mr4",column="mr4"),
           @Result(property="mr5",column="mr5"),
           @Result(property="mc1",column="mc1"),
           @Result(property="mc2",column="mc2"),
           @Result(property="mc3",column="mc3"),
           @Result(property="mc4",column="mc4"),
           @Result(property="mc5",column="mc5"),
           @Result(property="mr1Num",column="mr1_num"),
           @Result(property="mr2Num",column="mr2_num"),
           @Result(property="mr3Num",column="mr3_num"),
           @Result(property="mr4Num",column="mr4_num"),
           @Result(property="mr5Num",column="mr5_num"),
           @Result(property="mc1Num",column="mc1_num"),
           @Result(property="mc2Num",column="mc2_num"),
           @Result(property="mc3Num",column="mc3_num"),
           @Result(property="mc4Num",column="mc4_num"),
           @Result(property="mc5Num",column="mc5_num"),
           @Result(property="status",column="status"),
           @Result(property="stockId",column="stock_id")
   })
public List<StockMarket> selectDiefuList(int limit);

}

引用塊內容