欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

怎么在SpringBoot中使用MyBatis框架實(shí)現(xiàn)查詢操作-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)怎么在Spring Boot中使用MyBatis框架實(shí)現(xiàn)查詢操作,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

成都創(chuàng)新互聯(lián)IDC提供業(yè)務(wù):溫江服務(wù)器租用,成都服務(wù)器租用,溫江服務(wù)器租用,重慶服務(wù)器租用等四川省內(nèi)主機(jī)托管與主機(jī)租用業(yè)務(wù);數(shù)據(jù)中心含:雙線機(jī)房,BGP機(jī)房,電信機(jī)房,移動機(jī)房,聯(lián)通機(jī)房。

一.在你建立的工程下創(chuàng)建 Module 選擇Spring initializr創(chuàng)建。

怎么在Spring Boot中使用MyBatis框架實(shí)現(xiàn)查詢操作

二.在Type處選擇: Maven Project(項(xiàng)目的構(gòu)建工具)

怎么在Spring Boot中使用MyBatis框架實(shí)現(xiàn)查詢操作

三.創(chuàng)建依賴時(shí)勾上web,mybatis,mysql(這個看你個人需要吧,可以自主選擇)

怎么在Spring Boot中使用MyBatis框架實(shí)現(xiàn)查詢操作

怎么在Spring Boot中使用MyBatis框架實(shí)現(xiàn)查詢操作

建立好的項(xiàng)目結(jié)構(gòu)如下:

怎么在Spring Boot中使用MyBatis框架實(shí)現(xiàn)查詢操作

注意:application.properties和application.yml是同一個東西,均為項(xiàng)目的核心配置文件

內(nèi)容如下:

#連接數(shù)據(jù)庫
spring.datasource.url=jdbc:mysql://localhost:3306/smbms
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driverClassName=com.mysql.jdbc.Driver
#引入mybatis的配置文件
mybatis:
  mybatis.mapper-locations=classpath:mapper/*.xml
  mybatis.type-aliases-package=com.example.sprboot.pojo

相應(yīng)的pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<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.example</groupId>
  <artifactId>springboot</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>springboot</name>
  <description>Demo project for Spring Boot</description>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
  </properties>
  <dependencies>
    <!--添加web依賴-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!--引入spring boot包-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <!-- Spring-Mybatis -->
    <dependency>
      <groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-starter</artifactId>
      <version>1.3.0</version>
    </dependency>
    <!-- MySQL -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <!--使用json對象-->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.49</version>
    </dependency>
    <!--使用thymeleaf標(biāo)簽-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>

相應(yīng)的接口UserMapper如下:

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

service如下:

public interface UserService {
  List<User> getList();
}

impl如下:

@Service
public class UserServiceImpl implements UserService {
  @Resource
  private UserMapper userMapper;
  @Override
  public List<User> getList() {
    return userMapper.getList();
  }
}

在resources中建一個文件夾mapper里面放mapper.xml文件,代碼如下:

<select id="getList" resultType="User">
  select * from smbms_user
</select>

在templates文件夾中建html文件(注意:Spring Boot中不能跳轉(zhuǎn)到.jsp文件,所以只能用html)

核心代碼如下:

<table>
  <th>工號</th>
  <th>用戶名</th>
  <th>姓名</th>
  <th>性別</th>
  <th>生日</th>
  <th>電話</th>
  <th>地址</th>
  <th>創(chuàng)建時(shí)間</th>
  <tr th:each="user : ${users}">
    <td th:text="${user.id}"></td>
    <td th:text="${user.userCode}"></td>
    <td th:text="${user.userName}"></td>
    <td th:text="${user.gender}"></td>
    <td th:text="${user.birthday}"></td>
    <td th:text="${user.phone}"></td>
    <td th:text="${user.address}"></td>
    <td th:text="${user.createdBY}"></td>
  </tr>
</table>

此處有一個th標(biāo)簽,需要引入一個<html xmlns:th="http://www.thymeleaf.org">

并在pom.xml中引入對應(yīng)的jar包(html中不能使用jstl表達(dá)式)

大家可以擴(kuò)展一下thymeleaf的知識

控制器代碼如下:

@Controller
public class UserController {
  @Resource
  private UserService userService;
@RequestMapping("/")
  public String getStuinforList(HttpServletRequest request, Model model){
    List<User> list=userService.getList();
    model.addAttribute("users",list);
    System.out.println(list);
    return "/index.html";
  }
}

關(guān)于怎么在Spring Boot中使用MyBatis框架實(shí)現(xiàn)查詢操作就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

網(wǎng)頁名稱:怎么在SpringBoot中使用MyBatis框架實(shí)現(xiàn)查詢操作-創(chuàng)新互聯(lián)
URL鏈接:http://aaarwkj.com/article24/gioje.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、響應(yīng)式網(wǎng)站、品牌網(wǎng)站建設(shè)Google、網(wǎng)站收錄微信小程序

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作
91午夜福利偷拍视频| 久久精品国产亚洲av久一一区| 欧美亚洲一区二区三区精品| 亚洲综合色视频免费在线播放| 日韩欧美中文字幕综合网| 亚洲黄色av一区二区三区| 精品国产亚洲av剧情| 亚洲成人乱码一区二区| 人妻猛烈进入中文字幕| 精品人妻中文av一区二区 | 国产精品av一区二区在线| 天堂中文字幕在线乱码一区| 国产日产精品久久一区| 九九99九九99九九精品在线观看| 亚洲av乱码一区二区三四五六七| 在线亚洲精品一区二区| 国产一区国产二区中文字幕| 亚洲精品第一国产综合| 国产传媒免费在线播放| 少妇熟女视频一区二区三区| 亚洲一区二区三区在线观看呢| 国产在线视频不卡一区| 在线看日本十八禁网站| 门国产av一区二区三区| 国产在线一区二区三区观看| 成人黄色一级电影免费看| 日韩不卡的一区免费视频| 国产精品国产高清国产一区| 亚洲中文字幕一二区日韩| 色综合色狠狠天天综合色| 99热这里只有精品在线| 久久av免费一区二区观看| 亚洲av一区二区在线看| 青青草原免费在线观看| 亚洲午夜激情免费试看| 日本东京热不卡一区二区| 国产三级久久精品三级91| 日本国产精品久久一线| 人妻少妇系列一区二区| 日韩精品在线免费观看了| 91麻豆亚洲国产成人久久精品|