parent
3049ca2a44
commit
157bd0eb48
@ -1,2 +1,42 @@
|
||||
package com.example.demo.controller;public class DragonController {
|
||||
package com.example.demo.controller;
|
||||
|
||||
import com.example.demo.common.util.FormatResponseUtil;
|
||||
import com.example.demo.common.util.ResponseResult;
|
||||
import com.example.demo.domain.Dragon;
|
||||
import com.example.demo.service.impl.DragonServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/dragon")
|
||||
public class DragonController {
|
||||
@Autowired(required = false)
|
||||
DragonServiceImpl dragonService;
|
||||
|
||||
@GetMapping("/dragonList")
|
||||
public ResponseResult queryAll(){
|
||||
return FormatResponseUtil.formatResponse(dragonService.queryAll());
|
||||
}
|
||||
|
||||
@PostMapping("/addDragon")
|
||||
public ResponseResult addDragon(@RequestBody Dragon dragon){
|
||||
//System.out.println("1111111111");
|
||||
return FormatResponseUtil.formatResponse(dragonService.save(dragon));
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")//这里执行的是物理删除
|
||||
public ResponseResult delTDragonById(Integer id){
|
||||
return FormatResponseUtil.formatResponse(dragonService.delDragonById(id));
|
||||
}
|
||||
|
||||
@GetMapping("/one")
|
||||
public ResponseResult queryById(int id){
|
||||
return FormatResponseUtil.formatResponse(dragonService.queryDragonById(id));
|
||||
}
|
||||
|
||||
@PostMapping("/dragonInfo")
|
||||
public ResponseResult updateArea(@RequestBody Dragon dragon){
|
||||
return FormatResponseUtil.formatResponse(dragonService.updateById(dragon));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,2 +1,89 @@
|
||||
package com.example.demo.domain;public class Dragon {
|
||||
package com.example.demo.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class Dragon {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String CREATE_TIME = "createTime";
|
||||
public static final String MODIFIED_TIME = "lastEditTime";
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
/*
|
||||
* 任务内容
|
||||
* */
|
||||
private String property;
|
||||
|
||||
/**
|
||||
* 创建时间戳
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 最后修改时间戳
|
||||
*/
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private LocalDateTime lastEditTime;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getProperty() {
|
||||
return property;
|
||||
}
|
||||
|
||||
public void setProperty(String property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getLastEditTime() {
|
||||
return lastEditTime;
|
||||
}
|
||||
|
||||
public void setLastEditTime(LocalDateTime lastEditTime) {
|
||||
this.lastEditTime = lastEditTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Dragon{" +
|
||||
"id=" + id +
|
||||
", name=" + name +
|
||||
", priority=" + property +
|
||||
", createTime=" + createTime +
|
||||
", lastEditTime=" + lastEditTime +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,12 @@
|
||||
package com.example.demo.mapper;
|
||||
|
||||
public interface DragonInterface {
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.example.demo.domain.Dragon;
|
||||
|
||||
/**
|
||||
* 和数据库的连接层
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface DragonMapper extends BaseMapper<Dragon> {
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
<?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.example.demo.mapper.DragonMapper">
|
||||
|
||||
</mapper>
|
@ -1,2 +1,41 @@
|
||||
package com.example.demo.service.impl;public class DragonServiceImpl {
|
||||
package com.example.demo.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.example.demo.domain.Dragon;
|
||||
import com.example.demo.mapper.DragonMapper;
|
||||
import com.example.demo.service.IDragonService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DragonServiceImpl extends ServiceImpl<DragonMapper, Dragon> implements IDragonService {
|
||||
|
||||
|
||||
@Autowired(required = false)
|
||||
DragonMapper dragonMapper;
|
||||
|
||||
@Override
|
||||
public List<Dragon> queryAll() {
|
||||
LambdaQueryWrapper<Dragon> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.orderByAsc(Dragon::getId);
|
||||
List<Dragon> dragonList = dragonMapper.selectList(wrapper);
|
||||
return dragonList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dragon queryDragonById(int id) {
|
||||
Dragon dragon = dragonMapper.selectById(id);
|
||||
return dragon;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean delDragonById(int id) {
|
||||
boolean ans;
|
||||
int i = dragonMapper.deleteById(id);
|
||||
return ans = i>0 ? true:false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue