91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

在spring boot中使用mybatis實現搭建一個estfull服務

發布時間:2020-11-12 15:14:49 來源:億速云 閱讀:185 作者:Leah 欄目:開發技術

這篇文章給大家介紹在spring boot中使用mybatis實現搭建一個estfull服務,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

1、創建一個maven項目。

2、在pom.xml中引入依賴包,如下所示:

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<project xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 
 <groupId>com.best</groupId>
 <artifactId>spring-boot-mybatis</artifactId>
 <version>1.0-SNAPSHOT</version>
 
 <properties>
  <java.version>1.8</java.version>
  <fastjson.version>1.2.74</fastjson.version>
  <spring.version>5.3.5.RELEASE</spring.version>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 </properties>
 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.3.5.RELEASE</version>
 </parent>
 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-jdbc</artifactId>
   <exclusions>
    <!-- 排除 tomcat-jdbc 以使用 HikariCP -->
    <exclusion>
     <groupId>org.apache.tomcat</groupId>
     <artifactId>tomcat-jdbc</artifactId>
    </exclusion>
   </exclusions>
  </dependency>
  <!--  <dependency>-->
  <!--   <groupId>org.springframework.boot</groupId>-->
  <!--   <artifactId>spring-boot-starter-security</artifactId>-->
  <!--  </dependency>-->
  <dependency>
   <groupId>org.mybatis.spring.boot</groupId>
   <artifactId>mybatis-spring-boot-starter</artifactId>
   <version>2.1.3</version>
  </dependency>
  <dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
   <version>8.0.22</version>
  </dependency>
  <dependency>
   <groupId>com.alibaba</groupId>
   <artifactId>druid</artifactId>
   <version>1.2.1</version>
  </dependency>
  <dependency>
   <groupId>com.alibaba</groupId>
   <artifactId>fastjson</artifactId>
   <version>${fastjson.version}</version>
  </dependency>
  <dependency>
   <groupId>org.projectlombok</groupId>
   <artifactId>lombok</artifactId>
   <version>1.18.10</version>
  </dependency>
  <dependency>
   <groupId>org.mybatis.spring.boot</groupId>
   <artifactId>mybatis-spring-boot-starter</artifactId>
   <version>2.1.3</version>
  </dependency>
 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
     <source>1.8</source>
     <target>1.8</target>
    </configuration>
   </plugin>
  </plugins>
 </build>
</project>

3、在使用mybatis之前,那么首先需要創建數據表,如:

DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(255) COLLATE utf8_bin DEFAULT NULL,
 `create_date` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
 
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES ('1', 'user1', '2020-11-10 21:01:54');
INSERT INTO `user` VALUES ('2', 'user2', '2020-11-01 21:02:12');

4、然后配置數據庫連接池,這里使用的是alibaba的druid,首先在resources中新建一個application.yml文件,內容如下:

spring:
 datasource:
 type: com.alibaba.druid.pool.DruidDataSource
 driver-class-name: com.mysql.cj.jdbc.Driver
 platform: mysql
 url: jdbc:mysql://localhost:3306/springboottest&#63;useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=CTT
 username: root
 password:
server:
 port: 8080

5、然后新建一個包com.best.db,并新建一個DruidDBConfig類,代碼如下:

package com.best.db;
 
import com.alibaba.druid.pool.DruidDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
 
import javax.sql.DataSource;
 
/**
 * @author:sunxj
 * @date:2020-11-10 21:08:53
 * @description: 數據連接池
 */
