Entity,需要注明主键
package com.iwhalecloud.bassc.ncdp.web.test.entity;
import com.iwhalecloud.ids.core.common.pojo.BasePO;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;
public class BasiccBfmMenu extends BasePO implements Serializable {
private static final long serialVersionUID = -80830249105561636L;
@Id
private Long menuId;
private String iconUrl;
private String state;
private Date stateDate;
private String menuType;
public Long getMenuId() {
return menuId;
}
public void setMenuId(Long menuId) {
this.menuId = menuId;
}
public String getIconUrl() {
return iconUrl;
}
public void setIconUrl(String iconUrl) {
this.iconUrl = iconUrl;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Date getStateDate() {
return stateDate;
}
public void setStateDate(Date stateDate) {
this.stateDate = stateDate;
}
public String getMenuType() {
return menuType;
}
public void setMenuType(String menuType) {
this.menuType = menuType;
}
}
Mapper层
CommonDao
package com.iwhalecloud.bassc.ncdp.web.test.dao;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.Mapper;
public interface CommonDao <T> extends Mapper<T>, InsertListMapper<T> {
}
BasiccBfmMenuDao
package com.iwhalecloud.bassc.ncdp.web.test.dao;
import com.iwhalecloud.bassc.ncdp.web.test.entity.BasiccBfmMenu;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface BasiccBfmMenuDao extends CommonDao<BasiccBfmMenu> {
}
Service层
CommonService
package com.iwhalecloud.bassc.ncdp.web.test.service;
public interface CommonService<T> {
public T queryById(Long menuId);
public T insert(T t);
public T update(T t) ;
public boolean deleteById(Long menuId) ;
}
BasiccBfmMenuService
package com.iwhalecloud.bassc.ncdp.web.test.service;
public interface BasiccBfmMenuService {
}
CommonServiceImpl
package com.iwhalecloud.bassc.ncdp.web.test.service.impl;
import com.iwhalecloud.bassc.ncdp.web.test.dao.CommonDao;
import com.iwhalecloud.bassc.ncdp.web.test.service.CommonService;
import com.iwhalecloud.ids.core.common.pojo.BasePO;
import org.springframework.beans.factory.annotation.Autowired;
public class CommonServiceImpl<T extends BasePO,M extends CommonDao<T>> implements CommonService<T> {
@Autowired
M m;
@Override
public T queryById(Long id) {
return m.selectByPrimaryKey(id);
}
@Override
public T insert(T t) {
m.insert(t);
return t;
}
@Override
public T update(T t) {
m.updateByPrimaryKeySelective(t);
return t;
}
@Override
public boolean deleteById(Long id) {
return m.deleteByPrimaryKey(id) > 0;
}
}
BasiccBfmMenuServiceImpl
package com.iwhalecloud.bassc.ncdp.web.test.service.impl;
import com.iwhalecloud.bassc.ncdp.web.test.dao.BasiccBfmMenuDao;
import com.iwhalecloud.bassc.ncdp.web.test.entity.BasiccBfmMenu;
import com.iwhalecloud.bassc.ncdp.web.test.service.BasiccBfmMenuService;
import org.springframework.stereotype.Service;
@Service("basiccBfmMenuService")
public class BasiccBfmMenuServiceImpl extends CommonServiceImpl<BasiccBfmMenu, BasiccBfmMenuDao> implements BasiccBfmMenuService {
}
Controller层
CommonController
package com.iwhalecloud.bassc.ncdp.web.test.controller;
import com.iwhalecloud.bassc.ncdp.web.test.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
public class CommonController <T ,S extends CommonService<T>>{
@Autowired
S service;
@GetMapping("{id}")
public ResponseEntity<T> queryById(@PathVariable("id") Long id) {
return ResponseEntity.ok((T) service.queryById(id));
}
@PostMapping
public ResponseEntity<T> add(T t) {
return ResponseEntity.ok((T) service.insert(t));
}
@PutMapping
public ResponseEntity<T> edit(T t) {
return ResponseEntity.ok((T) service.update(t));
}
@DeleteMapping
public ResponseEntity<Boolean> deleteById(Long id) {
return ResponseEntity.ok(service.deleteById(id));
}
}
BasiccBfmMenuController
package com.iwhalecloud.bassc.ncdp.web.test.controller;
import com.iwhalecloud.bassc.ncdp.web.test.entity.BasiccBfmMenu;
import com.iwhalecloud.bassc.ncdp.web.test.service.impl.BasiccBfmMenuServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/basiccBfmMenu")
public class BasiccBfmMenuController extends CommonController<BasiccBfmMenu, BasiccBfmMenuServiceImpl>{
}
总结最后实现的效果
- 直接看controller层,直接生成了4个接口
localhost:8080/basiccBfmMenu/10086
localhost:8080/basiccBfmMenu
localhost:8080/basiccBfmMenu
localhost:8080/basiccBfmMenu?id=10087