久久亚洲精品国产精品_羞羞漫画在线版免费阅读网页漫画_国产精品久久久久久久久久久久_午夜dj免费观看在线视频_希崎杰西卡番号

hp m1005打印機(jī)驅(qū)動(dòng)下載

前沿拓展:


1 概述1.1 介紹

在項(xiàng)目開發(fā)過程中,有很多業(yè)務(wù)模塊的代碼是具有一定規(guī)律性的,例如controller控制器、service接口、service實(shí)現(xiàn)類、mapper接口、model實(shí)體類等等,這部分代碼可以使用代碼生成器生成,我們就可以將更多的時(shí)間放在業(yè)務(wù)邏輯上。

傳統(tǒng)的開發(fā)步驟:

創(chuàng)建數(shù)據(jù)庫和表 根據(jù)表設(shè)計(jì)實(shí)體類 ? 編寫mapper接口 ? 編寫service接口和實(shí)現(xiàn)類 ? 編寫controller控制器 ? 編寫前端頁面 ? 前后端聯(lián)調(diào)

基于代碼生成器開發(fā)步驟:

創(chuàng)建數(shù)據(jù)庫和表 ? 使用代碼生成器生成實(shí)體類、mapper、service、controller、前端頁面 ? 將生成好的代碼拷貝到項(xiàng)目中并做調(diào)整 ? 前后端聯(lián)調(diào)

我們只需要知道數(shù)據(jù)庫和表相關(guān)信息,就可以結(jié)合模版生成各個(gè)模塊的代碼,減少了很多重復(fù)工作,也減少出錯(cuò)概率,提高效率。

1.2 實(shí)現(xiàn)思路hp m1005打印機(jī)驅(qū)動(dòng)下載

(1)需要對(duì)數(shù)據(jù)庫表解析獲取到元數(shù)據(jù),包含表字段名稱、字段類型等等

(2)將通用的代碼編寫成模版文件,部分?jǐn)?shù)據(jù)需使用占位符替換

(3)將元數(shù)據(jù)和模版文件結(jié)合,使用一些模版引擎工具(例如freemarker)即可生成源代碼文件

2 Freemarker2.1 介紹

FreeMarker 是一款 模板引擎: 即一種基于模板和要改變的數(shù)據(jù), 并用來生成輸出文本(HTML網(wǎng)頁,電子郵件,配置文件,源代碼等)的通用工具。 它不是面向最終用戶的,而是一個(gè)Java類庫,是一款程序員可以嵌入他們所開發(fā)產(chǎn)品的組件。

模板編寫為FreeMarker Template Language (FTL)。它是簡單的,專用的語言, 在模板中,你可以專注于如何展現(xiàn)數(shù)據(jù), 而在模板之外可以專注于要展示什么數(shù)據(jù)。

hp m1005打印機(jī)驅(qū)動(dòng)下載

2.2 應(yīng)用場景

(1)動(dòng)態(tài)頁面

freemarker可以作為springmvc一種視圖格式,像jsp一樣被瀏覽器訪問。

(2)頁面靜態(tài)化

對(duì)于一些內(nèi)容比較多,更新頻率很小,訪問又很頻繁的頁面,可以使用freemarker靜態(tài)化,減少DB的壓力,提高頁面打開速度。

(3)代碼生成器

根據(jù)配置生成頁面和代碼,減少重復(fù)工作,提高開發(fā)效率。

2.3 快速入門

(1)創(chuàng)建freemarker-demo模塊,并導(dǎo)入相關(guān)依賴

<?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.itheima</groupId>
<artifactId>freemarker-demo</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
</parent>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>

<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>
</dependency>
<!– freemarker –>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!– lombok –>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

(2)application.yml相關(guān)配置

server:
port: 8881 #服務(wù)端口
spring:
application:
name: freemarker-demo #指定服務(wù)名
freemarker:
cache: false #關(guān)閉模板緩存,方便測試
settings:
template_update_delay: 0 #檢查模板更新延遲時(shí)間,設(shè)置為0表示立即檢查,如果時(shí)間大于0會(huì)有緩存不方便進(jìn)行模板測試
suffix: .ftl #指定Freemarker模板文件的后綴名