@Configuration
public class DruidDBConfig {
 @Value("${spring.datasource.url}")
 private String url;
 @Value("${spring.datasource.username}")
 private String username;
 @Value("${spring.datasource.password}")
 private String password;
 @Value("${spring.datasource.driver-class-name}")
 private String driverClassName;
 @Bean//DataSource 對象為 Spring 容器所管理;
 @Primary//表示這里定義的DataSource將覆蓋其他來源的DataSource。
 public DataSource dataSource(){
  DruidDataSource datasource = new DruidDataSource();
  datasource.setUrl(this.url);
  datasource.setUsername(username);
  datasource.setPassword(password);
  datasource.setDriverClassName(driverClassName);
  return datasource;
 }
 //配置數據庫事務
 @Bean(name = "transactionManager")
 public DataSourceTransactionManager dbOneTransactionManager(
   @Qualifier("dataSource") DataSource dataSource) {
  return new DataSourceTransactionManager(dataSource);
 }
 //配置數據庫工廠
 @Bean(name = "sqlSessionFactory")
 @ConditionalOnMissingBean(name = "sqlSessionFactory")
 public SqlSessionFactory dbOneSqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
  final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
  sessionFactory.setDataSource(dataSource);
  return sessionFactory.getObject();
 }
}

6、配置好連接池,那么就可以開始配置entity了,也就是與表映射的實體類,這里我們使用lombok的注解自動生成set和get方法,那么新建一個com.best.entity包,并新建一個User類,如:

package com.best.entity;
 
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
 
/**
 * @author:sunxj
 * @date:2020-11-10 21:12:58
 * @description:用戶實體類
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
 private Integer id;
 private String name;
 private Date createDate;
}

7、實體類創建好了之后,那么就是創建mybatis映射文件以及類了,這里的映射接口文件和Mapper.xml文件放到一起,首先創建一個com.best.dbo包,映射接口文件和.xml都放到這個包中,并創建一個接口UserMapper,如:

package com.best.dao;
 
import com.best.entity.User;
import org.springframework.stereotype.Repository;
 
import java.util.List;
/**
 * @author:sunxj
 * @date:2020-11-10 21:17:27
 * @description:用戶表的映射接口文件
 */
@Repository
public interface UserMapper {
 List<User> selectAll();
 User selectById(Integer id);
}

8、配置Mapper映射的xml文件,文件名為UserMapper.xml:

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.best.dao.UserMapper">
 <resultMap type="com.best.entity.User" id="UserMap">
  <result property="id" column="id" jdbcType="INTEGER"></result>
  <result property="name" column="name" jdbcType="VARCHAR"></result>
  <result property="createDate" column="create_date" jdbcType="TIMESTAMP"></result>
 </resultMap>
 <select id="selectAll" resultMap="UserMap">
  SELECT * FROM user
 </select>
 <select id="selectById" resultMap="UserMap">
  SELECT * FROM user WHERE id=#{id}
 </select>
</mapper>

9、在配置好之后就可以在application.xml來指定mybatis掃描哪些映射文件,配置如下:

spring:
 datasource:
 type: com.alibaba.druid.pool.DruidDataSource
 driver-class-name: com.mysql.cj.jdbc.Driver
 platform: mysql
 url: jdbc:mysql://localhost:3306/springboottest&#63;useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=CTT
 username: root
 password:
mybatis:
 #如果有多個目錄則可以寫多個,比如com/best/dao/*.xml,com/best/*/dao/*.xml,com/best/*/sss/*/dao/*.xml
 mapper-locations: classpath:com/best/dao/*.xml
 #配置包,這里同樣可以配置多個,
 type-aliases-package: com.best.dao
server:
 port: 8080

10、配置好之后就開始配置service以及impl了,首先創建一個service和service/impl包,并在service下創建一個IUserService接口,并在impl下來實現該接口UserServiceImpl,代碼如下:

package com.best.service;
 
import com.best.entity.User;
import java.util.List;
/**
 * @author:sunxj
 * @date:2020-11-10 21:33:23
 * @description:用戶接口表
 */
public interface IUserService {
 List<User> selectAll();
 User selectById(Integer id);
}
package com.best.service.impl;
 
import com.best.dao.UserMapper;
import com.best.entity.User;
import com.best.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * @author:sunxj
 * @date:2020-11-10 21:34:34
 * @description:用戶接口實現類
 */
@Service("userService")
public class UserServiceImpl implements IUserService {
 @Autowired
 private UserMapper userMapper;
 @Override
 public List<User> selectAll() {
  return userMapper.selectAll();
 }
 
