The current project uses Mybatis as the O/R mapping framework, which is really easy to use and is very convenient for project development. MyBatis supports ordinary SQL queries, view queries, and stored procedure calls, and is a very excellent persistence layer framework. It can map interfaces and POJOs in Java to records in the database using simple XML or annotation verb configuration and original mapping.
1. Call the view
The following is to call the view to query the revenue details, and the SQL part is as follows:
<!-- Get details--><select id ="getContactEarnsDetail" resultType= "java.util.Map" parameterType ="java.lang.Integer">selecttitle,trade_time,trade_amountfrom v_contacts_earn where user_id = #{userId}</select >The data type returned by this view is map.
The mapper part is as follows:
List<Map<String, Object>> getContactEarnsDetail(Integer userId);
The interface part is as follows:
List<Map<String, Object>> getContactEarnsDetail(Integer userId);
Implementation is as follows:
@Overridepublic List<Map<String, Object>> getContactEarnsDetail(Integer userId) {Assert. notNull(userId);return contactEarnsMapper.getContactEarnsDetail(userId);}As shown in the above example, calling a view is like calling a normal SQL query statement.
2. Call stored procedures
Calling stored procedures may also have a result set. Here I will mainly explain the situation of returning result sets.
(1) contains the return result set
As the stored procedure structure is as follows:
p_my_wallet(IN var_user_id INT); parameter is user idrevenue_today Today's income revenue_contacts network income balance available balance
The sql part is as follows:
<!-- Get wallet information--><select id="getMyWallet" parameterType="java.lang.Integer" resultType="java.util.Map" statementType="CALLABLE">{ call p_my_wallet( #{userId,jdbcType=INTEGER,mode=IN} )}</select>Then the mapper part is:
Map<String, Object> getMyWallet(@Param("userId")Integer userId);The interface part is:
Map<String, Object> getMyWallet(Integer userId);
(2) No result set is returned
The sql part is as follows:
< select id= "cardBuild" statementType ="CALLABLE"><![CDATA[{call p_insert_card_build_info (#{is_customized_,mode=IN,jdbcType=INTEGER},#{face_value_,mode=IN,jdbcType=IN,jdbcType=INTEGER},#{number_,mode=IN,jdbcType=INTEGER})}]]></ select>The above is the method of Mybatis calling views and stored procedures introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!