(3)創(chuàng)建啟動(dòng)類

package com.heima.freemarker;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class FreemarkerDemotApplication {
public static void main(String[] args) {
SpringApplication.run(FreemarkerDemotApplication.class,args);
}
}

(4)創(chuàng)建Student模型類

package com.itheima.freemarker.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Student {
private Integer id;
private String name;//姓名
private Integer age;//年齡
private Date birthday;//生日
private Float money;//錢包
}

(5)創(chuàng)建StudentController

package com.itheima.freemarker.controller;

import com.itheima.freemarker.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

@Controller
@RequestMapping("student")
public class StudentController {

@GetMapping("index")
public String index(Model model){
//1.純文本形式的參數(shù)
model.addAttribute("name", "Freemarker");

//2.實(shí)體類相關(guān)的參數(shù)
Student student = new Student();
student.setName("黑馬");
student.setAge(18);
model.addAttribute("stu", student);

return "01-index";
}
}

(6)在resources/templates下創(chuàng)建01-index.ftl模版文件

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>首頁</title>
</head>
<body>
<b>普通文本 String 展示:</b><br/>
Hello ${name} <br>

<hr>
<b>對(duì)象Student中的數(shù)據(jù)展示:</b><br/>
姓名:${stu.name}<br/>
年齡:${stu.age}
<hr>
</body>
</html>

(7)測試

瀏覽器訪問 http://localhost:8881/student/index

效果如下

hp m1005打印機(jī)驅(qū)動(dòng)下載

2.4 模版2.4.1 基礎(chǔ)語法種類

(1)注釋,即<#– –>,介于其之間的內(nèi)容會(huì)被freemarker忽略

<#–我是一個(gè)freemarker注釋–>

(2)插值(Interpolation):即 :遍歷學(xué)生**,顯示**總條數(shù),id不要逗號(hào)隔開,顯示學(xué)生的生日(只顯示年月日),錢包顯示整數(shù)并顯示單位,用戶姓名做脫敏處理(如果是兩個(gè)字第二個(gè)字顯示為星號(hào),例如張三顯示為張*,如果大于兩個(gè)字,中間字顯示為星號(hào),例如成吉思汗顯示為成*汗,諸葛亮顯示為諸*亮

(1)修改StudentController中的list方法,

@GetMapping("list")
public String list(Model model) throws ParseException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
List<Student> list = new ArrayList<>();

list.add(new Student(1001,"張三",15, dateFormat.parse("2007-10-01 10:00:00"), 1000.11F));
list.add(new Student(1002,"李四",28, dateFormat.parse("1994-10-01 10:00:00"), 5000.3F));
list.add(new Student(1003,"王五",45, dateFormat.parse("1977-10-01 10:00:00"), 9000.63F));
list.add(new Student(1004,"趙六",62, dateFormat.parse("1960-10-01 10:00:00"), 10000.99F));
list.add(new Student(1005,"孫七",75, dateFormat.parse("1947-10-01 10:00:00"), 16000.66F));
model.addAttribute("stus",list);

return "02-list";
}

(2)修改02-list.ftl模版

共${stus?size}條數(shù)據(jù):輸出總條數(shù)

stu.id后面加?c:id不需要逗號(hào)分割

stu.birthday后面加?date:生日只輸出年月日

stu.money后面加?int:金額取整

姓名需要使用replace和substring函數(shù)處理

完整內(nèi)容如下

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>列表頁面</title>
<style>
table{
border-spacing: 0;/*把單元格間隙設(shè)置為0*/
border-collapse: collapse;/*設(shè)置單元格的邊框合并為1*/
}
td{
border:1px solid #ACBED1;
text-align: center;
}
</style>
</head>
<body>
共${stus?size}條數(shù)據(jù)
<table>
<tr>
<td>序號(hào)</td>
<td>id</td>
<td>姓名</td>
<td>所處的年齡段</td>
<td>生日</td>
<td>錢包</td>
<td>是否最后一條數(shù)據(jù)</td>
</tr>
<#list stus as stu >
<tr>
<td>${stu_index + 1}</td>
<td>${stu.id?c}</td>
<td>
<#if stu.name?length=2>
${stu.name?replace(stu.name?substring(1), "*")}
<#else>
${stu.name?replace(stu.name?substring(1, stu.name?length-1), "*")}
</#if>
</td>
<td>
<#if stu.age <= 6>
童年
<#elseif stu.age <= 17>
少年
<#elseif stu.age <= 40>
青年
<#elseif stu.age <= 65>
中年
<#else>
老年
</#if>
</td>
<td>${stu.birthday?date}</td>
<td>${stu.money?int}元</td>
<td>
<#if stu_has_next>

