In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Preface
Thymeleaf is a modern server-side Java template engine for Web and stand-alone environments. The main goal of Thymeleaf is to bring elegant natural templates into your development workflow-HTML can be displayed correctly in the browser and can be used as a static prototype to achieve stronger collaboration in the development team. Thymeleaf can handle HTML,XML,JavaScript,CSS or even plain text.
Spring-boot-starter-web integrates Tomcat and Spring MVC, and automatically configures related things. Thymeleaf is a widely used template engine.
Update pom.xml
Org.springframework.boot
Spring-boot-starter-thymeleaf
Update application.properties
# thymeleaf
Spring.thymeleaf.cache=false
Spring.thymeleaf.prefix=classpath:/templates/
Spring.thymeleaf.check-template-location=true
Spring.thymeleaf.suffix=.html
Spring.thymeleaf.encoding=UTF-8
Spring.thymeleaf.mode=HTML5
Create Controller
The reason for creating a new Controller instead of reusing the previous IndexController is that IndexController uses the @ RESTController annotation.
Using the @ Controller annotation, the view parser can parse return's jsp,html page and jump to the corresponding page on the corresponding method. If you return json and other content to the page, you need to add @ ResponseBody annotation.
@ RestController annotation is equivalent to the combination of @ Controller+@ResponseBody annotation. To return json data, you do not need to add @ ResponseBody annotation in front of the method, but using @ RestController annotation, you cannot return the jsp,html page. The view parser cannot parse the jsp,html page.
Create a new UserController:
Package com.demo.controller
Import com.demo.pojo.UserPosition
Import com.demo.service.UserService
Import org.springframework.beans.factory.annotation.Autowired
Import org.springframework.stereotype.Controller
Import org.springframework.ui.Model
Import org.springframework.web.bind.annotation.RequestMapping
Import java.math.BigDecimal
Import java.util.List
/ * *
Created by toutou on 2018-10-20.
, /
@ Controller
Public class UserController {
@ Autowired
UserService userService
@ RequestMapping (value = "/ mynearby")
Public String myNearby (Model model, double lon, double lat)
{
Double r = 6371 pm / kilometer radius of the earth
Double dis = 2; / / Radius unit: km
Double dlng = 2Math.asin (Math.sin (dis/ (2R)) / Math.cos (lat*Math.PI/180))
Dlng = dlng*180/Math.PI;// Angle to Radian
Double dlat = dis/r
Dlat = dlat*180/Math.PI
Double minlat = lat-dlat
Double maxlat = lat+dlat
Double minlng = lon-dlng
Double maxlng = lon + dlng
List list = userService.getVicinity (BigDecimal.valueOf (minlng), BigDecimal.valueOf (maxlng), BigDecimal.valueOf (minlat), BigDecimal.valueOf (maxlat))
Model.addAttribute ("myinfo", list)
Return "mynearby"
}
}
Create a page
/ src/main/resources/templates/mynearby.html
A nearby neighborhood
My coordinates
116.31064,40.062658
A nearby neighborhood
Delete
/ / var single = [[${singlePerson}]]
/ / console.log (single.name+ "/" + single.age)
$(function () {)
$(".btn") .click (function () {
Alert ("deleting function is improving...")
});
});
The xmlns:th= "http://www.thymeleaf.org" namespace transforms the shot into a dynamic view, and the elements that need to be dynamically processed use the" th: "prefix; two link are introduced into the bootstrap framework to access the data in the model by introducing web static resources (resource paths in parentheses) through @ {}.
Running effect:
Directory structure:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.