MyBatis MySQL Call view

Source: Internet
Author: User

Java code

@RequestMapping (value = "/testview", method =requestmethod.get) Public@ResponseBody String TestView (httpservletrequest request, httpservletresponse response)throwsIOException {Map<string, object> paramap =NewHashmap<string, object>(); Paramap.put ("Usertype", "Doctor"); List<map<string, object>> list =NewArraylist<map<string,object>>(); List=Proceduremapper.testview (PARAMAP); if(List! =NULL&& list.size () > 0){             for(inti = 0; I < list.size (); i++) {System.out.println (List.get (i)); }        }        return NULL; }

Mapper

 PackageCn.zsmy.mapper;Importjava.util.List;ImportJava.util.Map;ImportCn.zsmy.entity.User;ImportCn.zsmy.form.UserForm;ImportCn.zsmy.mapper.base.SimpleMapper;Importcn.zsmy.tmp.core.MyBatisRepository;/*** @ClassName: Proceduremapper * @Description: Calling stored procedures and views *@authorTeacher Hamming * @date June 13, 2016 morning 11:52:38 **/@MyBatisRepository Public InterfaceProceduremapperextendsSimplemapper<userform,user>{Map<string, Object> testprocedure (map<string, object>Paramap); List<map<string, object>> TestView (map<string, object>paramap);}

Mapper.xml

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" >< Mapper namespace= "Cn.zsmy.mapper.ProcedureMapper" > <!--calling stored procedure query--<select id= "TestProcedure" Parametertype= "Java.util.Map" statementtype= "callable" resulttype= "Java.util.HashMap" >{call Loginandreg (#{out_ret,mode=out,javatype=java.lang.integer,jdbctype=INTEGER}, #{out_desc,mode=out,javatype=java.lang.string,jdbctype=VARCHAR}, #{userid,jdbctype=varchar,mode=Out }, #{user_pwd,jdbctype=varchar,mode=in}, #{nickname,jdbctype=varchar,mode=In }) }  </select> <!--call View query-<select id= "TestView" parametertype= "Java.util.Map" resulttype= "Java.util.Ha Shmap ">Select Username, nickname, dept from Test_view where User_type=#{usertype}</select> </mapper>

View

DROP VIEW IF EXISTS ' palm_2_0_16 '. ' Test_view '; CREATE VIEW ' palm_2_0_16 '. ' Test_view      '  as SELECT  from WHERE d.id=u.id;

Note:

The parameter conditions in the Mapper.xml in the back of a view must be returned in the views, otherwise an error will be given.

MyBatis MySQL Call view

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.