快速搭建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接口成功拿到数据
常见错误
- 如碰到An incompatible version [1.2.10] of the APR based Apache Tomcat Native libra错误可去以下链接查看
https://blog.youkuaiyun.com/zs520ct/article/details/80497281