mybaits判断要查询的表是否存在

Service层


实现类:



mybatis配置文件

    <select id="selectTableByName" parameterType="java.util.Map" resultType="String">
        show TABLES like #{tablename}
      </select>



-----------------------------------------运行结果--------------------------------------

如果表不存在,则返回空。

MyBatis provides various ways to conditionally apply mappings based on the values in a `Map`. Here are a few options: 1. Using `<if>` element: You can use the `<if>` element in your SQL mapping XML file to conditionally include or exclude certain parts of the SQL statement based on the values in the `Map`. For example: ```xml <select id="selectUsers" resultType="User"> SELECT * FROM users <where> <if test="name != null">AND name = #{name}</if> <if test="age != null">AND age = #{age}</if> </where> </select> ``` 2. Using `<choose>`, `<when>`, and `<otherwise>` elements: If you have multiple conditions to check, you can use the `<choose>`, `<when>`, and `<otherwise>` elements in your SQL mapping XML file. For example: ```xml <select id="selectUsers" resultType="User"> SELECT * FROM users <where> <choose> <when test="name != null">AND name = #{name}</when> <when test="age != null">AND age = #{age}</when> <otherwise></otherwise> </choose> </where> </select> ``` 3. Using dynamic SQL: MyBatis also allows you to write dynamic SQL statements using the `<script>` element. Inside the `<script>` element, you can write conditional logic using standard Java syntax. For example: ```xml <select id="selectUsers" resultType="User"> SELECT * FROM users <where> <script> <if test="name != null">AND name = #{name}</if> <if test="age != null">AND age = #{age}</if> </script> </where> </select> ``` These are just a few examples of how you can conditionally apply mappings in MyBatis based on the values in a `Map`. You can choose the approach that suits your needs best.
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值