CRM项目后端Query对象映射提取前端的form表单实现数据提交到数据库------CRM项目

这篇具有很好参考价值的文章主要介绍了CRM项目后端Query对象映射提取前端的form表单实现数据提交到数据库------CRM项目。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

package com.alatus.web;

import com.alatus.constant.Constants;
import com.alatus.model.TActivity;
import com.alatus.query.ActivityQuery;
import com.alatus.query.UserQuery;
import com.alatus.result.R;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import com.alatus.service.ActivityService;

@RestController
public class ActivityController {


    @Resource
    private ActivityService activityService;


    @GetMapping(value = "/api/activities")
    public R activityPage(@RequestParam(value = "current",required = false)Integer current,
                          ActivityQuery activityQuery){
        if(current == null){
            current = 1;
        }
//        返回结果为PageInfo
        PageInfo<TActivity> activityByPage = activityService.getActivityByPage(current,activityQuery);
        return R.OK(activityByPage);
    }


    @PostMapping(value = "/api/activity/add")
    public R addActivity(ActivityQuery activityQuery, @RequestHeader(value = Constants.TOKEN_NAME)String token){
        activityQuery.setToken(token);
        int result = activityService.saveActivity(activityQuery);
        return result >= 1 ? R.OK() : R.FAIL();
    }


    @GetMapping(value = "/api/activity/{id}")
    public R activityDetail(@PathVariable(value = Constants.ID)Integer id){
        TActivity tActivity = activityService.getActivityById(id);
        return R.OK(tActivity);
    }


    @PutMapping(value = "/api/activity/edit")
    public R editActivity(ActivityQuery activityQuery,@RequestHeader(value = Constants.TOKEN_NAME)String token){
        activityQuery.setToken(token);
        int result = activityService.updateActivity(activityQuery);
        return result >= 1 ? R.OK() : R.FAIL();
    }

}
package com.alatus.web;

import com.alatus.constant.Constants;
import com.alatus.model.TActivity;
import com.alatus.query.ActivityQuery;
import com.alatus.query.UserQuery;
import com.alatus.result.R;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import com.alatus.service.ActivityService;

@RestController
public class ActivityController {


    @Resource
    private ActivityService activityService;


    @GetMapping(value = "/api/activities")
    public R activityPage(@RequestParam(value = "current",required = false)Integer current,
                          ActivityQuery activityQuery){
        if(current == null){
            current = 1;
        }
//        返回结果为PageInfo
        PageInfo<TActivity> activityByPage = activityService.getActivityByPage(current,activityQuery);
        return R.OK(activityByPage);
    }


    @PostMapping(value = "/api/activity/add")
    public R addActivity(ActivityQuery activityQuery, @RequestHeader(value = Constants.TOKEN_NAME)String token){
        activityQuery.setToken(token);
        int result = activityService.saveActivity(activityQuery);
        return result >= 1 ? R.OK() : R.FAIL();
    }


    @GetMapping(value = "/api/activity/{id}")
    public R activityDetail(@PathVariable(value = Constants.ID)Integer id){
        TActivity tActivity = activityService.getActivityById(id);
        return R.OK(tActivity);
    }


    @PutMapping(value = "/api/activity/edit")
    public R editActivity(ActivityQuery activityQuery,@RequestHeader(value = Constants.TOKEN_NAME)String token){
        activityQuery.setToken(token);
        int result = activityService.updateActivity(activityQuery);
        return result >= 1 ? R.OK() : R.FAIL();
    }

}
package com.alatus.service;

import com.alatus.model.TActivity;
import com.alatus.query.ActivityQuery;
import com.github.pagehelper.PageInfo;

public interface ActivityService {
    PageInfo<TActivity> getActivityByPage(Integer current, ActivityQuery activityQuery);

    int saveActivity(ActivityQuery activityQuery);

    TActivity getActivityById(Integer id);

    int updateActivity(ActivityQuery activityQuery);
}
package com.alatus.service;

import com.alatus.model.TActivity;
import com.alatus.query.ActivityQuery;
import com.github.pagehelper.PageInfo;

public interface ActivityService {
    PageInfo<TActivity> getActivityByPage(Integer current, ActivityQuery activityQuery);

    int saveActivity(ActivityQuery activityQuery);

    TActivity getActivityById(Integer id);

    int updateActivity(ActivityQuery activityQuery);
}
package com.alatus.service.impl;