 @Override
 public User selectById(Integer id) {
  return userMapper.selectById(id);
 }
}

11、在創建好service后,需要創建一個controller,如UserController,代碼如下:

package com.best.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.best.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
/**
 * @author:sunxj
 * @date:2020-11-10 21:38:09
 * @description:
 */
@RestController//使用此注解,那么該類下的所有返回都是以json方式返回
@RequestMapping(value="best")//加上value后,在url訪問時必須加上/best才行
public class UserController {
 @Autowired
 private IUserService userService;
 @RequestMapping("/getUser")
 public JSONObject getUser(HttpServletRequest request, HttpServletResponse response) {
  JSONObject obj = new JSONObject();
  obj.put("user","1111");
  return obj;
 }
}

12、創建好之后,最后創建一個spring-boot的入口文件,代碼如下:

package com.best;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
/**
 * @author:sunxj
 * @date:2020-11-10 21:46:43
 * @description:
 */
@SpringBootApplication
public class Application {
 public static void main(String[] args) {
  SpringApplication.run(Application.class,args);
 }
}

13、此時啟動會提示無法找到com.best.dao.UserMapper,如:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-11-10 21:48:21.635 ERROR 10320 --- [   main] o.s.b.d.LoggingFailureAnalysisReporter : 
 
***************************
APPLICATION FAILED TO START
***************************
 
Description:
 
Field userMapper in com.best.service.impl.UserServiceImpl required a bean of type 'com.best.dao.UserMapper' that could not be found.
 
The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)
 
 
Action:
 
Consider defining a bean of type 'com.best.dao.UserMapper' in your configuration.

在spring boot中使用mybatis實現搭建一個estfull服務

14、出現此問題是由于springboot在啟動時,在UserServiceImpl中又使用到了UserMapper的自動注入,而springboot啟動時就沒有掃描到UserMapper,更不可能將它作為bean注入到IOC容器中,因此就無法注入了,那么需要再入口的main文件上加上@MapperScan即可,如:

package com.best;
 
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
/**
 * @author:sunxj
 * @date:2020-11-10 21:46:43
 * @description:
 */
@SpringBootApplication
@MapperScan({"com.best.dao"})//如果有多個可以使用{"com.best.dao","com.best.sss.dao"}
public class Application {
 public static void main(String[] args) {
  SpringApplication.run(Application.class,args);
 }
}

15、此時即可正常啟動,如下圖所示:

在spring boot中使用mybatis實現搭建一個estfull服務

16、此時在瀏覽器中輸入:http://localhost:8080/best/getUser即可,如下圖所示:

在spring boot中使用mybatis實現搭建一個estfull服務

17、以上只是搭建一個可以正常通過url訪問,那么現在來訪問數據庫中的記錄,在訪問之前先創建一些封裝類,比如將實體類封裝成json、返回狀態碼等,先創建一個common包,在該包下創建entity、enums、utils等包,如下圖所示:

在spring boot中使用mybatis實現搭建一個estfull服務

18、然后在enums中創建一個ResultCode枚舉類,此來定義了一些返回狀態碼信息,如下代碼所示:

package com.best.common.enums;
 
/**
 * @author:sunxj
 * @date:2020-11-10 22:08:11
 * @description:返回碼定義
 */
public enum ResultCode {
 //成功
 SUCCESS(200,"成功"),
 //默認失敗
 COMMON_FAIL(404,"失敗"),
 ;
 private Integer code;
 private String message;
 
 ResultCode(Integer code, String message) {
  this.code = code;
  this.message = message;
 }
 
 public Integer getCode() {
  return code;
 }
 
 public void setCode(Integer code) {
  this.code = code;
 }
 
 public String getMessage() {
  return message;
 }
 
 public void setMessage(String message) {
  this.message = message;
 }
 
 public static String getMessageByCode(Integer code) {
  for (ResultCode ele : values()) { //values會默認取出enum中的值對象列表,每個值都是一個ResultCode對象
   if (ele.getCode().equals(code)) {
    return ele.getMessage();
   }
  }
  return null;
 }
}

