🍊作者:計算機編程-吉哥
🍊簡介:專業從事JavaWeb程序開發,微信小程序開發,定制化項目、 源碼、代碼講解、文檔撰寫、ppt制作。做自己喜歡的事,生活就是快樂的。
🍊心愿:點贊 👍 收藏 ?評論 📝
🍅 文末獲取源碼聯系👇🏻 精彩專欄推薦訂閱 👇🏻 不然下次找不到喲~
Java畢業設計項目~熱門選題推薦《1000套》
目錄
1.技術選型
2.數據庫表結構
3.開發工具
4.功能
4.1【角色】
4.2【前臺功能模塊】
4.3【后臺功能模塊】
5.項目演示截圖
5.1 首頁
5.2 交流論壇
5.3 公告信息
5.4 農產品
5.5 個人中心
5.6 農產品管理
5.7 農產品訂單管理
5.8 用戶管理
6.數據庫文件設計
7.核心代碼?
7.1 農產品Controller
7.2 農產品ServiceImpl
7.3 農產品Service
7.4 農產品DAO
8.參考文檔
1.技術選型
springboot、mybatisplus、vue、elementui、html、css、js、mysql、jdk1.8
2.數據庫表結構
15張?
3.開發工具
idea、navicat
4.功能
4.1【角色】
管理員、用戶、商家
4.2【前臺功能模塊】
- 登錄注冊
- 首頁
- 交流論壇
- 公告信息
- 農產品
- 商家
- 個人中心
- 購物車
4.3【后臺功能模塊】
- 登錄
- 首頁
- 個人中心
- 管理員管理
- 商家管理
- 用戶管理
- 農產品管理(農產品、農產品評價、農產品訂單)
- 交流論壇管理
- 公告信息管理
- 基礎數據管理
- 輪播圖信息
5.項目演示截圖
5.1 首頁
5.2 交流論壇
?
5.3 公告信息
?
5.4 農產品
?
5.5 個人中心
?
5.6 農產品管理
?
5.7 農產品訂單管理
?
5.8 用戶管理
?
6.數據庫文件設計
CREATE TABLE `address` (`id` int(20) NOT NULL AUTO_INCREMENT COMMENT '主鍵 ',`yonghu_id` int(20) NOT NULL COMMENT '創建用戶',`address_name` varchar(200) NOT NULL COMMENT '收貨人 ',`address_phone` varchar(200) NOT NULL COMMENT '電話 ',`address_dizhi` varchar(200) NOT NULL COMMENT '地址 ',`isdefault_types` int(11) NOT NULL COMMENT '是否默認地址 ',`insert_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加時間',`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改時間',`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '創建時間 show3',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='收貨地址';CREATE TABLE `cart` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主鍵',`yonghu_id` int(11) DEFAULT NULL COMMENT '所屬用戶',`nongchanpin_id` int(11) DEFAULT NULL COMMENT '農產品',`buy_number` int(11) DEFAULT NULL COMMENT '購買數量',`create_time` timestamp NULL DEFAULT NULL COMMENT '添加時間',`update_time` timestamp NULL DEFAULT NULL COMMENT '更新時間',`insert_time` timestamp NULL DEFAULT NULL COMMENT '創建時間',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='購物車';CREATE TABLE `config` (`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主鍵',`name` varchar(100) NOT NULL COMMENT '配置參數名稱',`value` varchar(100) DEFAULT NULL COMMENT '配置參數值',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='配置文件';CREATE TABLE `dictionary` (`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主鍵',`dic_code` varchar(200) DEFAULT NULL COMMENT '字段',`dic_name` varchar(200) DEFAULT NULL COMMENT '字段名',`code_index` int(11) DEFAULT NULL COMMENT '編碼',`index_name` varchar(200) DEFAULT NULL COMMENT '編碼名字 Search111 ',`super_id` int(11) DEFAULT NULL COMMENT '父字段id',`beizhu` varchar(200) DEFAULT NULL COMMENT '備注',`create_time` timestamp NULL DEFAULT NULL COMMENT '創建時間',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 COMMENT='字典';CREATE TABLE `forum` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主鍵',`forum_name` varchar(200) DEFAULT NULL COMMENT '帖子標題 Search111 ',`yonghu_id` int(11) DEFAULT NULL COMMENT '用戶',`shangjia_id` int(11) DEFAULT NULL COMMENT '商家',`users_id` int(11) DEFAULT NULL COMMENT '管理員',`forum_content` longtext COMMENT '發布內容',`super_ids` int(11) DEFAULT NULL COMMENT '父id',`forum_state_types` int(11) DEFAULT NULL COMMENT '帖子狀態',`insert_time` timestamp NULL DEFAULT NULL COMMENT '發帖時間',`update_time` timestamp NULL DEFAULT NULL COMMENT '修改時間',`create_time` timestamp NULL DEFAULT NULL COMMENT '創建時間 show2',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 COMMENT='交流論壇';CREATE TABLE `gonggao` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主鍵 ',`gonggao_name` varchar(200) DEFAULT NULL COMMENT '公告名稱 Search111 ',`gonggao_photo` varchar(200) DEFAULT NULL COMMENT '公告圖片 ',`gonggao_types` int(11) NOT NULL COMMENT '公告類型 Search111 ',`insert_time` timestamp NULL DEFAULT NULL COMMENT '發布時間',`gonggao_content` longtext COMMENT '公告詳情 ',`create_time` timestamp NULL DEFAULT NULL COMMENT '創建時間 show1 show2 nameShow',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='公告信息';CREATE TABLE `nongchanpin_collection` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主鍵',`nongchanpin_id` int(11) DEFAULT NULL COMMENT '農產品',`yonghu_id` int(11) DEFAULT NULL COMMENT '用戶',`nongchanpin_collection_types` int(11) DEFAULT NULL COMMENT '類型',`insert_time` timestamp NULL DEFAULT NULL COMMENT '收藏時間',`create_time` timestamp NULL DEFAULT NULL COMMENT '創建時間 show3 photoShow',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='農產品收藏';CREATE TABLE `nongchanpin_commentback` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主鍵',`nongchanpin_id` int(11) DEFAULT NULL COMMENT '農產品',`yonghu_id` int(11) DEFAULT NULL COMMENT '用戶',`nongchanpin_commentback_text` text COMMENT '評價內容',`insert_time` timestamp NULL DEFAULT NULL COMMENT '評價時間',`reply_text` text COMMENT '回復內容',`update_time` timestamp NULL DEFAULT NULL COMMENT '回復時間',`create_time` timestamp NULL DEFAULT NULL COMMENT '創建時間',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8 COMMENT='農產品評價';CREATE TABLE `shangjia` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主鍵 ',`username` varchar(200) DEFAULT NULL COMMENT '賬戶 ',`password` varchar(200) DEFAULT NULL COMMENT '密碼 ',`shangjia_name` varchar(200) DEFAULT NULL COMMENT '商家名稱 Search111 ',`shangjia_phone` varchar(200) DEFAULT NULL COMMENT '聯系方式',`shangjia_email` varchar(200) DEFAULT NULL COMMENT '郵箱',`shangjia_photo` varchar(200) DEFAULT NULL COMMENT '營業執照展示 ',`shangjia_xingji_types` int(11) DEFAULT NULL COMMENT '商家信用類型',`new_money` decimal(10,2) DEFAULT NULL COMMENT '現有余額',`shangjia_content` longtext COMMENT '商家介紹 ',`shangjia_delete` int(11) DEFAULT NULL COMMENT '邏輯刪除',`create_time` timestamp NULL DEFAULT NULL COMMENT '創建時間 show1 show2 photoShow ',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='商家';CREATE TABLE `token` (`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主鍵',`userid` bigint(20) NOT NULL COMMENT '兒童id',`username` varchar(100) NOT NULL COMMENT '兒童名',`tablename` varchar(100) DEFAULT NULL COMMENT '表名',`role` varchar(100) DEFAULT NULL COMMENT '角色',`token` varchar(200) NOT NULL COMMENT '密碼',`addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '新增時間',`expiratedtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '過期時間',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='token表';CREATE TABLE `users` (`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主鍵',`username` varchar(100) NOT NULL COMMENT '兒童名',`password` varchar(100) NOT NULL COMMENT '密碼',`role` varchar(100) DEFAULT '管理員' COMMENT '角色',`addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '新增時間',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='管理員';CREATE TABLE `yonghu` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主鍵',`username` varchar(200) DEFAULT NULL COMMENT '賬戶',`password` varchar(200) DEFAULT NULL COMMENT '密碼',`yonghu_uuid_number` varchar(200) DEFAULT NULL COMMENT '用戶編號 Search111 ',`yonghu_name` varchar(200) DEFAULT NULL COMMENT '用戶姓名 Search111 ',`yonghu_phone` varchar(200) DEFAULT NULL COMMENT '用戶手機號',`yonghu_id_number` varchar(200) DEFAULT NULL COMMENT '用戶身份證號',`yonghu_photo` varchar(200) DEFAULT NULL COMMENT '用戶頭像',`sex_types` int(11) DEFAULT NULL COMMENT '性別',`yonghu_email` varchar(200) DEFAULT NULL COMMENT '用戶郵箱',`new_money` decimal(10,2) DEFAULT NULL COMMENT '余額 ',`create_time` timestamp NULL DEFAULT NULL COMMENT '創建時間',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='用戶';
7.核心代碼?
7.1 農產品Controller
package com.controller;/*** 農產品* 后端接口* @author 計算機編程-吉哥* @email
*/
@RestController
@Controller
@RequestMapping("/nongchanpin")
public class NongchanpinController {private static final Logger logger = LoggerFactory.getLogger(NongchanpinController.class);private static final String TABLE_NAME = "nongchanpin";@Autowiredprivate NongchanpinService nongchanpinService;@Autowiredprivate TokenService tokenService;@Autowiredprivate AddressService addressService;//收貨地址@Autowiredprivate CartService cartService;//購物車@Autowiredprivate DictionaryService dictionaryService;//字典@Autowiredprivate ForumService forumService;//交流論壇@Autowiredprivate GonggaoService gonggaoService;//公告信息@Autowiredprivate NongchanpinCollectionService nongchanpinCollectionService;//農產品收藏@Autowiredprivate NongchanpinCommentbackService nongchanpinCommentbackService;//農產品評價@Autowiredprivate NongchanpinOrderService nongchanpinOrderService;//農產品訂單@Autowiredprivate ShangjiaService shangjiaService;//商家@Autowiredprivate YonghuService yonghuService;//用戶@Autowiredprivate UsersService usersService;//管理員/*** 后端列表*/@RequestMapping("/page")public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));String role = String.valueOf(request.getSession().getAttribute("role"));if(false)return R.error(511,"永不會進入");else if("用戶".equals(role))params.put("yonghuId",request.getSession().getAttribute("userId"));else if("商家".equals(role))params.put("shangjiaId",request.getSession().getAttribute("userId"));params.put("nongchanpinDeleteStart",1);params.put("nongchanpinDeleteEnd",1);CommonUtil.checkMap(params);PageUtils page = nongchanpinService.queryPage(params);//字典表數據轉換List<NongchanpinView> list =(List<NongchanpinView>)page.getList();for(NongchanpinView c:list){//修改對應字典表字段dictionaryService.dictionaryConvert(c, request);}return R.ok().put("data", page);}/*** 后端詳情*/@RequestMapping("/info/{id}")public R info(@PathVariable("id") Long id, HttpServletRequest request){logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);NongchanpinEntity nongchanpin = nongchanpinService.selectById(id);if(nongchanpin !=null){//entity轉viewNongchanpinView view = new NongchanpinView();BeanUtils.copyProperties( nongchanpin , view );//把實體數據重構到view中//級聯表 商家//級聯表ShangjiaEntity shangjia = shangjiaService.selectById(nongchanpin.getShangjiaId());if(shangjia != null){BeanUtils.copyProperties( shangjia , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "shangjiaId"});//把級聯的數據添加到view中,并排除id和創建時間字段,當前表的級聯注冊表view.setShangjiaId(shangjia.getId());}//修改對應字典表字段dictionaryService.dictionaryConvert(view, request);return R.ok().put("data", view);}else {return R.error(511,"查不到數據");}}/*** 后端保存*/@RequestMapping("/save")public R save(@RequestBody NongchanpinEntity nongchanpin, HttpServletRequest request){logger.debug("save方法:,,Controller:{},,nongchanpin:{}",this.getClass().getName(),nongchanpin.toString());String role = String.valueOf(request.getSession().getAttribute("role"));if(false)return R.error(511,"永遠不會進入");else if("商家".equals(role))nongchanpin.setShangjiaId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));Wrapper<NongchanpinEntity> queryWrapper = new EntityWrapper<NongchanpinEntity>().eq("shangjia_id", nongchanpin.getShangjiaId()).eq("nongchanpin_name", nongchanpin.getNongchanpinName()).eq("nongchanpin_types", nongchanpin.getNongchanpinTypes()).eq("nongchanpin_kucun_number", nongchanpin.getNongchanpinKucunNumber()).eq("shangxia_types", nongchanpin.getShangxiaTypes()).eq("nongchanpin_delete", 1);logger.info("sql語句:"+queryWrapper.getSqlSegment());NongchanpinEntity nongchanpinEntity = nongchanpinService.selectOne(queryWrapper);if(nongchanpinEntity==null){nongchanpin.setNongchanpinClicknum(1);nongchanpin.setShangxiaTypes(1);nongchanpin.setNongchanpinDelete(1);nongchanpin.setCreateTime(new Date());nongchanpinService.insert(nongchanpin);return R.ok();}else {return R.error(511,"表中有相同數據");}}/*** 后端修改*/@RequestMapping("/update")public R update(@RequestBody NongchanpinEntity nongchanpin, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {logger.debug("update方法:,,Controller:{},,nongchanpin:{}",this.getClass().getName(),nongchanpin.toString());NongchanpinEntity oldNongchanpinEntity = nongchanpinService.selectById(nongchanpin.getId());//查詢原先數據String role = String.valueOf(request.getSession().getAttribute("role"));
// if(false)
// return R.error(511,"永遠不會進入");
// else if("商家".equals(role))
// nongchanpin.setShangjiaId(Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId"))));if("".equals(nongchanpin.getNongchanpinPhoto()) || "null".equals(nongchanpin.getNongchanpinPhoto())){nongchanpin.setNongchanpinPhoto(null);}if("".equals(nongchanpin.getNongchanpinContent()) || "null".equals(nongchanpin.getNongchanpinContent())){nongchanpin.setNongchanpinContent(null);}nongchanpinService.updateById(nongchanpin);//根據id更新return R.ok();}/*** 刪除*/@RequestMapping("/delete")public R delete(@RequestBody Integer[] ids, HttpServletRequest request){logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());List<NongchanpinEntity> oldNongchanpinList =nongchanpinService.selectBatchIds(Arrays.asList(ids));//要刪除的數據ArrayList<NongchanpinEntity> list = new ArrayList<>();for(Integer id:ids){NongchanpinEntity nongchanpinEntity = new NongchanpinEntity();nongchanpinEntity.setId(id);nongchanpinEntity.setNongchanpinDelete(2);list.add(nongchanpinEntity);}if(list != null && list.size() >0){nongchanpinService.updateBatchById(list);}return R.ok();}/*** 批量上傳*/@RequestMapping("/batchInsert")public R save( String fileName, HttpServletRequest request){logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//.eq("time", new SimpleDateFormat("yyyy-MM-dd").format(new Date()))try {List<NongchanpinEntity> nongchanpinList = new ArrayList<>();//上傳的東西Map<String, List<String>> seachFields= new HashMap<>();//要查詢的字段Date date = new Date();int lastIndexOf = fileName.lastIndexOf(".");if(lastIndexOf == -1){return R.error(511,"該文件沒有后綴");}else{String suffix = fileName.substring(lastIndexOf);if(!".xls".equals(suffix)){return R.error(511,"只支持后綴為xls的excel文件");}else{URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//獲取文件路徑File file = new File(resource.getFile());if(!file.exists()){return R.error(511,"找不到上傳文件,請聯系管理員");}else{List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//讀取xls文件dataList.remove(0);//刪除第一行,因為第一行是提示for(List<String> data:dataList){//循環NongchanpinEntity nongchanpinEntity = new NongchanpinEntity();//把要查詢是否重復的字段放入map中}//查詢是否重復nongchanpinService.insertBatch(nongchanpinList);return R.ok();}}}}catch (Exception e){e.printStackTrace();return R.error(511,"批量插入數據異常,請聯系管理員");}}/*** 個性推薦*/@IgnoreAuth@RequestMapping("/gexingtuijian")public R gexingtuijian(@RequestParam Map<String, Object> params, HttpServletRequest request){logger.debug("gexingtuijian方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));CommonUtil.checkMap(params);List<NongchanpinView> returnNongchanpinViewList = new ArrayList<>();//查詢訂單Map<String, Object> params1 = new HashMap<>(params);params1.put("sort","id");params1.put("yonghuId",request.getSession().getAttribute("userId"));params1.put("shangxiaTypes",1);params1.put("nongchanpinYesnoTypes",2);PageUtils pageUtils = nongchanpinOrderService.queryPage(params1);List<NongchanpinOrderView> orderViewsList =(List<NongchanpinOrderView>)pageUtils.getList();Map<Integer,Integer> typeMap=new HashMap<>();//購買的類型listfor(NongchanpinOrderView orderView:orderViewsList){Integer nongchanpinTypes = orderView.getNongchanpinTypes();if(typeMap.containsKey(nongchanpinTypes)){typeMap.put(nongchanpinTypes,typeMap.get(nongchanpinTypes)+1);}else{typeMap.put(nongchanpinTypes,1);}}List<Integer> typeList = new ArrayList<>();//排序后的有序的類型 按最多到最少typeMap.entrySet().stream().sorted((o1, o2) -> o2.getValue() - o1.getValue()).forEach(e -> typeList.add(e.getKey()));//排序Integer limit = Integer.valueOf(String.valueOf(params.get("limit")));for(Integer type:typeList){Map<String, Object> params2 = new HashMap<>(params);params2.put("nongchanpinTypes",type);params2.put("shangxiaTypes",1);params2.put("nongchanpinYesnoTypes",2);PageUtils pageUtils1 = nongchanpinService.queryPage(params2);List<NongchanpinView> nongchanpinViewList =(List<NongchanpinView>)pageUtils1.getList();returnNongchanpinViewList.addAll(nongchanpinViewList);if(returnNongchanpinViewList.size()>= limit) break;//返回的推薦數量大于要的數量 跳出循環}params.put("shangxiaTypes",1);params.put("nongchanpinYesnoTypes",2);//正常查詢出來商品,用于補全推薦缺少的數據PageUtils page = nongchanpinService.queryPage(params);if(returnNongchanpinViewList.size()<limit){//返回數量還是小于要求數量int toAddNum = limit - returnNongchanpinViewList.size();//要添加的數量List<NongchanpinView> nongchanpinViewList =(List<NongchanpinView>)page.getList();for(NongchanpinView nongchanpinView:nongchanpinViewList){Boolean addFlag = true;for(NongchanpinView returnNongchanpinView:returnNongchanpinViewList){if(returnNongchanpinView.getId().intValue() ==nongchanpinView.getId().intValue()) addFlag=false;//返回的數據中已存在此商品}if(addFlag){toAddNum=toAddNum-1;returnNongchanpinViewList.add(nongchanpinView);if(toAddNum==0) break;//夠數量了}}}else {returnNongchanpinViewList = returnNongchanpinViewList.subList(0, limit);}for(NongchanpinView c:returnNongchanpinViewList)dictionaryService.dictionaryConvert(c, request);page.setList(returnNongchanpinViewList);return R.ok().put("data", page);}/*** 前端列表*/@IgnoreAuth@RequestMapping("/list")public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));CommonUtil.checkMap(params);PageUtils page = nongchanpinService.queryPage(params);//字典表數據轉換List<NongchanpinView> list =(List<NongchanpinView>)page.getList();for(NongchanpinView c:list)dictionaryService.dictionaryConvert(c, request); //修改對應字典表字段return R.ok().put("data", page);}/*** 前端詳情*/@RequestMapping("/detail/{id}")public R detail(@PathVariable("id") Integer id, HttpServletRequest request){logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);NongchanpinEntity nongchanpin = nongchanpinService.selectById(id);if(nongchanpin !=null){//點擊數量加1nongchanpin.setNongchanpinClicknum(nongchanpin.getNongchanpinClicknum()+1);nongchanpinService.updateById(nongchanpin);//entity轉viewNongchanpinView view = new NongchanpinView();BeanUtils.copyProperties( nongchanpin , view );//把實體數據重構到view中//級聯表ShangjiaEntity shangjia = shangjiaService.selectById(nongchanpin.getShangjiaId());if(shangjia != null){BeanUtils.copyProperties( shangjia , view ,new String[]{ "id", "createTime", "insertTime", "updateTime", "username", "password", "newMoney", "shangjiaId"});//把級聯的數據添加到view中,并排除id和創建時間字段view.setShangjiaId(shangjia.getId());}//修改對應字典表字段dictionaryService.dictionaryConvert(view, request);return R.ok().put("data", view);}else {return R.error(511,"查不到數據");}}/*** 前端保存*/@RequestMapping("/add")public R add(@RequestBody NongchanpinEntity nongchanpin, HttpServletRequest request){logger.debug("add方法:,,Controller:{},,nongchanpin:{}",this.getClass().getName(),nongchanpin.toString());Wrapper<NongchanpinEntity> queryWrapper = new EntityWrapper<NongchanpinEntity>().eq("shangjia_id", nongchanpin.getShangjiaId()).eq("nongchanpin_name", nongchanpin.getNongchanpinName()).eq("nongchanpin_types", nongchanpin.getNongchanpinTypes()).eq("nongchanpin_kucun_number", nongchanpin.getNongchanpinKucunNumber()).eq("nongchanpin_clicknum", nongchanpin.getNongchanpinClicknum()).eq("shangxia_types", nongchanpin.getShangxiaTypes()).eq("nongchanpin_delete", nongchanpin.getNongchanpinDelete())
// .notIn("nongchanpin_types", new Integer[]{102});logger.info("sql語句:"+queryWrapper.getSqlSegment());NongchanpinEntity nongchanpinEntity = nongchanpinService.selectOne(queryWrapper);if(nongchanpinEntity==null){nongchanpin.setNongchanpinClicknum(1);nongchanpin.setNongchanpinDelete(1);nongchanpin.setCreateTime(new Date());nongchanpinService.insert(nongchanpin);return R.ok();}else {return R.error(511,"表中有相同數據");}}}
7.2 農產品ServiceImpl
package com.service.impl;/*** 農產品 服務實現類*/
@Service("nongchanpinService")
@Transactional
public class NongchanpinServiceImpl extends ServiceImpl<NongchanpinDao, NongchanpinEntity> implements NongchanpinService {@Overridepublic PageUtils queryPage(Map<String,Object> params) {Page<NongchanpinView> page =new Query<NongchanpinView>(params).getPage();page.setRecords(baseMapper.selectListView(page,params));return new PageUtils(page);}}
7.3 農產品Service
package com.service;import com.baomidou.mybatisplus.service.IService;
import com.utils.PageUtils;
import com.entity.NongchanpinEntity;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.lang.Nullable;
import java.util.List;/*** 農產品 服務類*/
public interface NongchanpinService extends IService<NongchanpinEntity> {/*** @param params 查詢參數* @return 帶分頁的查詢出來的數據*/PageUtils queryPage(Map<String, Object> params);}
7.4 農產品DAO
package com.dao;import com.entity.NongchanpinEntity;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;import org.apache.ibatis.annotations.Param;
import com.entity.view.NongchanpinView;/*** 農產品 Dao 接口** @author */
public interface NongchanpinDao extends BaseMapper<NongchanpinEntity> {List<NongchanpinView> selectListView(Pagination page,@Param("params")Map<String,Object> params);}
8.參考文檔
?
你可能還有感興趣的項目👇🏻👇🏻👇🏻
更多項目推薦:計算機畢業設計項目
如果大家有任何疑慮,請在下方咨詢或評論