IDEA 创建 Java 项目 SpringBoot 自动整合 SSM

IDEA 创建 Java 项目 SpringBoot 自动整合 SSM

一、环境准备

二、创建 Project

2.1、用 SpringBoot 向导创建工程

2.2、配置 Properties 文件

三、开发业务代码

3.1、创建实体类

java 复制代码
package com.yangjunbo.springbootssm01.pojo;

import lombok.Data;

/**
 * ClassName: User
 * Package: com.yangjunbo.springbootssm01.pojo
 * Description:
 *
 * @Author 杨钧博
 * @Create 2026/6/22 22:57
 * @Version 1.0
 */
@Data
public class User {
    private Integer id;
    private String username;
    private String password;
    private Integer age;
    private String gender;
    private String email;
}

3.2、创建 Mapper 接口和 Mapper 文件

java 复制代码
package com.yangjunbo.springbootssm01.mapper;

import com.yangjunbo.springbootssm01.pojo.User;
import org.apache.ibatis.annotations.Mapper;

/**
 * ClassName: UserMapper
 * Package: com.yangjunbo.springbootssm01.mapper
 * Description:
 *
 * @Author 杨钧博
 * @Create 2026/6/22 22:55
 * @Version 1.0
 */
@Mapper
public interface UserMapper {
    /**
     * 查询用户信息
     * @param id
     * @return
     */
    User getUser(String id);
}
xml 复制代码
<?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.yangjunbo.springbootssm01.mapper.UserMapper">

    <select id="getUser" resultType="com.yangjunbo.springbootssm01.pojo.User">
        select * from t_user where id = #{id}
    </select>
</mapper>

3.3、创建 Controller

java 复制代码
package com.yangjunbo.springbootssm01.controller;

import com.yangjunbo.springbootssm01.mapper.UserMapper;
import com.yangjunbo.springbootssm01.pojo.User;
import com.yangjunbo.springbootssm01.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassName: UserController
 * Package: com.yangjunbo.springbootssm01.controller
 * Description:
 *
 * @Author 杨钧博
 * @Create 2026/6/22 23:01
 * @Version 1.0
 */
@Controller
@ResponseBody
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/user/{id}")
    public User getUser(@PathVariable("id") String id){
        User user = userService.getUser(id);
        return user;
    }
}

3.4、创建 Service

java 复制代码
package com.yangjunbo.springbootssm01.service;

import com.yangjunbo.springbootssm01.pojo.User;

/**
 * ClassName: UserService
 * Package: com.yangjunbo.springbootssm01.service
 * Description:
 *
 * @Author 杨钧博
 * @Create 2026/6/22 23:13
 * @Version 1.0
 */
public interface UserService {
    /**
     * 获取用户信息
     * @param id
     * @return
     */
    User getUser(String id);
}
java 复制代码
package com.yangjunbo.springbootssm01.service.impl;

import com.yangjunbo.springbootssm01.mapper.UserMapper;
import com.yangjunbo.springbootssm01.pojo.User;
import com.yangjunbo.springbootssm01.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * ClassName: UserServiceImpl
 * Package: com.yangjunbo.springbootssm01.service.impl
 * Description:
 *
 * @Author 杨钧博
 * @Create 2026/6/22 23:13
 * @Version 1.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    /**
     * 获取用户信息
     * @param id
     * @return
     */
    @Override
    public User getUser(String id) {
        User user = userMapper.getUser(id);
        return user;
    }
}

四、部署测试