import com.alatus.constant.Constants;
import com.alatus.mapper.TActivityMapper;
import com.alatus.model.TActivity;
import com.alatus.query.ActivityQuery;
import com.alatus.service.ActivityService;
import com.alatus.util.JWTUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Resource
    private TActivityMapper tActivityMapper;
    @Override
    public PageInfo<TActivity> getActivityByPage(Integer current, ActivityQuery activityQuery) {
//        设置PageHelper和分页情况
        PageHelper.startPage(current, Constants.PAGE_SIZE);
//        查询
        ArrayList<TActivity> list = tActivityMapper.selectActivityByPage(activityQuery);
//        封装分页到PageInfo中
        PageInfo<TActivity> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public int saveActivity(ActivityQuery activityQuery) {
        TActivity tActivity = new TActivity();
//        把query对象的数据复制到activity对象里面
//        这个工具类的复制要求是两个对象的属性名要相同,属性要相同
        BeanUtils.copyProperties(activityQuery,tActivity);
        tActivity.setCreateTime(new Date());
//        通过token解析出的用户获取ID作为创建者的ID
        Integer loginId = JWTUtils.parseUserFromJWT(activityQuery.getToken()).getId();
        tActivity.setCreateBy(loginId);
        return tActivityMapper.insertSelective(tActivity);
    }

    @Override
    public TActivity getActivityById(Integer id) {
        return tActivityMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateActivity(ActivityQuery activityQuery) {
        TActivity tActivity = new TActivity();
        BeanUtils.copyProperties(activityQuery,tActivity);
//        编辑时间
        tActivity.setEditTime(new Date());
//        通过token解析出的用户获取ID作为编辑者的ID
        Integer loginId = JWTUtils.parseUserFromJWT(activityQuery.getToken()).getId();
        tActivity.setEditBy(loginId);
        return tActivityMapper.updateByPrimaryKeySelective(tActivity);
    }
}
package com.alatus.service.impl;

import com.alatus.constant.Constants;
import com.alatus.mapper.TActivityMapper;
import com.alatus.model.TActivity;
import com.alatus.query.ActivityQuery;
import com.alatus.service.ActivityService;
import com.alatus.util.JWTUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Resource
    private TActivityMapper tActivityMapper;
    @Override
    public PageInfo<TActivity> getActivityByPage(Integer current, ActivityQuery activityQuery) {
//        设置PageHelper和分页情况
        PageHelper.startPage(current, Constants.PAGE_SIZE);
//        查询
        ArrayList<TActivity> list = tActivityMapper.selectActivityByPage(activityQuery);
//        封装分页到PageInfo中
        PageInfo<TActivity> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public int saveActivity(ActivityQuery activityQuery) {
        TActivity tActivity = new TActivity();
//        把query对象的数据复制到activity对象里面
//        这个工具类的复制要求是两个对象的属性名要相同,属性要相同
        BeanUtils.copyProperties(activityQuery,tActivity);
        tActivity.setCreateTime(new Date());
//        通过token解析出的用户获取ID作为创建者的ID
        Integer loginId = JWTUtils.parseUserFromJWT(activityQuery.getToken()).getId();
        tActivity.setCreateBy(loginId);
        return tActivityMapper.insertSelective(tActivity);
    }

    @Override
    public TActivity getActivityById(Integer id) {
        return tActivityMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateActivity(ActivityQuery activityQuery) {
        TActivity tActivity = new TActivity();
        BeanUtils.copyProperties(activityQuery,tActivity);
//        编辑时间
        tActivity.setEditTime(new Date());
//        通过token解析出的用户获取ID作为编辑者的ID
        Integer loginId = JWTUtils.parseUserFromJWT(activityQuery.getToken()).getId();
        tActivity.setEditBy(loginId);
        return tActivityMapper.updateByPrimaryKeySelective(tActivity);
    }
}
package com.alatus.query;

import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;

@Data
public class ActivityQuery extends BaseQuery{
    private Integer id;

    private Integer ownerId;

//    将字符串转换为符合这个pattern规范的日期
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    private String name;

    private BigDecimal cost;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    private String description;
}
package com.alatus.query;

import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;

@Data
public class ActivityQuery extends BaseQuery{
    private Integer id;

    private Integer ownerId;

//    将字符串转换为符合这个pattern规范的日期
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    private String name;

    private BigDecimal cost;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    private String description;
}

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

到了这里,关于CRM项目后端Query对象映射提取前端的form表单实现数据提交到数据库------CRM项目的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

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

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

相关文章

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包