因为要学uniapp,需要后端服务器支持,自己又是写java的,所以就想用idea来搭建一个这个系统。看图操作吧。 

说说有两点要注意的,springboot项目要jdk8,且maven的版本不能超过3.6.2,当然有可能是我的idea版本过低。

1. 第一步springboot+mybatis+mysql 爬坑步骤详解。

第二步 , artifact这里输入项目名称,然后下一步

springboot+mybatis+mysql 爬坑步骤详解。

3.图中的勾选,然后下一步

springboot+mybatis+mysql 爬坑步骤详解。

4. 完成,点击finish 

springboot+mybatis+mysql 爬坑步骤详解。

完成后,,将properties删掉,新建一个application.yml文件,这个比application.prperties美观些

附上代码

server:
  port: 8089

spring:
  datasource:
    username: root
    password: root
    url: jdbc:mysql://localhost:3306/root?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
    driver-class-name: com.mysql.cj.jdbc.Driver

mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.example.demo2.entity

#showSql
logging:
  level:
    com:
      example:
        mapper : debug

 

4.新建 entity,controller ,service,impl,dao 等等附上文件

package com.example.demo2.entity;

/**
 * @Author:wjup
 * @Date: 2018/9/26 0026
 * @Time: 14:39
 */
public class User {
    private Integer cguid;

    public Integer getCguid() {
        return cguid;
    }

    public void setCguid(Integer cguid) {
        this.cguid = cguid;
    }


    @Override
    public String toString() {
        return "User{" +
                "cguid=" + cguid +
                '}';
    }
}
package com.example.demo2.controller;

import com.example.demo2.entity.User;
import com.example.demo2.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:wjup
 * @Date: 2018/9/26 0026
 * @Time: 14:42
 */

@RestController
@RequestMapping("/testBoot")

public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/getUser")
    public String GetUser(){

        return userService.Sel().toString();
    }
}
package com.example.demo2.service;

import com.example.demo2.entity.User;

/**
 * @Author:wjup
 * @Date: 2018/9/26 0026
 * @Time: 15:23
 */

public interface UserService {
     User Sel();
}

 

package com.example.demo2.service.impl;

import com.example.demo2.dao.UserMapper;
import com.example.demo2.entity.User;
import com.example.demo2.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author :lch
 * @Description :
 * @Date: Created in 13:20 2019/11/29
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired UserMapper userMapper;
    @Override
    public User Sel(){
        User sel = userMapper.Sel();
        return sel;
    }
}

 

package com.example.demo2.dao;

import com.example.demo2.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

/**
 * @Author:wjup
 * @Date: 2018/9/26 0026
 * @Time: 15:20
 */
@Repository
@Mapper
public interface UserMapper {

    User Sel();
}

 

<?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.example.demo2.dao.UserMapper">

    <resultMap id="BaseResultMap" type="com.example.demo2.entity.User">
        <result column="cguid" jdbcType="INTEGER" property="cguid" />
    </resultMap>

    <select id="Sel" resultType="com.example.demo2.entity.User">
        select * from aos_rms_user where cguid='1'
    </select>

</mapper>

 

 

最后是springboot 的入口

package com.example.demo2;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

@MapperScan("com.example.demo2.dao")
@SpringBootApplication
public class Demo2Application {

   public static void main(String[] args) {
      SpringApplication.run(Demo2Application.class, args);
   }

}

 

 

项目整体结构图

springboot+mybatis+mysql 爬坑步骤详解。

谢谢。 

相关文章:

  • 2021-11-19
  • 2021-07-20
  • 2021-06-09
  • 2022-12-23
  • 2022-01-31
  • 2021-07-30
  • 2021-12-04
猜你喜欢
  • 2021-12-03
  • 2022-12-23
  • 2021-05-23
  • 2021-06-21
  • 2021-08-05
  • 2022-02-07
  • 2021-07-16
相关资源
相似解决方案