快速搭建springboot项目

下载springboot的包

链接: https://spring.io/projects/spring-boot

在这里插入图片描述

使用idea或者eclipse导入Maven项目

  • 在pom.xml中添加依赖
		<!--mybatis的依赖包-->
		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>1.3.0</version>
		</dependency>
		<!--oracle的依赖包-->
		<dependency>
			<groupId>com.oracle</groupId>
			<artifactId>ojdbc6</artifactId>
			<version>11.2.0</version>
		</dependency>
		<!--springboot 热部署-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<optional>true</optional>
		</dependency>

<!--插件-->
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <fork>true</fork>
            </configuration>
        </plugin>
    </plugins>
</build>
##dataSource数据源配置
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:1521/orcl
spring.datasource.username=yjy
spring.datasource.password=yjy


##Mybatis映射实体类和映射文件配置,扫描哪个包
mybatis.typeAliasesPackage=com.cgzx.certificates.entity
mybatis.mapperLocations=classpath:com/cgzx/certificates/dao/*Mapper.xml

#debug
logging.level.org.springframework=WARN
logging.level.com.github.ArchiveService.dao=DEBUG
loggin.file=logs/srping-boot-loggin.log

#service端口配置和项目路径配置
server.port=8082
#server.servlet.context-path=/certificates

项目目录如下

  • 资源放在resources中,比如html,jar包
    在这里插入图片描述

三个层的代码

  • controller层
package com.cgzx.certificates.controller;

import com.cgzx.certificates.entity.User;
import com.cgzx.certificates.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/select")
public class controller {
    @Autowired
    private UserService userService;
    @RequestMapping(value = "/getUser")
    public List<User> getUser(){
        System.out.println("jinlaile");
        List<User> user = userService.getUser();
        System.out.println(user);
        return user;
    }
    @RequestMapping(value = "/ok")
    public String ok(){
        System.out.println("ok");
    return "ok";
    }
}

  • Service层
package com.cgzx.certificates.service;

import com.cgzx.certificates.dao.UserMapper;
import com.cgzx.certificates.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<User> getUser() {
        List<User> user = userMapper.getUser();
        return user;
    }
}

  • dao层
package com.cgzx.certificates.dao;

import com.cgzx.certificates.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface UserMapper {
    List<User> getUser();
}

<?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.cgzx.certificates.dao.UserMapper">

    <resultMap id="UserMap" type="com.cgzx.certificates.entity.User">
        <id column="id" property="id"/>
        <result property="wtrphone" column="wtrphone"/>
        <result property="projectcode" column="projectcode"/>
        <result property="casecode" column="casecode"/>
        <result property="projectname" column="projectname"/>
        <result property="pid" column="pid"/>
        <result property="registertime" column="registertime"/>
        <result property="fondsnumber" column="fondsnumber"/>
        <result property="buildaddress" column="buildaddress"/>
        <result property="buildunit" column="buildunit"/>
        <result property="linkman" column="linkman"/>
        <result property="linkphone" column="linkphone"/>
        <result property="legalman" column="legalman"/>
        <result property="legalphone" column="legalphone"/>
        <result property="majorproject" column="majorproject"/>
        <result property="zbbm" column="zbbm"/>
        <result property="certificatenumber" column="certificatenumber"/>
        <result property="certificatedate" column="certificatedate"/>
        <result property="dwbm" column="dwbm"/>
        <result property="xmlx" column="xmlx"/>
        <result property="slr" column="slr"/>
        <result property="wtr" column="wtr"/>
        <result property="ydxz" column="ydxz"/>
        <result property="tunumber" column="tunumber"/>
        <result property="content" column="content"/>
        <result property="costday" column="costday"/>
        <result property="actualdate" column="actualdate"/>
        <result property="theorydate" column="theorydate"/>
        <result property="limitstatus" column="limitstatus"/>
        <result property="handlestatus" column="handlestatus"/>
        <result property="lifestatus" column="lifestatus"/>
        <result property="jbj" column="jbj"/>
        <result property="ref_headproject_id" column="ref_headproject_id"/>
        <result property="ref_createuser_id" column="ref_createuser_id"/>
        <result property="ref_sender_id" column="ref_sender_id"/>
        <result property="ref_business_id" column="ref_business_id"/>
        <result property="ref_processrevision_id" column="ref_processrevision_id"/>
        <result property="ref_bureau_id" column="ref_bureau_id"/>
        <result property="ref_createorganization_id" column="ref_createorganization_id"/>
        <result property="builderadd" column="builderadd"/>
        <result property="ref_undertakeuser_id" column="ref_undertakeuser_id"/>
        <result property="ref_businessprocess_id" column="ref_businessprocess_id"/>
        <result property="bindingassignee" column="bindingassignee"/>
        <result property="bindingunit" column="bindingunit"/>
        <result property="bindingcompany" column="bindingcompany"/>
        <result property="agentoffice" column="agentoffice"/>
    </resultMap>
    <select id="getUser" resultMap="UserMap">
        select t.* from BZ_JBXX t where t.id='6350571'
    </select>
</mapper>

运行结果

  • 访问资源
    在这里插入图片描述

  • 访问select/getUser接口成功拿到数据
    在这里插入图片描述

常见错误

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值