<#else>

</#if>
</td>
</tr>
</#list>
</table>

<hr>
</body>
</html>

(3)測試

瀏覽器訪問http://localhost:8881/student/list

效果如下

hp m1005打印機(jī)驅(qū)動(dòng)下載

2.4.9 靜態(tài)化

(1)springboot整合freemarker靜態(tài)化文件用法

編寫springboot測試用例

package com.itheima.test;

import com.itheima.freemarker.FreemarkerDemoApplication;
import com.itheima.freemarker.entity.Student;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.FileWriter;
import java.io.IOException;
import java.util.*;

@SpringBootTest(classes = FreemarkerDemoApplication.class)
@RunWith(SpringRunner.class)
public class FreemarkerTest {

//注入freemarker配置類
@Autowired
private Configuration configuration;

@Test
public void test() throws IOException, TemplateException {
Template template = configuration.getTemplate("04-innerFunc.ftl");
/**
* 靜態(tài)化并輸出到文件中 參數(shù)1:數(shù)據(jù)模型 參數(shù)2:文件輸出流
*/
template.process(getData(), new FileWriter("d:/list.html"));
/**
* 靜態(tài)化并輸出到字節(jié)輸出流中
*/
//StringWriter out = new StringWriter();
//template.process(getData(), out);
//System.out.println(out.toString());
}

private Map getData(){

Map<String,Object> map = new HashMap<>();

Student stu1 = new Student();
stu1.setName("小強(qiáng)");
stu1.setAge(18);
stu1.setMoney(1000.86f);
stu1.setBirthday(new Date());

//小紅對(duì)象模型數(shù)據(jù)
Student stu2 = new Student();
stu2.setName("小紅");
stu2.setMoney(200.1f);
stu2.setAge(19);

//將兩個(gè)對(duì)象模型數(shù)據(jù)存放到List**中
List<Student> stus = new ArrayList<>();
stus.add(stu1);
stus.add(stu2);

//向model中存放List**數(shù)據(jù)
map.put("stus",stus);

//map數(shù)據(jù)
Map<String,Student> stuMap = new HashMap<>();
stuMap.put("stu1",stu1);
stuMap.put("stu2",stu2);

map.put("stuMap",stuMap);
//日期
map.put("today",new Date());

//長數(shù)值
map.put("point",38473897438743L);

return map;

}
}

(2)freemarker原生靜態(tài)化用法

package com.itheima.freemarker.test;

import com.itheima.freemarker.entity.Student;
import freemarker.cache.FileTemplateLoader;
import freemarker.cache.NullCacheStorage;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;

