栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

书本管理‘

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

书本管理‘

后台代码:

实体类:

@ToString
public class Book {
    private Integer id;

    private String bookname;

    private Float price;

    private String booktype;

    public Book(Integer id, String bookname, Float price, String booktype) {
        this.id = id;
        this.bookname = bookname;
        this.price = price;
        this.booktype = booktype;
    }

    public Book() {
        super();
    }

    public Integer getId() {
        return id;
    }

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

    public String getBookname() {
        return bookname;
    }

    public void setBookname(String bookname) {
        this.bookname = bookname;
    }

    public Float getPrice() {
        return price;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    public String getBooktype() {
        return booktype;
    }

    public void setBooktype(String booktype) {
        this.booktype = booktype;
    }
}

数据访问层(接口):
@Repository
public interface BookMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Book record);

    List all(Book book);

    int insertSelective(Book record);

    Book selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Book record);

    int updateByPrimaryKey(Book record);
}

接口实现类:



  
    
      
      
      
      
    
  
  
    id, bookname, price, booktype
  
  
    select  from t_book where 1=1
    
      and bookname like concat(#{bookname},'%');
    
  
  
    delete from t_book
    where id = #{id,jdbcType=INTEGER}
  
  
    insert into t_book (bookname, price,
      booktype)
    values (#{bookname,jdbcType=VARCHAR}, #{price,jdbcType=REAL},
      #{booktype,jdbcType=VARCHAR})
  
  
    insert into t_book
    
      
        id,
      
      
        bookname,
      
      
        price,
      
      
        booktype,
      
    
    
      
        #{id,jdbcType=INTEGER},
      
      
        #{bookname,jdbcType=VARCHAR},
      
      
        #{price,jdbcType=REAL},
      
      
        #{booktype,jdbcType=VARCHAR},
      
    
  
  
    update t_book
    
      
        bookname = #{bookname,jdbcType=VARCHAR},
      
      
        price = #{price,jdbcType=REAL},
      
      
        booktype = #{booktype,jdbcType=VARCHAR},
      
    
    where id = #{id,jdbcType=INTEGER}
  
  
    update t_book
    set bookname = #{bookname,jdbcType=VARCHAR},
      price = #{price,jdbcType=REAL},
      booktype = #{booktype,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  


业务逻辑层(接口):
public interface IBookService {

    int insert(Book record);

    List all(Book book);

}

实现类:
@Service
public class BookServiceImpl implements IBookService {

    @Autowired
    private BookMapper bookMapper;

    @Override
    public int insert(Book record) {
        return bookMapper.insert(record);
    }

    @Override
    public List all(Book book) {
        return bookMapper.all(book);
    }
}

控制层:
@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    private IBookService iBookService;

    @RequestMapping("/add")
    public ResponseData add(Book book){
        try {
            iBookService.insert(book);
            return new ResponseData<>(200,"新增成功!",null);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseData<>(500,"新增失败!",null);
        }
    }

    @RequestMapping("/all")
    public ResponseData> all(Book book){
        try {
            List all = iBookService.all(book);
            return new ResponseData<>(200,"查询成功!",all);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseData<>(500,"查询失败!",null);
        }
    }

}

@Data
@NoArgsConstructor
@AllArgsConstructor
class ResponseData {
    private int code;
    private String msg;
    private T data;
}

前端代码:

export default {
	//服务器
	'SERVER': 'http://localhost:8080/spboot', 
	'ADD': '/book/add', 
	'ALL': '/book/all', 
	//获得请求的完整地址,用于mockjs测试时使用
	'getFullPath': k => {
		return this.SERVER + this[k];
	}
}


页面:





转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1024292.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号