【若依】框架:第01讲前后端分离项目

这篇具有很好参考价值的文章主要介绍了【若依】框架:第01讲前后端分离项目。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

介绍 | RuoYi

一、准备工作

1.IDEA准备

        将下载好的若依项目导入IDEA,导入后配置MAVEN环境,等待下载完成。重点关注ruoyi-admin和ruoyi-system两个文件夹,前者放controller,后者放实体类、mapper、service

2.打开VS Code前端编写

①打开文件夹选择若依前端项目(ruoyi-ui)文件夹

②信任此作者进入

③重点关心src文件夹下的api和views两个文件夹

3.右键以管理员身份启动redis-server服务

【若依】框架:第01讲前后端分离项目

上图表示成功启动

4.IDEA启动

【若依】框架:第01讲前后端分离项目

5.VS Code启动

①新建终端

【若依】框架:第01讲前后端分离项目

②下方黑窗口输入口令,只要没有error就算启动成功,报错后可尝试重启电脑,理论上环境变量自动生成

npm install --registry=https://registry.npmmirror.com

【若依】框架:第01讲前后端分离项目

 ③启动服务

npm run dev

【若依】框架:第01讲前后端分离项目

自动弹出若依管理系统表示项目已经启动成功。

【若依】框架:第01讲前后端分离项目

二、后台代码编写

1.在ruoyi-system中创建自己的包basic

【若依】框架:第01讲前后端分离项目

①编写实体类、mapper以及service层代码

实体类

public class Channel extends BaseEntity {
    private String id;  //32位主键ID
    private String channelName;  //栏目名
    private Integer isShow;  //是否显示
    //private Date updateTime; //更新时间,父类中有子类删掉即可

    //手动生成getter和setter

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getChannelName() {
        return channelName;
    }

    public void setChannelName(String channelName) {
        this.channelName = channelName;
    }

    public Integer getIsShow() {
        return isShow;
    }

    public void setIsShow(Integer isShow) {
        this.isShow = isShow;
    }
}

 mapper

public interface ChannelMapper {
    /**
     * 添加栏目
     * @param channel
     * @return
     */
    public int insertChannel(Channel channel);

    /**
     * 根据ID删除栏目
     * @param id
     * @return
     */
    public int deleteChannelById(String id);

    /**
     * 修改栏目
     * @param channel
     * @return
     */
    public int updateChannel(Channel channel);

    /**
     * 根据ID查询栏目
     * @param id
     * @return
     */
    public Channel selectChannelById(String id);

    /**
     * 根据条件,查询栏目列表
     * @param channel
     * @return
     */
    public List<Channel> selectChannelList(Channel channel);
}

mapper.xml(basic和system不能同级可以选择打开文件根目录,在mapper文件夹中新建basic文件夹,回到项目刷新即可)