public class FreemarkerTest {

public static void main(String[] args) throws IOException, TemplateException {
//創(chuàng)建配置類
Configuration CONFIGURATION = new Configuration(Configuration.VERSION_2_3_22);
//設(shè)置模版加載路徑

//ClassTemplateLoader方式:需要將模版放在FreemarkerTest類所在的包,加載模版時(shí)會(huì)從該包下加載
//CONFIGURATION.setTemplateLoader(new ClassTemplateLoader(FreemarkerTest.class,""));

String path = java.net.URLDecoder.decode(FreemarkerTest.class.getClassLoader().getResource("").getPath(),"utf-8");
//FileTemplateLoader方式:需要將模版放置在classpath目錄下 目錄有中文也可以
CONFIGURATION.setTemplateLoader(new FileTemplateLoader(new File(path)));

//設(shè)置編碼
CONFIGURATION.setDefaultEncoding("UTF-8");
//設(shè)置異常處理器
CONFIGURATION.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
//設(shè)置緩存方式
CONFIGURATION.setCacheStorage(NullCacheStorage.INSTANCE);
//加載模版
Template template = CONFIGURATION.getTemplate("templates/04-innerFunc.ftl");
/**
* 靜態(tài)化并輸出到文件中 參數(shù)1:數(shù)據(jù)模型 參數(shù)2:文件輸出流
*/
template.process(getModel(), new FileWriter("d:/list.html"));
/**
* 靜態(tài)化并輸出到字節(jié)輸出流中
*/
//StringWriter out = new StringWriter();
//template.process(getData(), out);
//System.out.println(out.toString());
}

public static Map getModel(){
Map map = new HashMap();
//1.1 小強(qiáng)對(duì)象模型數(shù)據(jù)
Student stu1 = new Student();
stu1.setName("小強(qiáng)");
stu1.setAge(18);
stu1.setMoney(1000.86f);
stu1.setBirthday(new Date());
//1.2 小紅對(duì)象模型數(shù)據(jù)
Student stu2 = new Student();
stu2.setName("小紅");
stu2.setMoney(200.1f);
stu2.setAge(19);
//1.3 將兩個(gè)對(duì)象模型數(shù)據(jù)存放到List**中
List<Student> stus = new ArrayList<>();
stus.add(stu1);
stus.add(stu2);
map.put("stus", stus);
// 2.1 添加日期
Date date = new Date();
map.put("today", date);
// 3.1 添加數(shù)值
map.put("point", 102920122);
return map;
}
}3 數(shù)據(jù)庫元數(shù)據(jù)3.1 介紹

元數(shù)據(jù)(Metadata)是描述數(shù)據(jù)的數(shù)據(jù)。

數(shù)據(jù)庫元數(shù)據(jù)(DatabaseMetaData)就是指定義數(shù)據(jù)庫各類對(duì)象結(jié)構(gòu)的數(shù)據(jù)。

在mysql中可以通過show關(guān)鍵字獲取相關(guān)的元數(shù)據(jù)

show status; 獲取數(shù)據(jù)庫的狀態(tài)
show databases; 列出所有數(shù)據(jù)庫
show tables; 列出所有表
show create database [數(shù)據(jù)庫名]; 獲取數(shù)據(jù)庫的定義
show create table [數(shù)據(jù)表名]; 獲取數(shù)據(jù)表的定義
show columns from <table_name>; 顯示表的結(jié)構(gòu)
show index from <table_name>; 顯示表中有關(guān)索引和索引列的信息
show character set; 顯示可用的字符集以及其默認(rèn)整理
show collation; 顯示每個(gè)字符集的整理
show variables; 列出數(shù)據(jù)庫中的參數(shù)定義值

也可以從 information_schema庫中獲取元數(shù)據(jù),information_schema數(shù)據(jù)庫是MySQL自帶的信息數(shù)據(jù)庫,它提供了訪問數(shù)據(jù)庫元數(shù)據(jù)的方式。存著其他數(shù)據(jù)庫的信息。

select schema_name from information_schema.schemata; 列出所有的庫
select table_name FROM information_schema.tables; 列出所有的表

在代碼中可以由JDBC的Connection對(duì)象通過getMetaData方法獲取而來,主要封裝了是對(duì)數(shù)據(jù)庫本身的一些整體綜合信息,例如數(shù)據(jù)庫的產(chǎn)品名稱,數(shù)據(jù)庫的版本號(hào),數(shù)據(jù)庫的URL,是否支持事務(wù)等等。

DatabaseMetaData的常用方法:

getDatabaseProductName:獲取數(shù)據(jù)庫的產(chǎn)品名稱
getDatabaseProductName:獲取數(shù)據(jù)庫的版本號(hào)
getUserName:獲取數(shù)據(jù)庫的用戶名
getURL:獲取數(shù)據(jù)庫連接的URL
getDriverName:獲取數(shù)據(jù)庫的驅(qū)動(dòng)名稱
driverVersion:獲取數(shù)據(jù)庫的驅(qū)動(dòng)版本號(hào)
isReadOnly:查看數(shù)據(jù)庫是否只允許讀**作
supportsTransactions:查看數(shù)據(jù)庫是否支持事務(wù)3.2 搭建環(huán)境

