首页 > 编程语言 > 详细

SpringMVC+Spring+mybatis 项目实践

时间:2020-06-27 12:28:41      阅读:73      评论:0      收藏:0      [点我收藏+]

创建一个SpringBoot项目

这里使用的是Spring Initializer: https://start.spring.io/

技术分享图片

 

 

点击GENERATE就生成项目了下载后用IDEA打开

技术分享图片

 

 

 

导入上一个项目的代码

数据库设计

技术分享图片

 

 技术分享图片

 

 

进行配置数据库和MVC渲染

 

 

 

技术分享图片

 

 

 

 

 

修改pom.xml文件,添加依赖

技术分享图片

 

 

 修改新闻类

技术分享图片

 

添加一个mybatis的mapper库,进行增删查改

技术分享图片

 

 

 

 

 

修改 NewsService

package com.example.demo.Service;
import com.example.demo.Entity.News;
import com.example.demo.Mapper.NewsMapper;
import org.apache.catalina.mapper.Mapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class NewsService {

@Autowired
NewsMapper newsMapper;

public boolean AddNews(News news){

newsMapper.insert(news);

return true;
}

public boolean DeleteNews(int idnews){

newsMapper.deleteByPrimaryKey(idnews);

return true;
}

public boolean UpdateNews(News news) {

newsMapper.updateByPrimaryKey(news);


return true;
}

public List<News> QueryNews() throws SQLException {

return newsMapper.selectAll();
}

public News GetNews(int idnews) throws SQLException {
String sql="Select * from news where idnews=‘"+Integer.toString(idnews)+"‘";
return news; }
return newsMapper.selectByPrimaryKey(idnews);
}

 

 界面展示

登录界面

技术分享图片

 

 

 新闻列表

技术分享图片

 

 

 查看新闻

技术分享图片

 

 

 编辑新闻

技术分享图片

 码云地址:

https://gitee.com/TANGYILI/ssm_project_practice.git

SpringMVC+Spring+mybatis 项目实践

原文:https://www.cnblogs.com/TANGYILI/p/13197822.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!