preface
Is dubious
One, the background
1. Entity
I don’t have to say much
@table (name = "Table name ")
public classThe entity name{
@column (name = "name ")
privateType field name; . Ditto}Copy the code
2. The interface
It’s a way of defining what to do, okay
public interfaceThe interface nameextends Mapper< entity name >{List< entity name > method name (Map<String,Object> params); }Copy the code
3.XML
Method how to do the specific implementation (add, delete, change, check – also known as :CRUD) don’t when the interviewer ask you CRUD, you say you haven’t heard of oh interface and entity path know, right-click interface or entity, select copy Reference
<mapper namespace="Interface path">
<resultMap type="Path of substance" id="Give me an ID.">
<result property="Field name" column="Field name"/>. Same as above</resultMap>
<select id="Method name in interface" resultMap="Id name on top">SELECT * FROM table name WHERE condition</select>
</mapper>
Copy the code
4. Interface implementation classes
TableResultResponse is a paginated thing
public className of the interface implementation class{
@Autowired
privateInterface name Interface name lowercase;publicTableResultResponse implementation class method name (Query Query){Page<Object> result = PageHelper.startPage(query.getPageNo(),query.getPageSize()); List< entity name > List = Interface name lowercase. The method name (query);// This should be a paginated object before and after the main line of code
return newTableResultResponse( result.getPageSize(),result.getPageNum(),result.getPages(),result.getTotal(),list ); }}Copy the code
5. Control layer
@RestController
@requestMapping (" Create a pathname ")
public classControl layer,extends{
@Autowired
privateInterface implementation class name Interface implementation class name lowercase;@requestMapping (value = "pathname ",method = requestmethod.get)
publicTableResultResponse method name (@RequestParam Map<String,Object> params){
Query query = new Query(params);
returnThe interface implementation class name is lowercase. Interface implementation class method name (query); }}Copy the code
The front desk
1.JS
constAPI = {method name:'path'// The background path
}
export functionGive a method name (parameter) {
return axios({
url: API. The above method name,method: 'get'.params: parameter
})
}
Copy the code
2.VUE
<template>
<a-checkbox v-for="(item,index) in list" :key="item.key">{{item.title}}</a-checkbox>
<script>
import{method name of the above function}from '@/api/admin'
export default {
data() {
return {
list: [].// Multiple options returned in the background
created() {
this.method name ()},methods: {method name (item){method name (). Then ()res= > {
const result = res.result.data
result.forEach((res) = > {
this.list.push({ 'key': res.id, 'title': res. field name})})})}</script>
Copy the code
conclusion
Good cooks never say die