赞
踩
目录
3、在Idea中添加数据库 --------以Oracle数据库为例
6、自动生成(增删查改)在TestMapper中快速编写代码
file-->settings -->Plugins
下一步:按照红色表示的地方配置,其他的地方不用改变
测试ok后,点击Apply--OK就加好了
第一步:以TEST表为例,右键Test表,选择MybatisX-Generator
第二步:进入一下页面,填写信息
第三步:点击Next后,检查路径,文件名,基础选项配置
下一步:点击Finish,就可以了
生成的包名,接口,实体类,实现类为:
entity包下的Test实体类
- package com.entity;
-
- import com.baomidou.mybatisplus.annotation.TableField;
- import com.baomidou.mybatisplus.annotation.TableName;
- import java.io.Serializable;
- import lombok.Data;
-
- /**
- *
- * @TableName TEST
- */
- @TableName(value ="TEST")
- @Data
- public class Test implements Serializable {
- /**
- *
- */
- private Long id;
-
- /**
- *
- */
- private String jan;
-
- /**
- *
- */
- private String feb;
-
- /**
- *
- */
- private String mar;
-
- /**
- *
- */
- private String apr;
-
- /**
- *
- */
- private String may;
-
- /**
- *
- */
- private String jun;
-
- /**
- *
- */
- private String jul;
-
- /**
- *
- */
- private String aug;
-
- /**
- *
- */
- private String sep;
-
- /**
- *
- */
- private String oct;
-
- /**
- *
- */
- private String nov;
-
- /**
- *
- */
- private String dec;
-
- @TableField(exist = false)
- private static final long serialVersionUID = 1L;
- }
mapper包下的TestMapper
- package com.mapper;
-
- import com.entity.Test;
- import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-
- /**
- * @Entity com.entity.Test
- */
- public interface TestMapper extends BaseMapper<Test> {
-
- }
service包下的TestService
- package com.service;
-
- import com.entity.Test;
- import com.baomidou.mybatisplus.extension.service.IService;
-
- /**
- *
- */
- public interface TestService extends IService<Test> {
-
- }
service.impl 包下的TestServiceImpl
- package com.service.impl;
-
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.entity.Test;
- import com.service.TestService;
- import com.mapper.TestMapper;
- import org.springframework.stereotype.Service;
-
- /**
- *
- */
- @Service
- public class TestServiceImpl extends ServiceImpl<TestMapper, Test> implements TestService{
-
- }
-
mapper配置文件TestMapper.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="com.mapper.TestMapper">
-
- <resultMap id="BaseResultMap" type="com.entity.Test">
- <result property="id" column="ID" jdbcType="DECIMAL"/>
- <result property="jan" column="JAN" jdbcType="VARCHAR"/>
- <result property="feb" column="FEB" jdbcType="VARCHAR"/>
- <result property="mar" column="MAR" jdbcType="VARCHAR"/>
- <result property="apr" column="APR" jdbcType="VARCHAR"/>
- <result property="may" column="MAY" jdbcType="VARCHAR"/>
- <result property="jun" column="JUN" jdbcType="VARCHAR"/>
- <result property="jul" column="JUL" jdbcType="VARCHAR"/>
- <result property="aug" column="AUG" jdbcType="VARCHAR"/>
- <result property="sep" column="SEP" jdbcType="VARCHAR"/>
- <result property="oct" column="OCT" jdbcType="VARCHAR"/>
- <result property="nov" column="NOV" jdbcType="VARCHAR"/>
- <result property="dec" column="DEC" jdbcType="VARCHAR"/>
- </resultMap>
-
- <sql id="Base_Column_List">
- ID,JAN,FEB,
- MAR,APR,MAY,
- JUN,JUL,AUG,
- SEP,OCT,NOV,
- DEC
- </sql>
- </mapper>
自动生成查询-----写select关键字,
自动生成新增-----写insert关键字
自动生成修改-----写update关键字
自动生成删除-----写del关键字
自动带出后面的操作,例如,根据id查询,根据Apr查询,后面也会有根据哪个字段排序等
写完想要的接口后,接口名右键选择Show Context Actions
进入后,选择第一个
自动生成接口带参数
TestMapper.xml
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。