当前位置:网站首页>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;
}边栏推荐
- notepad++
- [code practice] [stereo matching series] Classic ad census: (4) cross domain cost aggregation
- 【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
- 顶会论文看图对比学习(GNN+CL)研究趋势
- Rebuild my 3D world [open source] [serialization-2]
- Information and entropy, all you want to know is here
- Can't find the activitymainbinding class? The pit I stepped on when I just learned databinding
- Introduction Guide to stereo vision (1): coordinate system and camera parameters
- Codeworks round 639 (Div. 2) cute new problem solution
- Kotlin introductory notes (VI) interface and function visibility modifiers
猜你喜欢

Nips2021 | new SOTA for node classification beyond graphcl, gnn+ comparative learning

Shutter uses overlay to realize global pop-up

Editor use of VI and VIM
![一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]](/img/c4/27ae0d259abc4e61286c1f4d90c06a.png)
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]

Solution to the problems of the 17th Zhejiang University City College Program Design Competition (synchronized competition)

22-07-04 西安 尚好房-项目经验总结(01)

Generate confrontation network

My experience from technology to product manager

Newton iterative method (solving nonlinear equations)

Progressive JPEG pictures and related
随机推荐
云计算技术热点
高性能Spark_transformation性能
Luo Gu p3177 tree coloring [deeply understand the cycle sequence of knapsack on tree]
Priority queue (heap)
Creation and reference of applet
Codeforces round 684 (Div. 2) e - green shopping (line segment tree)
Nodejs modularization
Codeworks round 681 (Div. 2) supplement
It's too difficult to use. Long articles plus pictures and texts will only be written in short articles in the future
LeetCode 31. 下一个排列
C language - input array two-dimensional array a from the keyboard, and put 3 in a × 5. The elements in the third column of the matrix are moved to the left to the 0 column, and the element rows in ea
np. allclose
[code practice] [stereo matching series] Classic ad census: (4) cross domain cost aggregation
Introduction Guide to stereo vision (6): level constraints and polar correction of fusiello method
Applet global style configuration window
Kotlin introductory notes (VII) data class and singleton class
Codeforces Round #648 (Div. 2) D. Solve The Maze
What is a firewall? Explanation of basic knowledge of firewall
VS Code问题:长行的长度可通过 “editor.maxTokenizationLineLength“ 进行配置
Rebuild my 3D world [open source] [serialization-3] [comparison between colmap and openmvg]