(1)導(dǎo)入mysql依賴

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>

(2)創(chuàng)建測試用例

package com.itheima.test;

import org.junit.Before;
import org.junit.Test;

import java.sql.*;
import java.util.Properties;

public class DataBaseMetaDataTest {
private Connection conn;

@Before
public void init() throws Exception {
Properties pro = new Properties();
pro.setProperty("user", "root");
pro.setProperty("password", "123456");
pro.put("useInformationSchema", "true");//獲取mysql表注釋
//pro.setProperty("remarksReporting","true");//獲取oracle表注釋
conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/?useUnicode=true&characterEncoding=UTF8", pro);
}
}3.3 綜合信息元數(shù)據(jù)

(1)獲取數(shù)據(jù)庫元信息綜合信息

@Test
public void testDatabaseMetaData() throws SQLException {
//獲取數(shù)據(jù)庫元數(shù)據(jù)
DatabaseMetaData dbMetaData = conn.getMetaData();
//獲取數(shù)據(jù)庫產(chǎn)品名稱
String productName = dbMetaData.getDatabaseProductName();
System.out.println(productName);
//獲取數(shù)據(jù)庫版本號(hào)
String productVersion = dbMetaData.getDatabaseProductVersion();
System.out.println(productVersion);
//獲取數(shù)據(jù)庫用戶名
String userName = dbMetaData.getUserName();
System.out.println(userName);
//獲取數(shù)據(jù)庫連接URL
String userUrl = dbMetaData.getURL();
System.out.println(userUrl);
//獲取數(shù)據(jù)庫驅(qū)動(dòng)
String driverName = dbMetaData.getDriverName();
System.out.println(driverName);
//獲取數(shù)據(jù)庫驅(qū)動(dòng)版本號(hào)
String driverVersion = dbMetaData.getDriverVersion();
System.out.println(driverVersion);
//查看數(shù)據(jù)庫是否允許讀**作
boolean isReadOnly = dbMetaData.isReadOnly();
System.out.println(isReadOnly);
//查看數(shù)據(jù)庫是否支持事務(wù)**作
boolean supportsTransactions = dbMetaData.supportsTransactions();
System.out.println(supportsTransactions);
}

(2)獲取數(shù)據(jù)庫列表

@Test
public void testFindAllCatalogs() throws Exception {
//獲取元數(shù)據(jù)
DatabaseMetaData metaData = conn.getMetaData();
//獲取數(shù)據(jù)庫列表
ResultSet rs = metaData.getCatalogs();
//遍歷獲取所有數(shù)據(jù)庫表
while (rs.next()) {
//打印數(shù)據(jù)庫名稱
System.out.println(rs.getString(1));
}
//釋放資源
rs.close();
conn.close();
}

(3)獲取某數(shù)據(jù)庫中的所有表信息

@Test
public void testFindAllTable() throws Exception {
//獲取元數(shù)據(jù)
DatabaseMetaData metaData = conn.getMetaData();
//獲取所有的數(shù)據(jù)庫表信息
ResultSet rs = metaData.getTables("庫名", "%", "%", new String[]{"TABLE"});
//拼裝table
while (rs.next()) {
//所屬數(shù)據(jù)庫
System.out.println(rs.getString(1));
//所屬schema
System.out.println(rs.getString(2));
//表名
System.out.println(rs.getString(3));
//數(shù)據(jù)庫表類型
System.out.println(rs.getString(4));
//數(shù)據(jù)庫表備注
System.out.println(rs.getString(5));
System.out.println("————–");
}
}

(4)獲取某張表所有的列信息

