当前位置:网站首页>22-07-04 Xi'an Shanghao housing project experience summary (01)
22-07-04 Xi'an Shanghao housing project experience summary (01)
2022-07-05 09:20:00 【£ small feather】
Shanghao house is a second-hand house management service platform , Open up high-quality resources and online capabilities , Aggregate online and offline second-hand real estate resources , Create an all-round second-hand housing service ecological market , Provide consumers with high-quality real estate service resources .
Understand the project business according to the demonstration
Shanghao room backstage management system : Authority management system
Front end of Shanghao house : Find Fangwang
Surprised : Extract common modules
BaseController, It's really simple , But considering everyone in the future Controller You need to use the two lines of encapsulated code ,
In addition , After modification and addition, you will get . It's for consumers Controller inherited .
public class BaseController {
private final static String PAGE_SUCCESS = "common/successPage";
public String successPage(Model model, String successMessage){
model.addAttribute("messagePage",successMessage);
return PAGE_SUCCESS;
}
}
BaseService It is used for middlemen “service-api” To inherit ,
Its contents are as follows , Inheriting it is equivalent to Service There are five general methods of adding, deleting, modifying and checking
public interface BaseService<T> {
void insert(T t);
T getById(Long id);
/**
* Logical deletion
* @param id
*/
void delete(Long id);
/**
* Modify the information
* @param t
*/
void update(T t);
/**
* Paging query information
* @param filters
* @return
*/
PageInfo<T> findPage(Map<String, Object> filters);
}
BaseServiceImpl and BaseMapper Let the service provider use inheritance . Write specific business logic , A write operation on the database .
here BaseServiceImpl Is an abstract class , There is an abstract method in it getEntityMapper(), This method is to allow subclasses that inherit it to override it , Really mapper Interface to him , He can help you call methods
public abstract class BaseServiceImpl<T> {
/**
* This abstract method is used to obtain the real mapper Interface
* @return
*/
protected abstract BaseMapper<T> getEntityMapper();
public void insert(T t) {
getEntityMapper().insert(t);
}
@Transactional(propagation = Propagation.SUPPORTS)
public T getById(Long id) {
return getEntityMapper().getById(id);
}
public void delete(Long id) {
getEntityMapper().delete(id);
}
public void update(T t) {
getEntityMapper().update(t);
}
@Transactional(propagation = Propagation.SUPPORTS)
public PageInfo<T> findPage(Map<String, Object> filters) {
// take pageSize and pageNum Strong conversion int type
// The second parameter indicates the default value if the forced conversion fails
int pageNum = CastUtil.castInt(filters.get("pageNum"),1);
int pageSize = CastUtil.castInt(filters.get("pageSize"),10);
// Open paging
PageHelper.startPage(pageNum,pageSize);
// Call the methods of the persistence layer to query the data set
// Encapsulation return result , The teacher didn't pass the second parameter here
return new PageInfo<>(getEntityMapper().findPage(filters),10);
}
}
Finally, this BaseMapper 了 , Every one we create mapper Interfaces should inherit this interface , So our mapper Interface can omit the five most commonly used methods
public interface BaseMapper<T> {
/**
* Save an entity
* @param t
*/
void insert(T t);
/**
* Through a sign ID Get a unique entity
* @param id
* @return
*/
T getById(Long id);
/**
* modify
* @param t
*/
void update(T t);
/**
* Delete
* @param id
*/
void delete(Long id);
/**
* Paging query
* @param filters
* @return
*/
Page<T> findPage(Map<String, Object> filters);
}
surprised 2、 Dictionaries
The dictionary itself is cleverly designed
The visual effect of this page is also very nice: This tree like directory looks very advanced , In fact, what the back end returns to the front end is only one json Array .
java Back end code :
The back-end logic is very simple , According to the id To query all child nodes , Use the found data Stream Flow to finish .
2021/11/12 Beijing stream flow , Inner class ,lambda expression _£ Little feather's blog -CSDN Blog
public List<Map<String, Object>> findZnodes(Long id) {
//1. Call persistence layer methods , According to the parent node id Inquire about List<Dict>
List<Dict> dictList = dictMapper.findListByParentId(id);
// Use Stream flow
List<Map<String, Object>> znodes = dictList.stream()
.map(dict -> {
Map<String, Object> znode = new HashMap<>();
// Go to znode In the store id
znode.put("id", dict.getId());
// Go to znode In the store name
znode.put("name", dict.getName());
// Go to znode In the store isParent
znode.put("isParent", dictMapper.countIsParent(dict.getId()) > 0);
return znode;
})
.collect(Collectors.toList());
return znodes;
}
stay SQlyog The following is executed in sql:
-- According to the id To query all child nodes
SELECT * FROM hse_dict WHERE parent_id =1
Click all categories
Observe network, Sent such a request , That's the kind of situation we analyzed above
http://139.198.152.148:8001/dict/findZnodes?id=1
Back to the front end json data : In fact, the return is still json Array .
{
"code": 200,
"data": [
{
"isParent": true,
"name": " House type ",
"id": 10000
},
{
"isParent": true,
"name": " floor ",
"id": 20000
},
{
"isParent": true,
"name": " Building structure ",
"id": 30000
},
{
"isParent": true,
"name": " Decoration ",
"id": 40000
},
{
"isParent": true,
"name": " toward ",
"id": 50000
},
{
"isParent": true,
"name": " The purpose of the house is ",
"id": 60000
},
{
"isParent": true,
"name": " province ",
"id": 100000
}
],
"message": " success ",
"ok": true
}
Let's click on the house type , Then send a request to query
http://139.198.152.148:8001/dict/findZnodes?id=10000
Back to the front end json The array is as follows :
{
"code": 200,
"data": [
{
"isParent": false,
"name": " A room ",
"id": 10001
},
{
"isParent": false,
"name": " Two rooms ",
"id": 10002
},
{
"isParent": false,
"name": " Three rooms ",
"id": 10003
},
{
"isParent": false,
"name": " Four rooms ",
"id": 10004
},
{
"isParent": false,
"name": " More than four rooms ",
"id": 10005
}
],
"message": " success ",
"ok": true
}
Two uses of enumeration :
usage 1: Listing release status HouseStatus
public enum HouseStatus {
// Unpublished means that users cannot see , But the background management system can see
PUBLISHED(1," The published "), UNPUBLISHED(0," Unpublished ");
public int code;
public String message;
HouseStatus(int code, String message) {
this.code = code;
this.message = message;
}
}
Use when adding listing information :
@PostMapping("/save")
public String save(House house,Model model){
// Unpublished
house.setStatus(HouseStatus.UNPUBLISHED.code);
houseService.insert(house);
return successPage(model," Add housing information successfully ");
}
Enumeration usage 2: Define as private variable .
public enum DictCode {
HOUSETYPE("houseType"),FLOOR("floor"),BUILDSTRUCTURE("buildStructure"),
DECORATION("decoration"),DIRECTION("direction"),HOUSEUSE("houseUse");
private String message;
DictCode(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}
Use :
//3. Query various initialization lists : List of house types 、 Floor list 、 Decoration list ....
List<Dict> houseTypeList =
dictService.findDictListByParentDictCode(DictCode.HOUSETYPE.getMessage());
getListingDateString() House class
stay show.html in
<dt> Listing time :</dt><dd th:text="${house.listingDateString}"></dd>
<dt> Last deal :</dt><dd th:text="${house.lastTradeDateString}"></dd>
But actually House These two properties are not in this class , Only the following two Date attribute , So how to display the data on the page
- Listing date private Date listingDate;
- Last transaction date private Date lastTradeDate;
An important knowledge point , stay thymeleaf In the syntax , In the request domain get Method to get value . So it's actually House This class has two more methods . Wonderful , Maggie wonderful house
/**
* Get the listing date in string type
* @return
*/
public String getListingDateString() {
Date date = this.getListingDate();
if(null == date) {
return "";
}
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String dateString = df.format(date);
return dateString;
}
/**
* Get the last transaction date in string
* @return
*/
public String getLastTradeDateString() {
Date date = this.getLastTradeDate();
if(null == date) {
return "";
}
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String dateString = df.format(date);
return dateString;
}
边栏推荐
- 高性能Spark_transformation性能
- C form click event did not respond
- A detailed explanation of the general process and the latest research trends of map comparative learning (gnn+cl)
- Wxml template syntax
- Applet network data request
- Ministry of transport and Ministry of Education: widely carry out water traffic safety publicity and drowning prevention safety reminders
- [reading notes] Figure comparative learning gnn+cl
- [ctfhub] Title cookie:hello guest only admin can get flag. (cookie spoofing, authentication, forgery)
- 520 diamond Championship 7-4 7-7 solution
- 编辑器-vi、vim的使用
猜你喜欢
Introduction Guide to stereo vision (7): stereo matching
Figure neural network + comparative learning, where to go next?
Generate confrontation network
nodejs_ fs. writeFile
AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
Wxml template syntax
The research trend of map based comparative learning (gnn+cl) in the top paper
利用请求头开发多端应用
Creation and reference of applet
什么是防火墙?防火墙基础知识讲解
随机推荐
2310. The number of bits is the sum of integers of K
Multiple linear regression (gradient descent method)
Kotlin introductory notes (VII) data class and singleton class
Uni app implements global variables
驾驶证体检医院(114---2 挂对应的医院司机体检)
LeetCode 556. 下一个更大元素 III
Kotlin introductory notes (VIII) collection and traversal
Nodemon installation and use
2311. 小于等于 K 的最长二进制子序列
[ctfhub] Title cookie:hello guest only admin can get flag. (cookie spoofing, authentication, forgery)
Confusion matrix
深入浅出PyTorch中的nn.CrossEntropyLoss
Wxml template syntax
[code practice] [stereo matching series] Classic ad census: (5) scan line optimization
Talking about the difference between unittest and pytest
测试老鸟浅谈unittest和pytest的区别
Applet (global data sharing)
一次 Keepalived 高可用的事故,让我重学了一遍它
2310. 个位数字为 K 的整数之和
Newton iterative method (solving nonlinear equations)