在mapper文件中隨便寫java
<select id="" resultMap="resultMap"> select * from USER_INFO t where t.name = #{sdfa,jdbcType=VARCHAR} </select>
List<Student> get(String name);
參數名字就是collectionspring
<select id="" resultMap="resultMap"> select * from USER_INFO t where t.name in <foreach collection="conllection" item="i" ......> </foreach> </select>
List<Student> get(List<String> names);
可使用 @Param("parametername")apache
<select id="" resultMap="resultMap"> select * from USER_INFO t where t.name in <foreach collection="param" item="i" ......> </foreach> and age = #{age,jdbcType=NUMERIC} </select>
List<Student> get(@Param("param") List<String> names,@Param("age") int age);
若是不想使用@Param,而是想直接使用接口方法參數的變量名做爲mapper的參數名,須要增長 編譯參數 -parameters
,並啓用 useActualParamName
選項(默認開啓)來編譯項目這裏以maven爲例springboot
普通工程app
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <target>1.8</target> <source>1.8</source> <parameters>true</parameters> </configuration> </plugin> </plugins> </build>
springboot:jvm
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <jvmArguments>-parameters</jvmArguments><!-- 增長這個參數 --> </configuration> </plugin>
如上設置好以後 ,就能夠直接用接口方法參數名做爲mapper參數了maven
接口文件中:spring-boot
List<ComBusinessSwitch> getSwitchByCode(String code, String orgId, String stationId);
mapper文件中ui
<select id="getSwitchByCode" resultMap="BaseResultMap"> select * from SWITCH T where code = #{code,jdbcType=VARCHAR} and orgid = #{orgId,jdbcType=VARCHAR} and stationid = #{stationId,jdbcType=VARCHAR} </select>