ssmp

pojo:

package com.example.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class Book {
private Integer id;
private String type;
private String name;
private String description;
}
dao:
package com.example.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.domain.Book;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
@Mapper
@Repository
public interface BookDao extends BaseMapper<Book>{
}
service:
package com.example.service;

import com.example.domain.Book;
import org.springframework.stereotype.Service;

import java.util.List;
public interface BookService {
Boolean save(Book book);
Boolean update(Book book);
Boolean delete(Integer id);
Book getId(Integer id);
List<Book> getAll();
}
package com.example.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.example.domain.Book;
import org.springframework.stereotype.Service;

public interface IBookService extends IService<Book> {
Boolean save1(Book book);
}


package com.example.service.impl;

import com.example.dao.BookDao;
import com.example.domain.Book;
import com.example.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class BookServiceImpl2 implements BookService {
@Resource
private BookDao bookDao;
@Override
public Boolean save(Book book) {
return bookDao.insert(book)>0;
}

@Override
public Boolean update(Book book) {
return bookDao.updateById(book)>0;
}

@Override
public Boolean delete(Integer id) {
return bookDao.deleteById(id)>0;
}

@Override
public Book getId(Integer id) {
return bookDao.selectById(id);
}

@Override
public List<Book> getAll() {
return bookDao.selectList(null);
}
}
package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.dao.BookDao;
import com.example.domain.Book;
import com.example.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class BookServiceImpl extends ServiceImpl<BookDao, Book> implements IBookService {
@Resource
private BookDao bookDao;
@Override
public Boolean save1(Book book) {
return bookDao.insert(book)>0;
}
}

controller:
package com.example.controlle;

import com.example.dao.BookDao;
import com.example.domain.Book;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/books")
public class BookController {
@Resource
private BookDao bookDao;
@GetMapping
public List<Book> getAll(){
return bookDao.selectList(null);
}
// @PostMapping
// public Boolean sava(@RequestBody Book book){
// return bookDao.insert(book)>0;
// }
@PutMapping
public Boolean update(@RequestBody Book book){
return bookDao.updateById(book)>0;
}
@DeleteMapping("{id}")
public Boolean delete(@PathVariable Integer id){
return bookDao.deleteById(id)>0;
}
@GetMapping("{id}")
public Book getById(@PathVariable Integer id){
return bookDao.selectById(id);
}
}

server:
port: 8080
spring:
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis
username: root
password: root
mybatis-plus:
global-config:
db-config:
table-prefix: tbl_
id-type: auto
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl



package com.example.controlle.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.xml.ws.soap.Addressing;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class R {
private Boolean flag;
private Object data;
public R(Boolean flag){
this.flag=flag;
}
}


posted @ 2022-07-03 19:41  小松2739  阅读(73)  评论(0编辑  收藏  举报