因爲要學uniapp,需要後端服務器支持,自己又是寫java的,所以就想用idea來搭建一個這個系統。看圖操作吧。
說說有兩點要注意的,springboot項目要jdk8,且maven的版本不能超過3.6.2,當然有可能是我的idea版本過低。
1. 第一步
第二步 , artifact這裏輸入項目名稱,然後下一步
3.圖中的勾選,然後下一步
4. 完成,點擊finish
完成後,,將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);
}
}
項目整體結構圖
謝謝。