导语:不会用eclipse创建springboot项目?也不会用IDEA创建springboot项目?没关系,会创建文件夹和文本文档就行。
1、springboot项目目录结构
注:矩形为文件夹,椭圆为文件。
2、pom.xml
4.0.0
com.example
demo
1.0
jar
demo
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
1.5.1.RELEASE
UTF-8
1.8
1.2.0
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.mybatis.spring.boot
mybatis-spring-boot-starter
${mybatis-spring-boot}
org.springframework.boot
spring-boot-starter-logging
org.springframework.boot
spring-boot-starter-aop
mysql
mysql-connector-java
c3p0
c3p0
0.9.1.2
org.springframework.boot
spring-boot-starter-jdbc
junit
junit
test
org.springframework.boot
spring-boot-devtools
true
commons-lang
commons-lang
2.6
com.alibaba
fastjson
1.2.31
commons-net
commons-net
3.1
org.scala-lang
scala-library
2.11.0
org.apache.poi
poi
RELEASE
org.apache.poi
poi-ooxml
RELEASE
src/main/java
**/*.properties
**/*.xml
false
src/main/resources
**/*.properties
**/*.xml
false
org.springframework.boot
spring-boot-maven-plugin
true
3、application.properties文件
spring.profiles.active=dev
## Mybatis
mybatis.mapperLocations=classpath\:mapper/*.xml
mybatis.configuration.call-setters-on-nulls=true
4、application-dev.properties文件
##端口配置
server.port =8095
## 数据源配置
spring.datasource.url=jdbc:mysql://localhost/test?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driverClassName=com.mysql.jdbc.Driver
5、Application.java文件
package com.example;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* Spring Boot 应用启动类
*
*/
// Spring Boot 应用的标识
@SpringBootApplication
// mapper 接口类扫描包配置
@EnableTransactionManagement
@EnableScheduling
@EnableAspectJAutoProxy(proxyTargetClass = true) //开启AspectJ代理,并将proxyTargetClass置为true,表示启用cglib对Class也进行代理
@MapperScan("com.example.dao")
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
// 程序启动入口
// 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件
SpringApplication.run(Application.class, args);
}
}
6、UserController.java文件
package com.example.controller;
import com.example.service.IServiceUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping(value = "/")
public class UserController {
private static Logger log = LoggerFactory.getLogger(UserController.class);
@Autowired
IServiceUser serviceUser;
public UserController() {
}
/**
* 查询用户
*
* @return Map
*/
@RequestMapping(value = "/User/select", method = { RequestMethod.POST, RequestMethod.GET })
public Map selectSysUser(@RequestParam Map mapParam) {
Map map =new HashMap();
try {
map = serviceUser.selectUser(mapParam);
if(map.size()>0){
map.put("data","success");
}
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
}
7、IDaoUser.java文件
package com.example.dao;
import java.util.Map;
public interface IDaoUser {
/**
* 查询用户
*/
public Map selectUser(Map mapParam);
}
8、IServiceUser.java文件
package com.example.service;
import java.util.List;
import java.util.Map;
public interface IServiceUser {
/**
* 查询系统用户记录
*/
public Map selectUser(Map mapParam);
}
9、ServiceUserImpl.java文件
package com.example.service.impl;
import com.example.dao.IDaoUser;
import com.example.service.IServiceUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Transactional
public class ServiceUserImpl implements IServiceUser {
private Logger log = LoggerFactory.getLogger(this.getClass());
@Autowired
private IDaoUser iDao;
public ServiceUserImpl(){
}
/**
* 查询用户
*/
public Map selectUser(Map mapParam){
Map map=new HashMap();
try {
map= iDao.selectUser(mapParam);
} catch (Exception e) {
log.error(e.getMessage());
}
return map;
}
}
10、T_USER.XML文件
10、创建T_USER表(数据库--MySQL)
CREATE TABLE `test`.`Untitled` (
`USER_ID` int(11) NOT NULL AUTO_INCREMENT,
`USER_NAME` char(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`USER_PASSWORD` char(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`USER_EMAIL` char(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY (`USER_ID`) USING BTREE,
INDEX `IDX_NAME`(`USER_NAME`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
11、往表中添加一条信息
12、把项目导入eclipse或idea中,启动项目,在谷歌浏览器或postmen地址栏输入:localhost:8095/User/select
{
"data": "success",
"USER_PASSWORD": "123",
"USER_EMAIL": "[email protected]",
"USER_ID": 1,
"USER_NAME": "小明"
}
结束语:在网上找过一些springboot项目的创建过程,但是感觉麻烦,这里的一个简约版springboot项目算是对自己的一个小总结吧,如果对您也有帮助,那我很荣幸。