@Test
public void testFindAllColumns() throws Exception {
//獲取元數(shù)據(jù)
DatabaseMetaData metaData = conn.getMetaData();
//獲取所有的數(shù)據(jù)庫某張表所有列信息
ResultSet rs = metaData.getColumns("庫名", "%", "表名","%");

while(rs.next()) {
//表名
System.out.println(rs.getString("TABLE_NAME"));
//列名
System.out.println(rs.getString("COLUMN_NAME"));
//類型碼值
System.out.println(rs.getString("DATA_TYPE"));
//類型名稱
System.out.println(rs.getString("TYPE_NAME"));
//列的大小
System.out.println(rs.getString("COLUMN_SIZE"));
//小數(shù)部分位數(shù),不適用的類型會(huì)返回null
System.out.println(rs.getString("DECIMAL_DIGITS"));
//是否允許使用null
System.out.println(rs.getString("NULLABLE"));
//列的注釋信息
System.out.println(rs.getString("REMARKS"));
//默認(rèn)值
System.out.println(rs.getString("COLUMN_DEF"));
//是否自增
System.out.println(rs.getString("IS_AUTOINCREMENT"));
//表中的列的索引(從 1 開始
System.out.println(rs.getString("ORDINAL_POSITION"));
System.out.println("————–");
}
}3.4 參數(shù)元數(shù)據(jù)

參數(shù)元數(shù)據(jù)(ParameterMetaData):是由PreparedStatement對(duì)象通過getParameterMetaData方法獲取而 來,主要是針對(duì)PreparedStatement對(duì)象和其預(yù)編譯的SQL命令語句提供一些信息,ParameterMetaData能提供占位符參數(shù)的個(gè)數(shù),獲取指**置占位符的SQL類型等等 以下有一些關(guān)于ParameterMetaData的常用方法:

getParameterCount:獲取預(yù)編譯SQL語句中占位符參數(shù)的個(gè)數(shù)@Test
public void testParameterMetaData() throws Exception {
String sql = "select * from health.t_checkgroup where id=? and code=?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "7");
pstmt.setString(2, "0003");
//獲取ParameterMetaData對(duì)象
ParameterMetaData paramMetaData = pstmt.getParameterMetaData();
//獲取參數(shù)個(gè)數(shù)
int paramCount = paramMetaData.getParameterCount();
System.out.println(paramCount);
}3.5 結(jié)果集元數(shù)據(jù)

結(jié)果集元數(shù)據(jù)(ResultSetMetaData):是由ResultSet對(duì)象通過getMetaData方法獲取而來,主要是針對(duì)由數(shù)據(jù)庫執(zhí)行的SQL腳本命令獲取的結(jié)果集對(duì)象ResultSet中提供的一些信息,比如結(jié)果集中的列數(shù)、指定列的名稱、指 定列的SQL類型等等,可以說這個(gè)是對(duì)于框架來說非常重要的一個(gè)對(duì)象。 以下有一些關(guān)于ResultSetMetaData的常用方法:

getColumnCount:獲取結(jié)果集中列項(xiàng)目的個(gè)數(shù)
getColumnType:獲取指定列的SQL類型對(duì)應(yīng)于Java中Types類的字段
getColumnTypeName:獲取指定列的SQL類型
getClassName:獲取指定列SQL類型對(duì)應(yīng)于Java中的類型(包名加類名@Test
public void testResultSetMetaData() throws Exception {
String sql = "select * from health.t_checkgroup where id=?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "7");
//執(zhí)行sql語句
ResultSet rs = pstmt.executeQuery();
//獲取ResultSetMetaData對(duì)象
ResultSetMetaData metaData = rs.getMetaData();
//獲取查詢字段數(shù)量
int columnCount = metaData.getColumnCount();
System.out.println("字段總數(shù)量:"+ columnCount);
for (int i = 1; i <= columnCount; i++) {
//獲取表名稱
System.out.println(metaData.getColumnName(i));
//獲取java類型
System.out.println(metaData.getColumnClassName(i));
//獲取sql類型
System.out.println(metaData.getColumnTypeName(i));
System.out.println("———-");
}
}4 代碼生成器環(huán)境搭建4.1 創(chuàng)建maven工程

創(chuàng)建maven工程并導(dǎo)入以下依賴

<properties>
<java.version>11</java.version>
<!– 項(xiàng)目源碼及編譯輸出的編碼 –>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!– 項(xiàng)目編譯JDK版本 –>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
</dependencies>

目錄結(jié)構(gòu)如下

hp m1005打印機(jī)驅(qū)動(dòng)下載

拓展知識(shí):

原創(chuàng)文章,作者:九賢生活小編,如若轉(zhuǎn)載,請(qǐng)注明出處:http://www.cddhlm.com/64544.html