3.0.0版本是集成了Mybatis-plus版本——源码分支mybatisPlus
<dependency>
<groupId>com.github.flying-cattle</groupId>
<artifactId>mybatis-dsc-generator</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
实体类
@ApiModel(value = "AcademyEntity")
@Data
@NoArgsConstructor
@Accessors(chain = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@TableName("tt_academy")
public class AcademyEntity extends BaseEntity implements Serializable {
/**
* 机构名称
*/
@ApiModelProperty(value = "机构名称",required = true)
@Column(name = "name")
private String name;
/**
* 机构代码
*/
@ApiModelProperty(value = "机构代码",required = true)
@Column(name = "code")
private String code;
/**
* 简称
*/
@ApiModelProperty(value = "简称")
@Column(name = "abbreviation")
private String abbreviation;
}
DAO
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import com.tfbj.itoo.exam.entity.AcademyEntity;
/**
*
* <p>说明: 用户数据访问层</P>
* @version: V1.0
* @author: BianPeng
*
*/
@Mapper
public interface UserDao extends BaseMapper<AcademyEntity> {
}
生成的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.xin.usercenter.dao.UserDao">
<resultMap id="BaseResultMap" type="com.tfbj.itoo.exam.entity.AcademyEntity">
<id column="id" property="id" />
<id column="login_name" property="loginName" />
<id column="password" property="password" />
<id column="nickname" property="nickname" />
<id column="type" property="type" />
<id column="state" property="state" />
<id column="note" property="note" />
<id column="create_time" property="createTime" />
<id column="update_time" property="updateTime" />
<id column="update_uid" property="updateUid" />
<id column="login_ip" property="loginIp" />
<id column="login_addr" property="loginAddr" />
</resultMap>
<sql id="Base_Column_List">
id, login_name, password, nickname, type, state, note, create_time, update_time, update_uid, login_ip, login_addr
</sql>
</mapper>
生成的SERVICE
import com.tfbj.itoo.exam.entity.AcademyEntity;
import com.baomidou.mybatisplus.extension.service.IService;
/**
*
* @version: V1.0
* @author: BianPeng
*
*/
public interface UserService extends IService<AcademyEntity> {
}
生成的SERVICE_IMPL
import com.tfbj.itoo.exam.entity.AcademyEntity;
import com.xin.usercenter.dao.UserDao;
import com.xin.usercenter.service.UserService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/**
* @version: V1.0
* @author: BianPeng
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, AcademyEntity> implements UserService {
}
生成的CONTROLLER
import com.item.util.JsonResult;
import com.tfbj.itoo.exam.entity.AcademyEntity;
import com.xin.usercenter.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* <p>说明: 用户API接口层</P>
* @version: V1.0
* @author: BianPeng
*
*/
@Api(description = "用户",value="用户" )
@RestController
@RequestMapping("/user")
public class UserController {
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
public UserService userServiceImpl;
/**
* @explain 查询用户对象 <swagger GET请求>
* @param 对象参数:id
* @return user
* @author Limit
* @time 2019年4月9日
*/
@GetMapping("/getUserById/{id}")
@ApiOperation(value = "获取用户信息", notes = "获取用户信息[user],作者:BianPeng")
@ApiImplicitParam(paramType="path", name = "id", value = "用户id", required = true, dataType = "Long")
public JsonResult<User> getUserById(@PathVariable("id")Long id){
JsonResult<User> result=new JsonResult<User>();
try {
AcademyEntity user=userServiceImpl.getById(id);
if (user!=null) {
result.setType("success");
result.setMessage("成功");
result.setData(user);
} else {
logger.error("获取用户失败ID:"+id);
result.setType("fail");
result.setMessage("你获取的用户不存在");
}
} catch (Exception e) {
logger.error("获取用户执行异常:"+e.getMessage());
result=new JsonResult<User>(e);
}
return result;
}
}