自创的安卓代码生成器-生成SpringBoot工程文件

大家好,我是飞刀,这次我来讲一下生成SpringBoot工程文件的功能。

首先打开界面看一下:

自创的安卓代码生成器-生成SpringBoot工程文件

这个功能也不是安卓使用的,而是我自己开发SpringBoot项目时使用的。

输入一个实体类:

public class Feedback {

private String phone;

private String content;

private Date createDatetime;

}

点击生成,结果如下:

自创的安卓代码生成器-生成SpringBoot工程文件

输出框生成的代码:

package com.zheng.boot.entity;

 

import com.fasterxml.jackson.annotation.JsonFormat;

import lombok.Data;

 

import java.util.Date;

 

@Data

public class Feedback {

private String phone;

private String content;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")

private Date createDatetime;

}

 

 

package com.zheng.boot.controller;

 

import com.zheng.boot.common.JsonResult;

import com.zheng.boot.entity.Feedback;

import com.zheng.boot.service.FeedbackService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

 

import java.util.Date;

import java.util.List;

 

@RestController

@RequestMapping("feedback")

public class FeedbackController {

 

@Autowired

FeedbackService feedbackService;

 

/**

* 插入

*/

@RequestMapping(value = {"/insert"})

public JsonResult<Feedback> insert(String phone, String content) {

if (content == null) {

return new JsonResult(-1, "content不能为空");

}

Feedback feedback = new Feedback();

feedback.setPhone(phone);

feedback.setContent(content);

feedback.setCreateDatetime(new Date());

int count = feedbackService.insert(feedback);

if (count > 0) {

return new JsonResult(0, "插入成功");

} else {

return new JsonResult(-1, "插入失败");

}

}

 

/**

* 删除

*/

@RequestMapping(value = {"/delete"})

public JsonResult<Feedback> delete(String phone) {

if (phone == null) {

return new JsonResult(-1, "phone不能为空");

}

int count = feedbackService.deleteByPrimaryKey(phone);

if (count > 0) {

return new JsonResult(0, "删除成功");

} else {

return new JsonResult(-1, "删除失败");

}

}

 

/**

* 更新

*/

@RequestMapping(value = {"/update"})

public JsonResult<Feedback> update(String phone, String content) {

if (phone == null) {

return new JsonResult(-1, "phone不能为空");

}

Feedback feedback = new Feedback();

feedback.setPhone(phone);

feedback.setContent(content);

feedback.setCreateDatetime(new Date());

int count = feedbackService.updateByPrimaryKey(feedback);

if (count > 0) {

return new JsonResult(0, "更新成功");

} else {

return new JsonResult(-1, "更新失败");

}

}

 

/**

* 查询

*/

@RequestMapping(value = {"/select"})

public JsonResult<Feedback> select(String phone) {

if (phone == null) {

return new JsonResult(-1, "phone不能为空");

}

Feedback feedback = feedbackService.selectByPrimaryKey(phone);

if (feedback == null) {

return new JsonResult(-1, "查询信息不存在");

}

return new JsonResult(0, feedback);

}

 

/**

* 查询全部

*/

@RequestMapping(value = {"/selectAll"})

public JsonResult<List<Feedback>> selectAll() {

List<Feedback> feedbackList = feedbackService.selectAll();

return new JsonResult(0, feedbackList);

}

 

/**

* 查询分页

*/

@RequestMapping(value = {"/selectPage"})

public JsonResult<List<Feedback>> selectPage(Integer pageNum, Integer pageSize) {

List<Feedback> feedbackList = feedbackService.selectPage(pageNum, pageSize);

return new JsonResult(0, feedbackList);

}

 

}

 

 

 

 

package com.zheng.boot.service;

 

import com.zheng.boot.entity.Feedback;

 

import java.util.List;

 

public interface FeedbackService {

 

int insert(Feedback feedback);

 

int deleteByPrimaryKey(String phone);

 

int updateByPrimaryKey(Feedback feedback);

 

Feedback selectByPrimaryKey(String phone);

 

List<Feedback> selectAll();

 

List<Feedback> selectPage(Integer pageNum, Integer pageSize);

}

 

 

 

