当前位置:网站首页>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;
}边栏推荐
- Uni app implements global variables
- Multiple linear regression (gradient descent method)
- Golang foundation -- map, array and slice store different types of data
- 我的一生.
- 2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
- Analysis of eventbus source code
- 【PyTorch Bug】RuntimeError: Boolean value of Tensor with more than one value is ambiguous
- 深入浅出PyTorch中的nn.CrossEntropyLoss
- Composition of applet code
- Ministry of transport and Ministry of Education: widely carry out water traffic safety publicity and drowning prevention safety reminders
猜你喜欢

LeetCode 31. 下一个排列

Editor use of VI and VIM

Node collaboration and publishing

什么是防火墙?防火墙基础知识讲解

Codeworks round 639 (Div. 2) cute new problem solution

Nodejs modularization

RT thread kernel quick start, kernel implementation and application development learning with notes
![[reading notes] Figure comparative learning gnn+cl](/img/44/2e13d63ef654663852cbccb342b838.png)
[reading notes] Figure comparative learning gnn+cl

Applet (global data sharing)

一篇文章带你走进cookie,session,Token的世界
随机推荐
[beauty of algebra] solution method of linear equations ax=0
520 diamond Championship 7-4 7-7 solution
notepad++
C#绘制带控制点的Bezier曲线,用于点阵图像及矢量图形
My experience from technology to product manager
一篇文章带你走进cookie,session,Token的世界
Codeforces Round #648 (Div. 2) E.Maximum Subsequence Value
uni-app 实现全局变量
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
22-07-04 西安 尚好房-项目经验总结(01)
An article takes you into the world of cookies, sessions, and tokens
Greendao reported an error in qigsaw, could not init daoconfig
RT thread kernel quick start, kernel implementation and application development learning with notes
2311. 小于等于 K 的最长二进制子序列
信息與熵,你想知道的都在這裏了
Global configuration tabbar
Codeworks round 638 (Div. 2) cute new problem solution
Driver's license physical examination hospital (114-2 hang up the corresponding hospital driver physical examination)
Generate confrontation network
Nodejs modularization