FT網站開發過程遇到的問題匯總

來源:互聯網
上載者:User

標籤:

1.jar包不相容問題。主要是mybatis,spring jar包不相容。同時jstl標籤也需要jar包,是jstl.jar,standard.jar。

2.mybatis的mapper.xml對應檔,傳入多個參數問題

第一種方案 

DAO層的函數方法 

  1. Public User selectUser(String name,String area);  

對應的Mapper.xml  

  1. <select id="selectUser" resultMap="BaseResultMap">  
  2.     select  *  from user_user_t   where user_name = #{0} and user_area=#{1}  
  3. </select>  

其中,#{0}代表接收的是dao層中的第一個參數,#{1}代表dao層中第二參數,更多參數一致往後加即可。

第二種方案

此方法採用Map傳多參數.

Dao層的函數方法

  1. Public User selectUser(Map paramMap);  

對應的Mapper.xml

 
  1. <select id=" selectUser" resultMap="BaseResultMap">  
  2.    select  *  from user_user_t   where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}  
  3. </select>  

Service層調用

 Private User xxxSelectUser(){  
  1.    Map paramMap=new hashMap();  
  2.    paramMap.put(“userName”,”對應具體的參數值”);  
  3.    paramMap.put(“userArea”,”對應具體的參數值”);  
  4.    User user=xxx. selectUser(paramMap);}  

個人認為此方法不夠直觀,見到介面方法不能直接的知道要傳的參數是什麼。

第三種方案

Dao層的函數方法

  1. Public User selectUser(@param(“userName”)String name,@param(“userArea”)String area);  

對應的Mapper.xml

  1. <select id=" selectUser" resultMap="BaseResultMap">  
  2.    select  *  from user_user_t   where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}  
  3. </select>   

個人覺得這種方法比較好,能讓開發人員看到dao層方法就知道該傳什麼樣的參數,比較直觀,個人推薦用此種方案。

3.mybatis update語句怎麼寫?這個至今還沒完全解決好,主要糾結在於id是資料庫主鍵,自動成長的。

4.mysql返回指定的多行記錄:select * from product limit 15 offset #{(value-1)*15+1}

主要用到了limit 和offest指令。offest指令標識位移量,即記錄從哪開始。limit用來指定選取多少記錄。

<select id="getSomeProductsList" parameterType="int" resultMap="ProductsList">
select * from product limit 15 offset #{(value-1)*15+1}
</select>

在這裡發現的解決辦法,http://blog.chinaunix.net/uid-23028928-id-2567738.html

5.spring 用c3p0資料庫連接池必須採用jdbc前置名properties檔案

6.mybatis的 mappe.xml怎樣返回list<object>?

答:配置resultMap

<resultMap id="ProductsList" type="com.pojo.ProductItem">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="amount" property="amount" />
<result column="price" property="price" />
</resultMap>

然後在,注意傳回型別不再是ResultType屬性,而是resultMap屬性

<select id="getAllProductsList" resultMap="ProductsList">
select * from product
</select>

FT網站開發過程遇到的問題匯總

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.