19、然后在entity中新建一個JsonResult類,用來封裝統一返回的實體類,如:

package com.best.common.entity;
 
import com.best.common.enums.ResultCode;
 
import java.io.Serializable;
 
/**
 * @author:sunxj
 * @date:2020-11-10 22:06:50
 * @description:統一返回的實體類
 */
public class JsonResult<T> implements Serializable {
 private Boolean success;
 private Integer errorCode;
 private String errorMsg;
 private T data;
 
 public JsonResult() {
 }
 
 public JsonResult(Boolean success) {
  this.success = success;
  this.errorCode = success &#63; ResultCode.SUCCESS.getCode():ResultCode.COMMON_FAIL.getCode();
  this.errorMsg = success &#63; ResultCode.SUCCESS.getMessage():ResultCode.COMMON_FAIL.getMessage();
 }
 public JsonResult(Boolean success,ResultCode resultCode) {
  this.success = success;
  this.errorCode = success &#63; ResultCode.SUCCESS.getCode():(resultCode == null &#63; ResultCode.COMMON_FAIL.getCode():resultCode.getCode());
  this.errorMsg = success &#63; ResultCode.SUCCESS.getMessage():(resultCode == null &#63; ResultCode.COMMON_FAIL.getMessage():resultCode.getMessage());
 }
 public JsonResult(Boolean success,T data) {
  this.success = success;
  this.errorCode = success &#63; ResultCode.SUCCESS.getCode():ResultCode.COMMON_FAIL.getCode();
  this.errorMsg = success &#63; ResultCode.SUCCESS.getMessage() : ResultCode.COMMON_FAIL.getMessage();
  this.data = data;
 }
 public JsonResult(Boolean success,ResultCode resultCode,T data) {
  this.success = success;
  this.errorCode = success &#63; ResultCode.SUCCESS.getCode():(resultCode == null &#63; ResultCode.COMMON_FAIL.getCode():resultCode.getCode());
  this.errorMsg = success &#63; ResultCode.SUCCESS.getMessage():(resultCode == null &#63; ResultCode.COMMON_FAIL.getMessage():resultCode.getMessage());
  this.data = data;
 }
 
 public Boolean getSuccess() {
  return success;
 }
 
 public void setSuccess(Boolean success) {
  this.success = success;
 }
 
 public Integer getErrorCode() {
  return errorCode;
 }
 
 public void setErrorCode(Integer errorCode) {
  this.errorCode = errorCode;
 }
 
 public String getErrorMsg() {
  return errorMsg;
 }
 
 public void setErrorMsg(String errorMsg) {
  this.errorMsg = errorMsg;
 }
 
 public T getData() {
  return data;
 }
 
 public void setData(T data) {
  this.data = data;
 }
}

20、然后在utils中新建一個ResultTool,如下代碼所示:

package com.best.common.utils;
 
import com.best.common.entity.JsonResult;
import com.best.common.enums.ResultCode;
 
/**
 * @author:sunxj
 * @date:2020-11-10 22:11:03
 * @description:json返回構造工具
 */
public class ResultTool {
 public static JsonResult success() {
  return new JsonResult(true);
 }
 public static <T> JsonResult<T> success(T data) {
  return new JsonResult<>(true,data);
 }
 public static JsonResult fail() {
  return new JsonResult(false);
 }
 public static JsonResult fail(ResultCode resultCode) {
  return new JsonResult(false,resultCode);
 }
}

21、創建好這些之后,那么就可以開始在controller中進行構造了,controller如下:

package com.best.controller;
 
import com.best.common.entity.JsonResult;
import com.best.common.utils.ResultTool;
import com.best.entity.User;
import com.best.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
 
/**
 * @author:sunxj
 * @date:2020-11-10 21:38:09
 * @description:
 */
@RestController//使用此注解,那么該類下的所有返回都是以json方式返回
@RequestMapping(value="best")//加上value后,在url訪問時必須加上/best才行
public class UserController {
 @Autowired
 private IUserService userService;
 @RequestMapping("/getUser")
 public JsonResult getUser(HttpServletRequest request, HttpServletResponse response) {
  List<User> users = userService.selectAll();
  return ResultTool.success(users);
 }
}