package com.zheng.boot.serviceImpl;

 

import com.github.pagehelper.PageHelper;

import com.zheng.boot.entity.Feedback;

import com.zheng.boot.mapper.FeedbackMapper;

import com.zheng.boot.service.FeedbackService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

 

import java.util.List;

 

@Service

public class FeedbackServiceImpl implements FeedbackService {

@Autowired

FeedbackMapper feedbackMapper;

 

@Override

public int insert(Feedback feedback) {

return feedbackMapper.insert(feedback);

}

 

@Override

public int deleteByPrimaryKey(String phone) {

return feedbackMapper.deleteByPrimaryKey(phone);

}

 

@Override

public int updateByPrimaryKey(Feedback feedback) {

return feedbackMapper.updateByPrimaryKey(feedback);

}

 

@Override

public Feedback selectByPrimaryKey(String phone) {

return feedbackMapper.selectByPrimaryKey(phone);

}

 

@Override

public List<Feedback> selectAll() {

return feedbackMapper.select();

}

 

@Override

public List<Feedback> selectPage(Integer pageNum, Integer pageSize) {

PageHelper.startPage(pageNum,pageSize);

return feedbackMapper.select();

}

}

 

 

 

 

package com.zheng.boot.mapper;

 

import com.zheng.boot.entity.Feedback;

 

import java.util.List;

 

public interface FeedbackMapper {

 

int insert(Feedback feedback);

 

int deleteByPrimaryKey(String phone);

 

int updateByPrimaryKey(Feedback feedback);

 

Feedback selectByPrimaryKey(String phone);

 

List<Feedback> select();

 

}

 

 

<?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.zheng.boot.mapper.FeedbackMapper">

<resultMap id="BaseResultMap" type="Feedback">

<id column="phone" property="phone"/>

<result column="phone" property="phone"/>

<result column="content" property="content"/>

<result column="create_datetime" property="createDatetime"/>

</resultMap>

<sql id="Base_Column_List">

phone, content, create_datetime

</sql>

<insert id="insert">

insert into feedback (phone, content, create_datetime)

values (#{phone}, #{content}, #{createDatetime})

</insert>

<delete id="deleteByPrimaryKey">

delete from feedback where phone = #{phone}

</delete>

<update id="updateByPrimaryKey">

update feedback set

content = #{content},

create_datetime = #{createDatetime}

where phone = #{phone}

</update>

<select id="selectByPrimaryKey" resultMap="BaseResultMap">

select <include refid="Base_Column_List"/> from feedback where phone = #{phone}

</select>

<select id="select" resultMap="BaseResultMap">

select * from feedback order by created desc

</select>

</mapper>

 

自动生成了SpringBoot各个层的增删改查代码,同样不需要复制这些代码,因为代码已经自动写入项目工程中了,看看截图:

首先实体类entity自动添加了lombok注解:

自创的安卓代码生成器-生成SpringBoot工程文件

然后是Controller:

自创的安卓代码生成器-生成SpringBoot工程文件

Service:

自创的安卓代码生成器-生成SpringBoot工程文件

serviceImpl:

自创的安卓代码生成器-生成SpringBoot工程文件

mapper:

自创的安卓代码生成器-生成SpringBoot工程文件

以及mapper.xml:

自创的安卓代码生成器-生成SpringBoot工程文件

 

最后再根据自己的需要稍微调整一下就可以了。

 

好了,今天的内容分享就到这了,我们下篇见。

【我是小尾巴】自创的安卓快速开发框架,自创的自定义控件,自创的代码生成器,自创的代码模板,自创的demo集合。并开始涉猎springboot,vue,uniapp,unicloud,云函数,云数据库,cocoscreator游戏开发。同时也分享一些好用的软件,开发工具,学习视频。关注微信公众号【飞刀帮主】免费获取资料。

自创的安卓代码生成器-生成SpringBoot工程文件自创的安卓代码生成器-生成SpringBoot工程文件