Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
//html 布局
<view v-html="html">
{{html}}
</view>
//動(dòng)態(tài)生成的元素
<view class="btngo" @tap="handleLink(`${ajaxlink}`)" >
去報(bào)名
</view>
//然后scoped的.btngo不生效,因?yàn)関-html創(chuàng)建的DOM內(nèi)容不受作用域內(nèi)的樣式影響,
//于是我們?nèi)匀豢梢酝ㄟ^深度作用選擇器來為他們?cè)O(shè)置樣式。
::v-deep {
.btngo{
display: inline-block;
width: 200px;
height: 44px;
line-height: 44px;
background-image: linear-gradient(180deg, #62AFFF 0%, #007BFF 100%);
}
}
讓我醍醐灌頂?shù)膬煞N解決方法,我選擇了第2種。
pring Boot中,你可能想要基于動(dòng)態(tài)內(nèi)容生成靜態(tài)HTML頁面。有幾種方法可以實(shí)現(xiàn)這一目標(biāo),以下是其中的一些方法:
下面是一個(gè)使用Thymeleaf的簡(jiǎn)單示例:
@Service
public class StaticHtmlGeneratorService {
@Autowired
private TemplateEngine templateEngine;
@Autowired
private ApplicationContext applicationContext;
public void generateStaticHtml(String templateName, Map<String, Object> context, String outputPath) {
Context thContext = new Context();
thContext.setVariables(context);
String processedHtml = templateEngine.process(templateName, thContext);
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputPath))) {
writer.write(processedHtml);
} catch (IOException e) {
// Handle exception
}
}
}
這段代碼不是完整的實(shí)現(xiàn),因?yàn)門emplateEngine類并不是Spring Boot標(biāo)準(zhǔn)庫中的一部分。在實(shí)際應(yīng)用中,你會(huì)使用具體的模板引擎的API(例如Thymeleaf的TemplateEngine),并相應(yīng)地調(diào)整代碼。
實(shí)際上,Spring Boot集成Thymeleaf后,你會(huì)這樣使用Thymeleaf的API:
@Autowired
private SpringTemplateEngine templateEngine;
public void generateStaticHtml(String templateName, Map<String, Object> contextVars, String outputPath) {
Context context = new Context();
context.setVariables(contextVars);
String processedHtml = templateEngine.process(templateName, context);
// Write the processedHtml to a file
// ...
}
public void generateStaticHtmlWithJsoup(String title, String bodyContent, String outputPath) throws IOException {
Document doc = Jsoup.parse("<html><head><title></title></head><body></body></html>");
doc.title(title);
doc.body().append(bodyContent);
// 美化輸出(Pretty-print)
doc.outputSettings().prettyPrint(true);
// 寫入文件
Files.write(Paths.get(outputPath), doc.outerHtml().getBytes(StandardCharsets.UTF_8));
}
@Autowired
private RestTemplate restTemplate;
public void generateStaticHtmlFromWebService(String url, String outputPath) throws IOException {
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
if (response.getStatusCode() == HttpStatus.OK) {
Files.write(Paths.get(outputPath), response.getBody().getBytes(StandardCharsets.UTF_8));
}
}
在生成靜態(tài)HTML時(shí),請(qǐng)考慮以下幾點(diǎn):
Java實(shí)現(xiàn)根據(jù)svg模版動(dòng)態(tài)生成圖片
需要Java語言動(dòng)態(tài)生成圖片
用流程圖簡(jiǎn)單說明下我這邊工作中使用的場(chǎng)景
僅供參考
所以這里就需要生成證書了
我先給大家看下最終實(shí)現(xiàn)的圖片效果
這里要先說明一下
下面說下我是如何解決的
這種方式是不能實(shí)現(xiàn)這個(gè)需求的
這個(gè)的原理就是對(duì)網(wǎng)頁截圖 但只能對(duì)于靜態(tài)頁面截圖 不能根據(jù)不同的參數(shù)值動(dòng)態(tài)生成圖片
所以不提倡使用這種方式
但也介紹下這種使用方式 朋友們根據(jù)自己的實(shí)際需求情況有選擇的使用
這是h5代碼
test文件夾下面的內(nèi)容
安裝一個(gè)docker nginx 將test文件夾加載到nginx容器的/usr/share/nginx/html目錄下面
docker run --name nginx80 -p 8000:80 -v /tmp/test:/usr/share/nginx/html -d docker.io/nginx
訪問的頁面效果
這張圖片是截圖生成的圖片 但url中的id值并沒有傳給頁面
在h5代碼中請(qǐng)求后端接口獲取數(shù)據(jù)動(dòng)態(tài)顯示出來也是不可以的
所以這種方式使用局限性很窄
大致原理是 通過http請(qǐng)求該url獲取該url的文件流然后解析h5代碼生成圖片
其實(shí)現(xiàn)原理大致為 讀取svg document h5代碼 將動(dòng)態(tài)參數(shù)map解析到h5代碼中 轉(zhuǎn)換成字節(jié)數(shù)組 生成圖片格式
我本地是mac系統(tǒng)沒有這個(gè)問題 在發(fā)布到測(cè)試環(huán)境linux系統(tǒng)出現(xiàn)了這個(gè)問題
先看下問題的現(xiàn)象
看到了沒 生成的圖片中文全是亂碼
原因是因?yàn)閘inux系統(tǒng)沒有中文字體
既然linux系統(tǒng)沒有中文字體 那么就安裝它嘛 let's 盤它!!!
brew install fontconfig
fc-list :lang=zh (注意‘:’前的空格)
mac環(huán)境默認(rèn)會(huì)安裝很多中文字體
yum -y install fontconfig
fc-list :lang=zh
果然沒有中文字體
a 先在mac系統(tǒng)中找到字體安裝目錄
/System/Library/Fonts
b 找到宋體對(duì)應(yīng)的文件
c 將該文件上傳到linux指定的目錄下
/usr/share/fonts/chinese
d 賦予文件夾操作權(quán)限
chmod -R 755 /usr/share/fonts/chinese
e 安裝ttmkfdir來搜索目錄中所有的字體信息,并匯總生成fonts.scale文件
yum -y install ttmkfdir
ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir
vi /etc/fonts/fonts.conf
添加
<dir>/usr/share/fonts/chinese</dir>
fc-cache
a 找到j(luò)dk所在的安裝目錄
echo $JAVA_HOME
b 將宋體文件復(fù)制過來
cp /usr/share/fonts/chinese/STHeiti\ Light.ttc /usr/local/software/jdk1.8.0_141/jre/lib/fonts/fallback
fallback代表存放后備語言的文件夾
https://gitee.com/pingfanrenbiji/resource/tree/master/image
注意: 引入的依賴問題
<!--phantomjs -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>com.github.detro</groupId>
<artifactId>ghostdriver</artifactId>
<version>2.1.0</version>
</dependency>
<!--svg-->
<dependency>
<groupId>com.github.hui.media</groupId>
<artifactId>svg-core</artifactId>
<version>2.5</version>
</dependency>
這些依賴jar包我是上傳到了公司的私服上了
若是朋友們下拉不下來
我提供給大家這些底層jar包的實(shí)現(xiàn)源碼
https://gitee.com/pingfanrenbiji/quick-media
自行上傳到自己的私服即可
*請(qǐng)認(rèn)真填寫需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。