22、重新啟動springboot,然后輸入:http://localhost:8080/best/getUser,此時頁面會出現如下錯誤:

在spring boot中使用mybatis實現搭建一個estfull服務

23、后臺顯示如下錯誤:

package com.best.controller;
 
import com.best.common.entity.JsonResult;
import com.best.common.utils.ResultTool;
import com.best.entity.User;
import com.best.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
 
/**
 * @author:sunxj
 * @date:2020-11-10 21:38:09
 * @description:
 */
@RestController//使用此注解,那么該類下的所有返回都是以json方式返回
@RequestMapping(value="best")//加上value后,在url訪問時必須加上/best才行
public class UserController {
 @Autowired
 private IUserService userService;
 @RequestMapping("/getUser")
 public JsonResult getUser(HttpServletRequest request, HttpServletResponse response) {
  List<User> users = userService.selectAll();
  return ResultTool.success(users);
 }
}

23、這意思就是沒有找到UserMapper接口文件中的selectAll方法,也就是沒有和*Mapper.xml匹配成功,這是由于我們將.xml文件和java文件放在了java目錄,而通過maven來管理,它不會將java文件中的xml文件打包進去的,因此需要再pom中的build中指定,如:

2020-11-10 22:15:10.487 ERROR 12992 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.best.dao.UserMapper.selectAll] with root cause
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.best.dao.UserMapper.selectAll
 at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235) ~[mybatis-3.5.5.jar:3.5.5]
 at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53) ~[mybatis-3.5.5.jar:3.5.5]
 at org.apache.ibatis.binding.MapperProxy.lambda$cachedInvoker$0(MapperProxy.java:115) ~[mybatis-3.5.5.jar:3.5.5]
 at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_261]
 at org.apache.ibatis.binding.MapperProxy.cachedInvoker(MapperProxy.java:102) ~[mybatis-3.5.5.jar:3.5.5]
 at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) ~[mybatis-3.5.5.jar:3.5.5]
 at com.sun.proxy.$Proxy57.selectAll(Unknown Source) ~[na:na]
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_261]
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_261]
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_261]
 at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_261]
 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at com.sun.proxy.$Proxy58.selectAll(Unknown Source) ~[na:na]
 at com.best.service.impl.UserServiceImpl.selectAll(UserServiceImpl.java:22) ~[classes/:na]
 at com.best.controller.UserController.getUser(UserController.java:26) ~[classes/:na]
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_261]
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_261]
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_261]
 at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_261]
 at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878) ~[spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792) ~[spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:626) ~[tomcat-embed-core-9.0.39.jar:4.0.FR]
 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.39.jar:4.0.FR]
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.39.jar:9.0.39]
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.10.RELEASE.jar:5.2.10.RELEASE]
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:41002) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_261]
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_261]
 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.39.jar:9.0.39]
 at java.lang.Thread.run(Thread.java:748) [na:1.8.0_261]

在spring boot中使用mybatis實現搭建一個estfull服務

24、然后在此重新運行,重新輸入網址即可,如下圖所示:

在spring boot中使用mybatis實現搭建一個estfull服務

25、到此即可搭建完畢,使用此方法可以搭建一個前后端完全分離通過json通信的springboot后臺。

關于在spring boot中使用mybatis實現搭建一個estfull服務就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

江永县| 彰武县| 南华县| 新津县| 江源县| 富阳市| 渑池县| 临桂县| 宽甸| 淳化县| 高台县| 徐水县| 伽师县| 儋州市| 鄂州市| 曲阳县| 赫章县| 昌图县| 邵阳市| 喀什市| 安丘市| 曲阳县| 宁化县| 聂荣县| 新巴尔虎左旗| 青神县| 怀仁县| 建阳市| 襄樊市| 纳雍县| 夹江县| 麻江县| 黔江区| 富宁县| 泾川县| 汉中市| 阿合奇县| 延川县| 思南县| 西平县| 威海市|