In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces mybatis-plus how to query the incoming parameter Map, return List mode, the article introduces in great detail, has a certain reference value, interested friends must read!
Mybatis-plus query passes the parameter Map and returns List
Because sometimes the entity class attributes are not enough, and you don't want to write a custom VO, so use map, which is very convenient to return to the foreground.
1 、 mapper.xml
Note that it is resultType, not resultMap, or an error is reported.
SELECT * FROM order and order_id = # {orderId} 2, mapper.javaList getOrder (Map map); 3. Service assembly query condition public List getOrder (String storeId) {Map map=new HashMap (); map.put ("orderId", orderId); return storeApiOrderMapper.getOrder (map);} the basic use of mybatis-plus first we need to create a database table
Used to demonstrate the basic usage of MyBatis-Plus.
CREATE TABLE `user` (`id` varchar (32) NOT NULL, `username` varchar (32) DEFAULT'', `password` varchar (32) DEFAULT'', PRIMARY KEY (`id`)), and then create a Spring Boot project
The pom.xml and configuration are as follows:
4.0.0 org.kaven mybatis-plus 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent 2.3.4.RELEASE 1.8 org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter- Test org.springframework.boot spring-boot-starter-webflux com.baomidou mybatis-plus-boot-starter 3.4.0 mysql mysql-connector-java 5.1.49 org.projectlombok Lombok org.springframework.boot spring-boot-maven-plugin spring: application: name: mybatis-plus datasource: driver-class-name: com.mysql.jdbc.Driver username: root password: 123456 url: jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf- 8&useSSL=falseserver: port: 8085 logging: level: root: warn com.kaven.mybatisplus.dao: trace pattern: console:'% p% m% n'
Entity class User:
Package com.kaven.mybatisplus.entity;import com.baomidou.mybatisplus.annotation.TableField;import com.baomidou.mybatisplus.annotation.TableId;import com.baomidou.mybatisplus.annotation.TableName;import lombok.Data;@TableName ("user") @ Datapublic class User {@ TableId private String id; @ TableField ("username") private String username; @ TableField ("password") private String password / * * use @ TableField (exist = false), indicating that the field does not exist in the database, so it will not be inserted into the database * attributes decorated with transient and static will not be inserted into the database * / @ TableField (exist = false) private String phone;}
Mapper API UserMapper:
Package com.kaven.mybatisplus.dao;import com.baomidou.mybatisplus.core.mapper.BaseMapper;import com.kaven.mybatisplus.entity.User;import org.springframework.stereotype.Component;@Componentpublic interface UserMapper extends BaseMapper {}
UserMapper needs to inherit the BaseMapper interface of MyBatis-Plus.
The source code of the BaseMapper interface is as follows, which actually defines the CRUD methods of some database tables.
Package com.baomidou.mybatisplus.core.mapper;import com.baomidou.mybatisplus.core.conditions.Wrapper;import com.baomidou.mybatisplus.core.metadata.IPage;import java.io.Serializable;import java.util.Collection;import java.util.List;import java.util.Map;import org.apache.ibatis.annotations.Param;public interface BaseMapper extends Mapper {int insert (T entity); int deleteById (Serializable id); int deleteByMap (@ Param ("cm") Map columnMap); int delete (@ Param ("ew") Wrapper wrapper) Int deleteBatchIds (@ Param ("coll") Collection
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.