<?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.ruoyi.basic.mapper.ChannelMapper">
    <resultMap id="ChannelResult" type="Channel">
        <result property="id" column="id"></result>
        <result property="channelName" column="channel_name"></result>
        <result property="isShow" column="is_show"></result>
        <result property="updateTime" column="update_time"></result>
    </resultMap>

    <sql id="selectChannelVO">
        select id,channel_name,is_show,update_time from cms_channel
    </sql>

    <select id="selectChannelById" parameterType="String" resultMap="ChannelResult">
        <include refid="selectChannelVO"></include>
        where id=#{id}
    </select>

    <select id="selectChannelList" parameterType="Channel" resultMap="ChannelResult">
        <include refid="selectChannelVO"></include>
        <where>
            <if test="channelName != null and channelName != ''">and channel_name like concat(#{channelName},'%')</if>
            <if test="isShow != null">and is_show=#{isShow}</if>
        </where>
    </select>

    <insert id="insertChannel" parameterType="Channel">
        insert into
            cms_channel (id,channel_name,is_show,update_time)
        values
            (#{id},#{channelName},#{isShow},#{updateTime})
    </insert>

    <delete id="deleteChannelById" parameterType="String">
        delete from cms_channel where id=#{id}
    </delete>

    <update id="updateChannel" parameterType="Channel">
        update cms_channel
        set channel_name=#{channelName},is_show=#{isShow},update_time=#{updateTime}
        where id=#{id}
    </update>

</mapper>

service层

public interface IChannelService {
    /**
     * 添加栏目
     * @param channel
     * @return
     */
    public int insertChannel(Channel channel);

    /**
     * 根据ID删除栏目
     * @param id
     * @return
     */
    public int deleteChannelById(String id);

    /**
     * 修改栏目
     * @param channel
     * @return
     */
    public int updateChannel(Channel channel);

    /**
     * 根据ID查询栏目
     * @param id
     * @return
     */
    public Channel selectChannelById(String id);

    /**
     * 根据条件,查询栏目列表
     * @param channel
     * @return
     */
    public List<Channel> selectChannelList(Channel channel);
}

service层实现类

@Service
public class ChannelServiceImpl implements IChannelService {

    @Autowired(required = false)
    private ChannelMapper channelMapper;
    @Override
    public int insertChannel(Channel channel) {
        //id不是自增,需要生成32位主键ID
        String id = UUID.randomUUID().toString().replace("-","");
        channel.setId(id);
        return channelMapper.insertChannel(channel);
    }

    @Override
    public int deleteChannelById(String id) {
        return channelMapper.deleteChannelById(id);
    }

    @Override
    public int updateChannel(Channel channel) {
        return channelMapper.updateChannel(channel);
    }

    @Override
    public Channel selectChannelById(String id) {
        return channelMapper.selectChannelById(id);
    }

    @Override
    public List<Channel> selectChannelList(Channel channel) {
        return channelMapper.selectChannelList(channel);
    }
}

2.在ruoyi-admin中创建自己的包basic

controller文章来源地址https://www.toymoban.com/news/detail-402530.html

@RestController
@RequestMapping("/basic/channel")
public class ChannelController extends BaseController {

    @Autowired
    private IChannelService channelService;

    @PostMapping("/add")
    public AjaxResult add(Channel channel){
        int rows = channelService.insertChannel(channel);
        return toAjax(rows);//如果rows > 0就是成功,否则失败
    }

    @DeleteMapping("/remove")
    public AjaxResult remove(String id){
        int rows = channelService.deleteChannelById(id);
        return toAjax(rows);//如果rows > 0就是成功,否则失败
    }

    @PutMapping("/edit")
    public AjaxResult edit(Channel channel){
        int rows = channelService.updateChannel(channel);
        return toAjax(rows);//如果rows > 0就是成功,否则失败
    }

    @GetMapping("/get_info")
    public AjaxResult grtInfo(String id){
        return AjaxResult.success(channelService.selectChannelById(id));
//        Channel channel = channelService.selectChannelById(id);
//        return AjaxResult.success(channel);
    }

    @GetMapping("/list")
    public TableDataInfo list(Channel channel){
        startPage();//分页函数,注意:该函数必须和select语句写在一起
        List<Channel> channels = channelService.selectChannelList(channel);
        return getDataTable(channels);
    }
}

到了这里,关于【若依】框架:第01讲前后端分离项目的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Ruoyi若依前后端分离框架【若依登录详细过程】

    后端包含ruoyi-admin,ruoyi-common,ruoyi-framework等多个模块,ruoyi-admin为启动模块。先看一下ruoyi-admin/src/main/application.yml配置文件。 指定了服务端启动的端口8080。我们运行ruoyi-admin/src/main/java/com/ruoyi/ RuoYiApplication.java即可启动后端,监听8080端口。 我们回到前端的登录界面。 views

    2024年02月05日
    浏览(48)
  • 从零入门开源框架---若依(前后端分离版)

    一、若依是什么? 若依它就是一个开源项目,别人写好的代码,我们拿来进行二次开发,它主要是做数据和权限管理系统。 二、使用背景 任何公司的各种大的项目必然需要一个后台权限管理系统,这是必然的,但是如果不想投入太多人力物力去开发,又恰好有现成且比较好用

    2024年02月02日
    浏览(27)
  • 若依框架环境的搭建(前后端不分离版)

            最近在做数据库课程设计,因为不想再用Java里面的GUI界面,想用Web页面来替代,但手写各个页面和增删改查这些重复性较高的模块属实作业量不小,所以,正好借此机会来学习一下早有耳闻的,号称后台管理系统神器—— 若依框架 ,下面先来总结一下环境部署与

    2024年02月04日
    浏览(44)
  • 若依前后端分离项目docker部署

    1.centos 7 2.docker 3.mysql5.x 8.x 4.redis 5.nginx 前往 Gitee 下载页面(https://gitee.com/y_project/RuoYi-Vue (opens new window))下载解压到工作目录 3.1 后端 1.下载代码到本地后,解压完成,用idea打开项目 2.创建数据库:ry-vue 3.在创建好数据库后,运行以下两个sql文件生成数据表(quartz.sql、ry_202208

    2024年02月05日
    浏览(32)
  • 基于若依前后端分离框架的小程序的token验证

    后端和管理端都用的若依框架。 但是前段的小程序需要微信授权登录。这时候就需要在若依框架上重新再起一套token验证。 首先创建两个类(只要放在你能够引用得到的位置就可以): 第一个:实体 第二个service: 下一步: 找到 com.ruoyi.framework.security.filter; 这个文件 添加你

    2024年02月11日
    浏览(32)
  • 四、若依(前后端分离)项目构建docker 镜像

    修改配置文件参数,数据库ip和账号密码 修改端口号,这个修改不修改都无所谓,docker run时端口映射时修改也可以的 redis ip和端口修改 输入目录 rz 上传

    2024年02月10日
    浏览(33)
  • IDEA若依框架入门(前后端分离版本) 0基础详细步骤代码导入运行

    若依官网:http://ruoyi.vip (这些准备工作,都会在其他章节持续更新相应操作步骤的奥~请关注我❤) JDK = 1.8 (推荐1.8版本) Mysql = 5.7.0 (推荐5.7版本) Redis = 3.0 Maven = 3.0 Node = 12 官网地址:https://gitee.com/y_project/RuoYi-Vue 1.可以点击克隆/下载,直接导出。下载后解压即可导入IDEA使用

    2024年02月09日
    浏览(50)
  • 【若依后管框架(前后端分离版)】 如何部署若依以及添加自己的功能模块和菜单

    【若依后管框架(前后端分离版)】 如何添加自己的功能模块以及菜单 【文章开始之前,先说一句,若依牛逼!】 1 若依框架简介 RuoYi-Vue 是一个 Java EE 企业级快速开发平台,基于经典技术组合(Spring Boot、Spring Security、MyBatis、Jwt、Vue),内置模块如:部门管理、角色用户、菜

    2024年02月05日
    浏览(43)
  • 若依前后端分离项目在腾讯云的部署

    本文章使用了腾讯云提供的宝塔系统 在部署项目和配置环境的时候会相对其他方法更容易一些  购买腾讯云服务器 腾讯云11.11云上盛惠_腾讯云11.11优惠活动-腾讯云 (tencent.com)  我购买的是2核4g的服务器 之前听老师建议最好2核4g起步    购买的时候选择默认的宝塔系统就ok了不

    2024年02月06日
    浏览(33)
  • 若依RuoYi-Vue项目部署(前后端分离版本)

    RuoYi 是一个后台管理系统,基于经典技术组合(Spring Boot、Apache Shiro、MyBatis、Thymeleaf)主要目的让开发者注重专注业务,降低技术难度,从而节省人力成本,缩短项目周期,提高软件安全质量。 若依是作者给女儿取的名字(寓意:你若不离不弃,我必生死相依) 在线体验 若

    2023年04月08日
    浏览(39)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包