将SSM工程用springboot框架来搭建

实现一个简单的从网页获取数据库成员信息的操作。

大致效果如下:
页面数据库数据

结构图:
工程框架
创建maven工程,在spring-all模块的pom.xml中加载spring-boot-starter-parent.后面的工程只需要继承这个spring-all工程作为子工程即可。

<parent>
    <artifactId>spring-boot-starter-parent</artifactId>
    <groupId>org.springframework.boot</groupId>
    <version>2.2.5.RELEASE</version>
</parent>

在spring-boot-user模块的pom中添加工程需要的jar。包括jdbc,starter-web,mybatis

<dependencies>
<!--starter-web-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--持久层-->
<!--jdbc-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--mysql-->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.47</version>
    <scope>runtime</scope>
</dependency>
<!--mybatis-->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.0</version>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
</dependency>
</dependencies>

在application.properties中。完成jdbc的datasource配置和mybatis的配置文件读取路径。

server.port=8080
#server.servlet.context-path=/spring-boot-user
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/zb_database
spring.datasource.username=root
spring.datasource.password=root

mybatis.mapper-locations=classpath:mappers/*.xml

在-resources/mappers/userMapper.xml中,完成mybatis操作数据库的语句编写。

`

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zb.mapper.userMaper">
    <update id="addPoints">
        update t_user set points = points + #{points} where user_id = #{user_id};
    </update>
    <select id="queryUserById" resultType="com.zb.domain.User">
        select * from t_user where user_id = #{user_id};
    </select>
</mapper>

调用mybatis的操作类是userMaper.java,此类的方法对应的功能实现,就是userMaper.xml

public interface userMaper {
    void addPoint(@Param("user_id") String user_id, @Param("points") int points);
    User queryUserById(@Param("user_id") String user_id);
}

MyController.java实现servlet的功能,连接url请求,返回数据库中的数据给前端。

@RestController
public class MyController {

    @Autowired
    private iuserService iuser = null;
    
    @RequestMapping("/point.action")
    public String point(String userId) {
        try{
            int ipoint = iuser.getUserPoint(userId);
            return "{\"points\":\""+ipoint+"\"}";
        }catch (Exception e) {
            e.printStackTrace();
            return "{\"proints\":\"-1\"}";
        }
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于springboot_ssm的个人博客源代码: 个人博客系统主要用于发表个人博客,记录个人生活日常,学习心得,技术分享等,供他人浏览,查阅,评论等。本系统结构如下: (1)博主端: 登录模块:登入后台管理系统:首先进入登录页面,需要输入账号和密码。它会使用Shiro进行安全管理,对前台输入的密 码进行加密运算,然后与数据库中的进行比较。成功后才能登入后台系统。 博客管理模块: 博客管理功能分为写博客和博客信息管理。写博客是博主用来发表编写博客的,需要博客标题,然后选择博 客类型,最后将博客内容填入百度的富文本编辑器中,点击发布博客按钮即可发布博客。 博客类别管理模块:博主类别管理系统可以添加,修改和删除博客类型名称和排序序号。将会显示到首页的按日志类别区域。 游客可 以从这里查找相关的感兴趣的博客内容 评论信息管理模块:评论管理功能分为评论审核和评论信息管理两部分。评论审核是当有游客或自己发表了评论之后,博主需 要在后台管理系统中审核评论。若想将此评论显示在页面上则点击审核通过,否则点击审核不通过。 个人信息管理模块:修改博主的个人信息,可以修改昵称,个性签名,可以添加个人头像,修改个人简介; 系统管理功能模块:友情链接管理,修改密码,刷新系统缓存和安全退出,友情链接管理可以添加,修改,删除友情链接网址 (2)游客端: 查询博客: 查询具体哪一篇博客 查看博客内容: 查看博客内容 查看博主个人信息:查看博主个人简介 发表评论: 可以评论具体某篇博客 友情链接: 查看友情链接

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值