文章目录  user_index.html myaccount_style.css myaccount_scripts.js address_edit.html ReceiverAddress ReceiverAddressController ReceiverAddressServiceImpl IReceiverAddressService R FshopAppApplication ServletInitializer pom.xml ReceiverAddressMapper.xml ReceiverAddressMapper.java   
 
<! DOCTYPE  html > < htmllang = " zh-CN" > < head> < metacharset = " UTF-8" > < metaname = " viewport" content = " width=device-width, initial-scale=1.0" > < title> </ title> < linkrel = " stylesheet" href = " myaccount_style.css" > < scriptsrc = " ../common/jquery-3.3.1.min.js" > </ script> < scriptsrc = " myaccount_scripts.js" > </ script> </ head> < main> < aside> < nav> < ul> < li> < ahref = " #" data-page = " my_coupons" > </ a> </ li> < li> < ahref = " #" data-page = " my_addresses" > </ a> </ li> </ ul> </ nav> </ aside> < divid = " content-area" > </ div> < buttonid = " addNewAddressBtn" class = " add-address-btn" > </ button> < divid = " content-area-address" > < formid = " newAddressForm" style = " display :  none; " > < inputtype = " hidden" id = " userId" name = " userId" value = " " > < inputtype = " hidden" id = " receiveAddressId" name = " receiveAddressId" value = " " > < divclass = " form-group" > < labelfor = " receiverName" > </ label> < inputtype = " text" id = " receiverName" name = " receiverName" placeholder = " 请输入收件人姓名" required > </ div> < divclass = " form-group" > < labelfor = " receiverPhone" > </ label> < inputtype = " tel" id = " receiverPhone" name = " receiverPhone" placeholder = " 请输入收件人电话号码" required > </ div> < divclass = " form-group" > < labelfor = " receiverProvince" > </ label> < selectid = " receiverProvince" name = " receiverProvince" required > < optionvalue = " " > </ option> </ select> </ div> < divclass = " form-group" > < labelfor = " receiverCity" > </ label> < selectid = " receiverCity" name = " receiverCity" required > < optionvalue = " " > </ option> </ select> </ div> < divclass = " form-group" > < labelfor = " receiverArea" > </ label> < selectid = " receiverArea" name = " receiverArea" required  disabled > < optionvalue = " " > </ option> </ select> </ div> < divclass = " form-group" > < labelfor = " receiverStreet" > </ label> < selectid = " receiverStreet" name = " receiverStreet" required  disabled > < optionvalue = " " > </ option> </ select> </ div> < divclass = " form-group" > < labelfor = " receiverDetail" > </ label> < textareaid = " receiverDetail" name = " receiverDetail" placeholder = " 请输入详细地址" required > </ textarea> </ div> < divclass = " form-group" > < label> < inputtype = " radio" id = " isDefaultYes" name = " isDefault" value = " 1" > </ label> < label> < inputtype = " radio" id = " isDefaultNo" name = " isDefault" value = " 0" checked > </ label> </ div> < divclass = " form-actions" > < inputtype = " submit" value = " 保存" > < buttontype = " button" class = " cancel-new-address-btn" > </ button> </ div> </ form> </ div> < divid = " content-area-review" > </ div> </ main> < divid = " my_coupons-list-template" style = " display :  none; " > < divclass = " content-block coupon-list" > < h2> </ h2> < divclass = " coupon-item" > < p> </ p> </ div> < divclass = " coupon-item" > < p> </ p> </ div> </ div> </ div> < divid = " my_addresses-list-template" style = " display :  none; " > < divclass = " content-block address-list" > < h2> </ h2> < divclass = " address-item" > < p> </ p> < buttonclass = " edit-btn" > </ button> < buttonclass = " delete-btn" > </ button> </ div> </ div> </ div> </ body> </ html> 
body  { font-family :  Arial,  sans-serif; margin :  0; padding :  0; 
} header  { background-color :  #f2f2f2; padding :  15px; box-shadow :  0 2px 4px rgba ( 0,  0,  0,  0.1) ;  
} main  { display :  flex; margin-top :  20px;  
} aside  { width :  20%;  background-color :  #fff; border-right :  1px solid #ddd;  box-shadow :  2px 0 4px rgba ( 0,  0,  0,  0.1) ;  padding :  20px; 
} nav ul  { list-style :  none; padding :  0; } 
nav ul li a  { display :  block; padding :  10px; text-decoration :  none; color :  #333; transition :  background-color 0.3s ease; border-radius :  5px;  } nav ul li a.active,nav ul li a:hover  { color :  #fff;  background-color :  #f00;  
} 
.address-item  { border :  1px solid #ddd;  border-radius :  5px;  padding :  10px;  margin-bottom :  20px;  box-shadow :  0 2px 4px rgba ( 0,  0,  0,  0.05) ;  transition :  all 0.3s ease;   
} .address-item button  {  padding :  5px 10px;  font-size :  12px;  margin-right :  5px;  
} .address-item:hover  { box-shadow :  0 4px 8px rgba ( 0,  0,  0,  0.1) ;  transform :  translateY ( -2px) ;  
} 
.edit-form  { display :  none;  margin-top :  10px;  padding :  10px;  border :  1px solid #ccc;  border-radius :  5px;  background-color :  #f5f5f5;  position :  absolute;  width :  100%;  z-index :  10;  box-shadow :  0 2px 8px rgba ( 0,  0,  0,  0.1) ;  
} 
.edit-form input[type="text"]  { width :  100%;  padding :  5px;  margin-bottom :  10px;  
} .edit-form button  { padding :  5px 10px;  margin-right :  5px;  background-color :  #4CAF50;  border :  none;  color :  white;  cursor :  pointer;  
} 
.edit-form .cancel-new-address-btn  { padding :  5px 10px; margin-right :  5px; background-color :  #f44336;  border :  none; color :  white; cursor :  pointer; 
} 
#content-area  { padding :  30px;  
} #content-area div  { display :  none;  
} #content-area div.active  { display :  block;  
} 
nav ul li a.active  { border-bottom-color :  #f00;  
} 
#addNewAddressBtn  { margin-top :  20px;  
} 
.address-list h2  { font-size :  18px;  font-weight :  bold;  color :  #333;  margin-bottom :  20px;  text-align :  left;  
} 
.address-list  { background-color :  #fff;  border :  1px solid #ddd;  padding :  10px;  
} 
.add-address-btn  { padding :  5px 10px;  font-size :  14px;  position :  absolute;  top :  20px;  right :  20px;  z-index :  10;  display :  inline-block;  color :  white;  background-color :  #4CAF50;  border :  none;  border-radius :  5px;  cursor :  pointer;  transition :  background-color 0.3s ease;  
} .add-address-btn:hover  { background-color :  #45a049;  
} 
.add-address-btn.active  { opacity :  0.6;  cursor :  not-allowed;  
} 
#newAddressForm  { background-color :  #fff;  border :  1px solid #ccc;  border-radius :  5px;  padding :  20px;  box-shadow :  0 2px 4px rgba ( 0,  0,  0,  0.1) ;  margin-top :  20px;  width :  100%;  max-width :  600px;  
} #newAddressForm label  { display :  block;  margin-bottom :  10px;  font-weight :  bold;  
} #newAddressForm input[type="text"],
#newAddressForm input[type="tel"],
#newAddressForm textarea  { width :  100%;  padding :  10px;  border :  1px solid #ddd;  border-radius :  4px;  box-sizing :  border-box;  
} #newAddressForm textarea  { height :  100px;  resize :  vertical;  
} #newAddressForm select  { width :  100%;  padding :  10px;  border :  1px solid #ddd;  border-radius :  4px;  
} #newAddressForm .form-group  { margin-bottom :  20px;  
} #newAddressForm .form-actions  { text-align :  right;  margin-top :  20px;  
} #newAddressForm .form-actions button  { padding :  10px 20px;  margin-left :  10px;  border :  none;  border-radius :  4px;  cursor :  pointer;  
} #newAddressForm .form-actions .save-btn  { background-color :  #4CAF50;  color :  #fff;  
} #newAddressForm .form-actions .cancel-btn  { background-color :  #f44336;  color :  #fff;  
} 
@media  ( max-width :  768px) { aside, #content-area  { width :  100%;  border-right :  none;  } main  { flex-direction :  column;  } aside  { margin-bottom :  20px;  } .add-address-btn  { top :  10px; right :  10px; padding :  3px 8px; font-size :  12px; } .address-list h2  { font-size :  16px; } .address-item  { margin-bottom :  10px; } } $ ( document) . ready ( function ( )  { var  currentPage =  '未赋值' ;  var  provinces =  [ { name :  '省份1' , cities :  [ {  name :  '城市1' ,  areas :  [ {  name :  '县区1' ,  streets :  [ '街道1-1' ,  '街道1-2' ]  } ,  {  name :  '县区2' ,  streets :  [ '街道2-1' ,  '街道2-2' ]  } ]  } , ] } , { name :  '省份2' , cities :  [ {  name :  '城市3' ,  areas :  [ {  name :  '县区3' ,  streets :  [ '街道3-1' ,  '街道3-2' ]  } ]  } , ] } , ] ; function  initProvinceSelect ( )  { var  $provinceSelect =  $ ( '#receiverProvince' ) ; $provinceSelect. empty ( ) ; $provinceSelect. append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; $. each ( provinces,  function ( index,  province )  { $provinceSelect. append ( $ ( '<option>' ) . val ( province. name) . text ( province. name) ) ; } ) ; } function  initCitySelect ( provinceName )  { var  $citySelect =  $ ( '#receiverCity' ) ; $citySelect. empty ( ) ; $citySelect. append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; var  $areaSelect =  $ ( '#receiverArea' ) ; $areaSelect. empty ( ) . append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; $areaSelect. prop ( 'disabled' ,  true ) ; var  $streetSelect =  $ ( '#receiverStreet' ) ; $streetSelect. empty ( ) . append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; $streetSelect. prop ( 'disabled' ,  true ) ; $. each ( provinces,  function ( index,  province )  { if  ( province. name ===  provinceName)  { $. each ( province. cities,  function ( cityIndex,  city )  { $citySelect. append ( $ ( '<option>' ) . val ( city. name) . text ( city. name) ) ; } ) ; return  false ;  } } ) ; } function  initAreaSelect ( cityName )  { var  $areaSelect =  $ ( '#receiverArea' ) ; $areaSelect. empty ( ) ; $areaSelect. append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; var  $streetSelect =  $ ( '#receiverStreet' ) ; $streetSelect. empty ( ) . append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; $streetSelect. prop ( 'disabled' ,  true ) ; $. each ( provinces,  function ( index,  province )  { $. each ( province. cities,  function ( cityIndex,  city )  { if  ( city. name ===  cityName)  { $. each ( city. areas,  function ( areaIndex,  area )  { $areaSelect. append ( $ ( '<option>' ) . val ( area. name) . text ( area. name) ) ; } ) ; $areaSelect. prop ( 'disabled' ,  false ) ; return  false ;  } } ) ; } ) ; } function  initStreetSelect ( areaName )  { var  $streetSelect =  $ ( '#receiverStreet' ) ; $streetSelect. empty ( ) ; $streetSelect. append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; $. each ( provinces,  function ( index,  province )  { $. each ( province. cities,  function ( cityIndex,  city )  { $. each ( city. areas,  function ( areaIndex,  area )  { if  ( area. name ===  areaName)  { $. each ( area. streets,  function ( streetIndex,  street )  { $streetSelect. append ( $ ( '<option>' ) . val ( street) . text ( street) ) ; } ) ; $streetSelect. prop ( 'disabled' ,  false ) ; return  false ;  } } ) ; if  ( ! $streetSelect. prop ( 'disabled' ) )  return  false ;  } ) ; } ) ; } $ ( '#receiverProvince' ) . on ( 'change' ,  function ( )  { var  selectedProvince =  $ ( this ) . val ( ) ; if  ( selectedProvince)  { initCitySelect ( selectedProvince) ; } } ) ; $ ( '#receiverCity' ) . on ( 'change' ,  function ( )  { var  selectedCity =  $ ( this ) . val ( ) ; if  ( selectedCity)  { initAreaSelect ( selectedCity) ; } } ) ; $ ( '#receiverArea' ) . on ( 'change' ,  function ( )  { var  selectedArea =  $ ( this ) . val ( ) ; if  ( selectedArea)  { initStreetSelect ( selectedArea) ; } } ) ; $ ( 'nav ul li a' ) . on ( 'click' ,  function ( e )  { e. preventDefault ( ) ; var  page =  $ ( this ) . data ( 'page' ) ; console. log ( "变量" + currentPage) ; console. log ( "传入的" + page) ; if  ( ( page !==  currentPage)  ||  page ==  '未赋值' )  { loadContent ( page) ; currentPage =  page;  } $ ( '#addNewAddressBtn' ) . toggle ( page ===  'my_addresses' ) ; } ) ; function  loadContent ( page )  { console. log ( "加载" ) ; $ ( 'nav ul li a' ) . removeClass ( 'active' ) ; $ ( 'nav ul li a[data-page="'  +  page +  '"]' ) . addClass ( 'active' ) ; if  ( page ===  'my_addresses' )  { $ ( '#content-area-address' ) . show ( ) ; let  token =  localStorage. getItem ( "token" ) ; $. ajax ( { url :  'http://localhost:8080/fshop/receiverAddress' ,  headers : { 'token' :  token} , type :  'GET' , dataType :  'json' , success :  function ( addresses )  { console. log ( addresses. data) ; var  addressListHtml =  '<div class="address-list active">' ; $. each ( addresses. data,  function ( index,  address )  { addressListHtml +=  '<div class="address-item active" data-address-id="'  +  address. receiveAddressId +  '" data-user-id="'  +  address. userId +  '">'  + '<p><strong>姓名:</strong> '  +  address. receiverName +  '</p>'  + '<p><strong>电话:</strong> '  +  address. receiverPhone +  '</p>'  + '<p><strong>省份:</strong> '  +  address. receiverProvince +  '</p>'  + '<p><strong>城市:</strong> '  +  address. receiverCity +  '</p>'  + '<p><strong>县区:</strong> '  +  address. receiverArea +  '</p>'  + '<p><strong>街道:</strong> '  +  address. receiverStreet +  '</p>'  + '<p><strong>详细地址:</strong> '  +  address. receiverDetail +  '</p>'  + '<button class="edit-btn">修改</button>'  + '<button class="delete-btn">删除</button>'  + '</div>' ; } ) ; addressListHtml +=  '</div>' ; $ ( '#content-area' ) . html ( addressListHtml) ;  $ ( '#addNewAddressBtn' ) . show ( ) ;  } , error :  function ( jqXHR,  textStatus,  errorThrown )  { alert ( '加载地址列表失败!错误: '  +  textStatus +  ', 详细信息: '  +  errorThrown) ; } } ) ; }  else  if  ( page ===  'my_coupons' )  { $ ( '#content-area' ) . text ( '我的优惠券页面' ) ; $ ( '#content-area-address' ) . hide ( ) ; } $ ( '#content-area .content-block' ) . removeClass ( 'active' ) ; $ ( '#content-area .content-block' ) . addClass ( 'active' ) ; $ ( '#content-area .address-item' ) . addClass ( 'active' ) ; } function  bindAddNewAddressEvents ( )  { $ ( '#addNewAddressBtn' ) . on ( 'click' ,  function ( )  { $ ( '#newAddressForm' ) . show ( ) . find ( 'input[type="text"]' ) . val ( '' ) ;  $ ( '#newAddressForm' ) . removeData ( 'edit-mode' ) ;  } ) ; $ ( '#newAddressForm' ) . on ( 'submit' ,  function ( e )  { e. preventDefault ( ) ; var  formData =  { userId :  $ ( '#userId' ) . val ( ) , receiverName :  $ ( '#receiverName' ) . val ( ) , receiverPhone :  $ ( '#receiverPhone' ) . val ( ) , receiverProvince :  $ ( '#receiverProvince' ) . val ( ) , receiverCity :  $ ( '#receiverCity' ) . val ( ) , receiverArea :  $ ( '#receiverArea' ) . val ( ) , receiverStreet :  $ ( '#receiverStreet' ) . val ( ) , receiverDetail :  $ ( '#receiverDetail' ) . val ( ) , isDefault :  $ ( 'input[name="isDefault"]:checked' ) . val ( ) } ; if  ( ! receiverName ||  ! receiverPhone ||  ! receiverProvince ||  ! receiverCity ||  ! receiverArea ||  ! receiverStreet)  { alert ( '请填写所有必填字段!' ) ; return ; } let  token =  localStorage. getItem ( "token" ) ; $. ajax ( { url :  'http://localhost:8080/fshop/receiverAddress/saveAddr' ,  contentType :  'application/json; charset=utf-8' ,  headers : { 'token' :  token} , type :  'POST' , data :  JSON . stringify ( formData) , dataType :  'json' , success :  function ( response )  { console. log ( response) ; if  ( response. code ==  1 )  { console. log ( "成功" + response. data) ; var  newAddressHtml =  createAddressItemHtml ( response. data) ;  $ ( '#content-area .address-list' ) . append ( newAddressHtml) ; $ ( '#newAddressForm' ) . hide ( ) ; alert ( '地址添加成功!' ) ; }  else  { console. log ( "失败" + response. data) ; alert ( '地址添加失败:'  +  response. message) ; } } , error :  function ( jqXHR,  textStatus,  errorThrown )  { alert ( '添加地址时发生错误:'  +  textStatus +  ', 详细信息: '  +  errorThrown) ; } } ) ; } ) ; $ ( '#newAddressForm' ) . on ( 'click' ,  '.cancel-new-address-btn' ,  function ( )  { $ ( '#newAddressForm' ) . hide ( ) ;  } ) ; } function  createAddressItemHtml ( addressData )  { return  '<div class="address-item active" data-address-id="'  +  addressData. receiveAddressId +  '" data-user-id="'  +  addressData. userId +  '">'  + '<p><strong>姓名:</strong> '  +  addressData. receiverName +  '</p>'  + '<p><strong>电话:</strong> '  +  addressData. receiverPhone +  '</p>'  + '<p><strong>省份:</strong> '  +  addressData. receiverProvince +  '</p>'  + '<p><strong>城市:</strong> '  +  addressData. receiverCity +  '</p>'  + '<p><strong>县区:</strong> '  +  addressData. receiverArea+  '</p>'  + '<p><strong>街道:</strong> '  +  addressData. receiverStreet +  '</p>'  + '<p><strong>详细地址:</strong> '  +  addressData. receiverDetail +  '</p>'  + '<button class="edit-btn">修改</button>'  + '<button class="delete-btn">删除</button>'  + '</div>' ; } function  bindEditAddressEvents ( )  { $ ( '#content-area' ) . on ( 'click' ,  '.edit-btn' ,  function ( )  { var  addressItem =  $ ( this ) . closest ( '.address-item' ) ; var  addressId =  addressItem. data ( 'address-id' ) ;  var  editUrl =  'address_edit.html?addressId='  +  addressId; window. location. href =  editUrl; } ) ; } function  bindDeleteAddressEvents ( )  { $ ( '#content-area' ) . on ( 'click' ,  '.delete-btn' ,  function ( )  { var  addressItem =  $ ( this ) . closest ( '.address-item' ) ; var  addressId =  addressItem. data ( 'address-id' ) ;  if  ( confirm ( '确定要删除这个地址吗?' ) )  {  $. ajax ( { url :  'http://localhost:8080/fshop/receiverAddress/'  +  addressId,  headers :  {  'token' :  localStorage. getItem ( "token" )  } ,  type :  'DELETE' ,  dataType :  'json' , success :  function ( response )  { if  ( response. code ==  1 )  { addressItem. remove ( ) ;  alert ( '地址删除成功!' ) ; }  else  { alert ( '地址删除失败:'  +  response. message) ; } } , error :  function ( jqXHR,  textStatus,  errorThrown )  { alert ( '删除地址时发生错误:'  +  textStatus +  ', 详细信息: '  +  errorThrown) ; } } ) ; } } ) ; } loadContent ( 'my_addresses' ) ; initProvinceSelect ( ) ;  bindAddNewAddressEvents ( ) ; bindEditAddressEvents ( ) ; bindDeleteAddressEvents ( ) ; } ) ; <! DOCTYPE  html > < htmllang = " en" > < head> < metacharset = " UTF-8" > < title> </ title> < scriptsrc = " ../common/jquery-3.3.1.min.js" > </ script> < script> function  getQueryParam ( name )  { var  regex =  new  RegExp ( "[?&]"  +  name +  "(=([^&#]*)|&|#|$)" ) , results =  regex. exec ( window. location. href) ; if  ( ! results)  return  null ; if  ( ! results[ 2 ] )  return  '' ; return  decodeURIComponent ( results[ 2 ] . replace ( / \+ / g ,  " " ) ) ; } var  addressId =  getQueryParam ( 'addressId' ) ; console. log ( addressId) ;  </ script> < style> #newAddressForm  { max-width :  600px; margin :  0 auto;  padding :  20px; border :  1px solid #ccc; border-radius :  5px; box-shadow :  0 2px 5px rgba ( 0,  0,  0,  0.1) ; } .form-group  { margin-bottom :  20px; } .form-group label  { display :  block; font-weight :  bold; margin-bottom :  5px; } .form-group input[type="text"],.form-group input[type="tel"],.form-group textarea  { width :  100%; padding :  10px; border :  1px solid #ccc; border-radius :  4px; box-sizing :  border-box;  } .form-group select  { width :  100%; padding :  10px; border :  1px solid #ccc; border-radius :  4px; } .form-group input[type="radio"]  { margin-right :  5px; } .form-actions  { text-align :  right;  margin-top :  20px; } .form-actions input[type="button"],.form-actions button  { padding :  10px 20px; border :  none; border-radius :  4px; cursor :  pointer; } .form-actions input[type="button"]:hover,.form-actions button:hover  { background-color :  #ddd;  } #submitBtn  { background-color :  #4CAF50;  color :  white;  } .cancel-new-address-btn  { background-color :  #f44336;  color :  white;  } #loading-indicator  { text-align :  center; padding :  10px; background-color :  rgba ( 255,  255,  255,  0.8) ; position :  fixed; top :  50%; left :  50%; transform :  translate ( -50%,  -50%) ; z-index :  9999;  } </ style> </ head> < body> < divid = " loading-indicator" style = " display :  none; " > </ div> < formid = " newAddressForm" style = " display :  none; " > < inputtype = " hidden" id = " userId" name = " userId" value = " " > < inputtype = " hidden" id = " receiveAddressId" name = " receiveAddressId" value = " " > < divclass = " form-group" > < labelfor = " receiverName" > </ label> < inputtype = " text" id = " receiverName" name = " receiverName" placeholder = " 请输入收件人姓名" required > </ div> < divclass = " form-group" > < labelfor = " receiverPhone" > </ label> < inputtype = " tel" id = " receiverPhone" name = " receiverPhone" placeholder = " 请输入收件人电话号码" required > </ div> < divclass = " form-group" > < labelfor = " receiverProvince" > </ label> < selectid = " receiverProvince" name = " receiverProvince" required > < optionvalue = " " > </ option> </ select> </ div> < divclass = " form-group" > < labelfor = " receiverCity" > </ label> < selectid = " receiverCity" name = " receiverCity" required > < optionvalue = " " > </ option> </ select> </ div> < divclass = " form-group" > < labelfor = " receiverArea" > </ label> < selectid = " receiverArea" name = " receiverArea" required  disabled > < optionvalue = " " > </ option> </ select> </ div> < divclass = " form-group" > < labelfor = " receiverStreet" > </ label> < selectid = " receiverStreet" name = " receiverStreet" required  disabled > < optionvalue = " " > </ option> </ select> </ div> < divclass = " form-group" > < labelfor = " receiverDetail" > </ label> < textareaid = " receiverDetail" name = " receiverDetail" placeholder = " 请输入详细地址" required > </ textarea> </ div> < divclass = " form-group" > < label> < inputtype = " radio" id = " isDefaultYes" name = " isDefault" value = " 1" > </ label> < label> < inputtype = " radio" id = " isDefaultNo" name = " isDefault" value = " 0" checked > </ label> </ div> < divclass = " form-actions" > < inputtype = " button" id = " submitBtn" value = " 保存" > < buttontype = " button" id = " cancelBtn" class = " cancel-new-address-btn" > </ button> </ div> </ form> </ body> < script> $ ( document) . ready ( function ( )  { $ ( '#loading-indicator' ) . show ( ) ; var  provinces =  [ { name :  '省份1' , cities :  [ {  name :  '城市1' ,  areas :  [ {  name :  '县区1' ,  streets :  [ '街道1-1' ,  '街道1-2' ]  } ,  {  name :  '县区2' ,  streets :  [ '街道2-1' ,  '街道2-2' ]  } ]  } , ] } , { name :  '省份2' , cities :  [ {  name :  '城市3' ,  areas :  [ {  name :  '县区3' ,  streets :  [ '街道3-1' ,  '街道3-2' ]  } ]  } , ] } , { name :  '江苏省' , cities :  [ {  name :  '宿迁市' ,  areas :  [ {  name :  '灌南县' ,  streets :  [ '五老村街道' ,  '五老村街道3' ]  } , {  name :  '2县' ,  streets :  [ '2街道' ,  '3街道' ]  } ]  } , ] } ] ; function  initProvinceSelect ( )  { var  $provinceSelect =  $ ( '#receiverProvince' ) ; $provinceSelect. empty ( ) ; $provinceSelect. append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; $. each ( provinces,  function ( index,  province )  { $provinceSelect. append ( $ ( '<option>' ) . val ( province. name) . text ( province. name) ) ; } ) ; } function  initCitySelect ( provinceName )  { var  $citySelect =  $ ( '#receiverCity' ) ; $citySelect. empty ( ) ; $citySelect. append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; var  $areaSelect =  $ ( '#receiverArea' ) ; $areaSelect. empty ( ) . append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; $areaSelect. prop ( 'disabled' ,  true ) ; var  $streetSelect =  $ ( '#receiverStreet' ) ; $streetSelect. empty ( ) . append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; $streetSelect. prop ( 'disabled' ,  true ) ; $. each ( provinces,  function ( index,  province )  { if  ( province. name ===  provinceName)  { $. each ( province. cities,  function ( cityIndex,  city )  { $citySelect. append ( $ ( '<option>' ) . val ( city. name) . text ( city. name) ) ; } ) ; return  false ;  } } ) ; } function  initAreaSelect ( cityName )  { var  $areaSelect =  $ ( '#receiverArea' ) ; $areaSelect. empty ( ) ; $areaSelect. append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; var  $streetSelect =  $ ( '#receiverStreet' ) ; $streetSelect. empty ( ) . append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; $streetSelect. prop ( 'disabled' ,  true ) ; $. each ( provinces,  function ( index,  province )  { $. each ( province. cities,  function ( cityIndex,  city )  { if  ( city. name ===  cityName)  { $. each ( city. areas,  function ( areaIndex,  area )  { $areaSelect. append ( $ ( '<option>' ) . val ( area. name) . text ( area. name) ) ; } ) ; $areaSelect. prop ( 'disabled' ,  false ) ; return  false ;  } } ) ; } ) ; } function  initStreetSelect ( areaName )  { var  $streetSelect =  $ ( '#receiverStreet' ) ; $streetSelect. empty ( ) ; $streetSelect. append ( $ ( '<option>' ) . val ( '' ) . text ( '请选择' ) ) ; $. each ( provinces,  function ( index,  province )  { $. each ( province. cities,  function ( cityIndex,  city )  { $. each ( city. areas,  function ( areaIndex,  area )  { if  ( area. name ===  areaName)  { $. each ( area. streets,  function ( streetIndex,  street )  { $streetSelect. append ( $ ( '<option>' ) . val ( street) . text ( street) ) ; } ) ; $streetSelect. prop ( 'disabled' ,  false ) ; return  false ;  } } ) ; if  ( ! $streetSelect. prop ( 'disabled' ) )  return  false ;  } ) ; } ) ; } $ ( '#receiverProvince' ) . on ( 'change' ,  function ( )  { var  selectedProvince =  $ ( this ) . val ( ) ; if  ( selectedProvince)  { initCitySelect ( selectedProvince) ; } } ) ; $ ( '#receiverCity' ) . on ( 'change' ,  function ( )  { var  selectedCity =  $ ( this ) . val ( ) ; if  ( selectedCity)  { initAreaSelect ( selectedCity) ; } } ) ; $ ( '#receiverArea' ) . on ( 'change' ,  function ( )  { var  selectedArea =  $ ( this ) . val ( ) ; if  ( selectedArea)  { initStreetSelect ( selectedArea) ; } } ) ; initProvinceSelect ( ) ;  } ) ; var  addressId =  getQueryParam ( 'addressId' ) ; if  ( addressId)  { $. ajax ( { url :  'http://localhost:8080/fshop/receiverAddress/'  +  addressId,  headers :  {  'token' :  localStorage. getItem ( "token" )  } , type :  'GET' , dataType :  'json' , success :  function ( address )  { let  addressData =  address. data; $ ( '#loading-indicator' ) . hide ( ) ; $ ( '#receiveAddressId' ) . val ( addressData. receiveAddressId) ;  $ ( '#userId' ) . val ( addressData. userId) ;  $ ( '#receiverName' ) . val ( addressData. receiverName) ; $ ( '#receiverPhone' ) . val ( addressData. receiverPhone) ; $ ( '#receiverProvince' ) . val ( addressData. receiverProvince) . trigger ( 'change' ) ;  $ ( '#receiverDetail' ) . val ( addressData. receiverDetail) ; var  defaultValueFromBackend =  addressData. isDefault; if  ( defaultValueFromBackend ===  1 )  { $ ( '#isDefaultYes' ) . prop ( 'checked' ,  true ) ; }  else  if  ( defaultValueFromBackend ===  0 )  { $ ( '#isDefaultNo' ) . prop ( 'checked' ,  true ) ; } $ ( '#newAddressForm' ) . show ( ) ; } , error :  function ( jqXHR,  textStatus,  errorThrown )  { $ ( '#loading-indicator' ) . hide ( ) ; alert ( '获取地址详情失败:'  +  textStatus) ; } } ) ; } $ ( '#submitBtn' ) . on ( 'click' ,  function ( event )  { event. preventDefault ( ) ;  var  formData =  { userId :  $ ( '#userId' ) . val ( ) , receiveAddressId :  $ ( '#receiveAddressId' ) . val ( ) , receiverName :  $ ( '#receiverName' ) . val ( ) , receiverPhone :  $ ( '#receiverPhone' ) . val ( ) , receiverProvince :  $ ( '#receiverProvince' ) . val ( ) , receiverCity :  $ ( '#receiverCity' ) . val ( ) , receiverArea :  $ ( '#receiverArea' ) . val ( ) , receiverStreet :  $ ( '#receiverStreet' ) . val ( ) , receiverDetail :  $ ( '#receiverDetail' ) . val ( ) , isDefault :  $ ( 'input[name="isDefault"]:checked' ) . val ( ) } ; $. ajax ( { url :  'http://localhost:8080/fshop/receiverAddress/updateAddr' ,  contentType :  'application/json; charset=utf-8' ,  headers : { 'token' :  localStorage. getItem ( "token" ) } , type :  'POST' , data :  JSON . stringify ( formData) , headers :  {  'token' :  localStorage. getItem ( "token" )  } ,  dataType :  'json' , success :  function ( response )  { console. log ( response) ; if  ( response. code ==  1  )  {  window. location. href =  'user_index.html' ; }  else  { alert ( '地址保存失败:'  +  response. message) ; } } , error :  function ( jqXHR,  textStatus,  errorThrown )  { alert ( '保存地址时发生错误:'  +  textStatus +  ', 详细信息: '  +  errorThrown) ; } } ) ; } ) ; $ ( '#cancelBtn' ) . on ( 'click' ,  function ( event )  { event. preventDefault ( ) ; window. location. href =  'user_index.html' ; } ) ; </ script> </ html> 
package  com. fshop. entity ; import  com. baomidou. mybatisplus. annotation.  IdType ; 
import  com. baomidou. mybatisplus. annotation.  TableId ; 
import  com. baomidou. mybatisplus. annotation.  TableName ; 
import  com. fasterxml. jackson. annotation.  JsonFormat ; 
import  lombok.  AllArgsConstructor ; 
import  lombok.  Data ; 
import  lombok.  NoArgsConstructor ; import  java. io.  Serializable ; 
import  java. time.  LocalDateTime ; 
@Data 
@NoArgsConstructor 
@AllArgsConstructor 
@TableName ( "receiver_address" ) 
public  class  ReceiverAddress  implements  Serializable  { private  static  final  long  serialVersionUID =  1L ; @TableId ( value =  "receive_address_id" ,  type =  IdType . AUTO ) private  Integer  receiveAddressId; private  Integer  userId; private  String  receiverName; private  String  receiverPhone; private  String  receiverProvince; private  String  receiverCity; private  String  receiverArea; private  String  receiverStreet; private  String  receiverDetail; private  Byte  isDefault; private  Integer  status; private  Integer  version; @JsonFormat ( pattern =  "yyyy-MM-dd HH:mm:ss" ) private  LocalDateTime  createTime; @JsonFormat ( pattern =  "yyyy-MM-dd HH:mm:ss" ) private  LocalDateTime  updateTime; private  String  other1; private  String  other2; } 
package  com. fshop. controller ; import  com. fshop. common.  R ; 
import  com. fshop. common.  ResponseCode ; 
import  com. fshop. entity.  ReceiverAddress ; 
import  com. fshop. service.  IReceiverAddressService ; 
import  com. fshop. util.  JwtUtil ; 
import  lombok.  RequiredArgsConstructor ; 
import  lombok. extern. slf4j.  Slf4j ; 
import  org. springframework. web. bind. annotation.  * ; import  javax. servlet. http.  HttpServletRequest ; 
import  java. util.  List ; 
@RestController 
@CrossOrigin ( origins =  "*" ) 
@RequestMapping ( "/receiverAddress" ) 
@RequiredArgsConstructor 
@Slf4j 
public  class  ReceiverAddressController  { private  final  IReceiverAddressService  receiverAddressService; @GetMapping ( ) public  R < List < ReceiverAddress > > getById ( HttpServletRequest  request) { String  token =  request. getHeader ( "token" ) ; log. info ( "根据id查询地址的token:{}" , token) ; if  ( JwtUtil . checkToken ( token) ) { log. info ( "查询地址的token正确:{}" , token) ; R < List < ReceiverAddress > > =  receiverAddressService. getById ( token) ; log. info ( "查询地址返回的数据:{}" , listR) ; return  listR; } return  R . error ( ResponseCode . TOKEN_ERROR ) ; } @GetMapping ( "{addrId}" ) public  R < ReceiverAddress > getByAddrId ( @PathVariable ( "addrId" )  Integer  addrId) { log. info ( "地址id:{}" , addrId) ; R < ReceiverAddress > =  receiverAddressService. getByAddrId ( addrId) ; return  result; } @PostMapping ( "/saveAddr" ) public  R < ReceiverAddress > saveAddr ( @RequestBody  ReceiverAddress  receiverAddress,  HttpServletRequest  request) { log. info ( "地址信息:{}" , receiverAddress) ; String  token =  request. getHeader ( "token" ) ; log. info ( "地址信息token:{}" , token) ; if  ( JwtUtil . checkToken ( token) ) { R < ReceiverAddress > =  receiverAddressService. saveAddr ( receiverAddress,  token) ; return  receiverAddressR; } return  R . error ( ResponseCode . TOKEN_ERROR ) ; } @PostMapping ( "/updateAddr" ) public  R < ReceiverAddress > updateAddr ( @RequestBody  ReceiverAddress  receiverAddress,  HttpServletRequest  request) { String  token =  request. getHeader ( "token" ) ; if  ( JwtUtil . checkToken ( token) ) { R < ReceiverAddress > =  receiverAddressService. updateAddr ( receiverAddress,  token) ; return  receiverAddressR; } return  R . error ( ResponseCode . TOKEN_ERROR ) ; } @DeleteMapping ( "{addrId}" ) public  R < ReceiverAddress > deleteByAddrId ( @PathVariable ( "addrId" )  Integer  addrId,  HttpServletRequest  request) { String  token =  request. getHeader ( "token" ) ; if  ( JwtUtil . checkToken ( token) ) { R < ReceiverAddress > =  receiverAddressService. deleteByAddrId ( addrId,  token) ; return  receiverAddressR; } return  R . error ( ResponseCode . TOKEN_ERROR ) ; } } 
package  com. fshop. service. impl ; import  com. baomidou. mybatisplus. core. conditions. query.  QueryWrapper ; 
import  com. fshop. common.  R ; 
import  com. fshop. dto.  LoginUserDto ; 
import  com. fshop. entity.  ReceiverAddress ; 
import  com. fshop. mapper.  ReceiverAddressMapper ; 
import  com. fshop. service.  IReceiverAddressService ; 
import  com. baomidou. mybatisplus. extension. service. impl.  ServiceImpl ; 
import  com. fshop. util.  JwtUtil ; 
import  lombok.  RequiredArgsConstructor ; 
import  lombok. extern. slf4j.  Slf4j ; 
import  org. springframework. stereotype.  Service ; 
import  org. springframework. web. bind. annotation.  PathVariable ; import  javax. servlet. http.  HttpServletRequest ; 
import  java. time.  LocalDateTime ; 
import  java. util.  List ; 
@Service 
@RequiredArgsConstructor 
@Slf4j 
public  class  ReceiverAddressServiceImpl  extends  ServiceImpl < ReceiverAddressMapper ,  ReceiverAddress > implements  IReceiverAddressService  { private  final  ReceiverAddressMapper  receiverAddressMapper; @Override public  R < List < ReceiverAddress > > getById ( String  token)  { log. info ( "根据用户id查询地址:{}" , token) ; LoginUserDto  loginUserDto =  JwtUtil . parseToken ( token) ; QueryWrapper < ReceiverAddress > =  new  QueryWrapper < > ( ) ; wrapper. eq ( "user_id" , loginUserDto. getUserId ( ) ) . eq ( "status" , 1 ) ; List < ReceiverAddress > =  receiverAddressMapper. selectList ( wrapper) ; log. info ( "根据用户id查询到的地址信息:{}" , receiverAddresses) ; return  R . ok ( receiverAddresses) ; } @Override public  R < ReceiverAddress > getByAddrId ( Integer  addrId)  { ReceiverAddress  address =  receiverAddressMapper. selectById ( addrId) ; if  ( address !=  null ) return  R . ok ( address) ; return  R . error ( "地址不存在" ) ; } @Override public  R < ReceiverAddress > saveAddr ( ReceiverAddress  receiverAddress,  String  token)  { LoginUserDto  loginUserDto =  JwtUtil . parseToken ( token) ; if  ( loginUserDto. getUserId ( )  !=  null ) { receiverAddress. setUserId ( loginUserDto. getUserId ( ) ) ; receiverAddress. setStatus ( 1 ) ; receiverAddress. setVersion ( 1 ) ; receiverAddress. setCreateTime ( LocalDateTime . now ( ) ) ; receiverAddress. setUpdateTime ( LocalDateTime . now ( ) ) ; Integer  insert =  receiverAddressMapper. insert ( receiverAddress) ; if  ( insert >  0 ) { return  R . ok ( receiverAddress) ; } return  R . error ( "添加失败" ) ; } return  R . error ( "token错误,未登录" ) ; } @Override public  R < ReceiverAddress > updateAddr ( ReceiverAddress  receiverAddress,  String  token)  { LoginUserDto  loginUserDto =  JwtUtil . parseToken ( token) ; if  ( loginUserDto. getUserId ( )  !=  null  &&  receiverAddress. getUserId ( ) . equals ( loginUserDto. getUserId ( ) ) ) { ReceiverAddress  receiverAddress1 =  receiverAddressMapper. selectById ( receiverAddress. getReceiveAddressId ( ) ) ; receiverAddress. setVersion ( receiverAddress1. getVersion ( ) + 1 ) ; receiverAddress. setUpdateTime ( LocalDateTime . now ( ) ) ; Integer  update =  receiverAddressMapper. updateById ( receiverAddress) ; if  ( update >  0 ) { return  R . ok ( receiverAddress) ; } return  R . error ( "修改失败" ) ; } return  R . error ( "token错误,未登录" ) ; } @Override public  R < ReceiverAddress > deleteByAddrId ( @PathVariable ( "addrId" )  Integer  addrId, String  token) { LoginUserDto  loginUserDto =  JwtUtil . parseToken ( token) ; ReceiverAddress  receiverAddress =  receiverAddressMapper. selectById ( addrId) ; receiverAddress. setStatus ( 0 ) ; if ( receiverAddress !=  null  &&  receiverAddress. getUserId ( ) . equals ( loginUserDto. getUserId ( ) ) ) { receiverAddressMapper. updateById ( receiverAddress) ; return  R . ok ( "删除成功" ) ; } return   R . error ( "删除失败" ) ; } } 
package  com. fshop. service ; import  com. fshop. common.  R ; 
import  com. fshop. entity.  ReceiverAddress ; 
import  com. baomidou. mybatisplus. extension. service.  IService ; 
import  org. springframework. web. bind. annotation.  PathVariable ; import  java. util.  List ; 
public  interface  IReceiverAddressService  extends  IService < ReceiverAddress > { R < List < ReceiverAddress > > getById ( String  token) ; R < ReceiverAddress > getByAddrId ( Integer  addrId) ; R < ReceiverAddress > saveAddr ( ReceiverAddress  receiverAddress,  String  token) ; public  R < ReceiverAddress > deleteByAddrId ( @PathVariable ( "addrId" )  Integer  addrId,  String  token) ; public  R < ReceiverAddress > updateAddr ( ReceiverAddress  receiverAddress,  String  token) ; 
} 
package  com. fshop. common ; import  com. fasterxml. jackson. annotation.  JsonInclude ; 
import  lombok.  Getter ; import  java. io.  Serializable ; 
@Getter 
@JsonInclude ( JsonInclude. Include . NON_NULL ) 
public  class  R < T > implements  Serializable  { private  static  final  long  serialVersionUID =  7735505903525411467L ; private  static  final  int  SUCCESS_CODE  =  1 ; private  static  final  int  ERROR_CODE  =  0 ; private  final  int  code; private  String  msg; private  T  data; private  R ( int  code)  { this . code =  code; } private  R ( int  code,  T  data)  { this . code =  code; this . data =  data; } private  R ( int  code,  String  msg)  { this . code =  code; this . msg =  msg; } private  R ( int  code,  String  msg,  T  data)  { this . code =  code; this . msg =  msg; this . data =  data; } public  static  < T > R < T > ok ( )  { return  new  R < T > ( SUCCESS_CODE ,  "success" ) ; } public  static  < T > R < T > ok ( String  msg)  { return  new  R < T > ( SUCCESS_CODE ,  msg) ; } public  static  < T > R < T > ok ( T  data)  { return  new  R < T > ( SUCCESS_CODE ,  data) ; } public  static  < T > R < T > ok ( String  msg,  T  data)  { return  new  R < T > ( SUCCESS_CODE ,  msg,  data) ; } public  static  < T > R < T > error ( )  { return  new  R < T > ( ERROR_CODE ,  "error" ) ; } public  static  < T > R < T > error ( String  msg)  { return  new  R < T > ( ERROR_CODE ,  msg) ; } public  static  < T > R < T > error ( int  code,  String  msg)  { return  new  R < T > ( code,  msg) ; } public  static  < T > R < T > error ( ResponseCode  res)  { return  new  R < T > ( res. getCode ( ) ,  res. getMessage ( ) ) ; } @Override public  String  toString ( )  { return  "R{"  + "code="  +  code + ", msg='"  +  msg +  '\''  + ", data="  +  data + '}' ; } 
} package  com. fshop ; import  org. mybatis. spring. annotation.  MapperScan ; 
import  org. springframework. boot.  SpringApplication ; 
import  org. springframework. boot. autoconfigure.  SpringBootApplication ; 
import  org. springframework. boot. context. properties.  ConfigurationProperties ; 
import  org. springframework. boot. context. properties.  ConfigurationPropertiesScan ; 
import  org. springframework. boot. context. properties.  EnableConfigurationProperties ; @SpringBootApplication 
@MapperScan ( "com.fshop.mapper" ) 
public  class  FshopAppApplication  { public  static  void  main ( String [ ]  args)  { SpringApplication . run ( FshopAppApplication . class ,  args) ; } } 
package  com. fshop ; import  org. springframework. boot. builder.  SpringApplicationBuilder ; 
import  org. springframework. boot. web. servlet. support.  SpringBootServletInitializer ; public  class  ServletInitializer  extends  SpringBootServletInitializer  { @Override protected  SpringApplicationBuilder  configure ( SpringApplicationBuilder  application)  { return  application. sources ( FshopAppApplication . class ) ; } } <?xml version="1.0" encoding="UTF-8"?> 
< projectxmlns = " http://maven.apache.org/POM/4.0.0" xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation= " http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion> </ modelVersion> < parent> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < relativePath/> </ parent> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < name> </ name> < description> </ description> < packaging> </ packaging> < properties> < java.version> </ java.version> </ properties> < dependencies> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < scope> </ scope> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < scope> </ scope> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < scope> </ scope> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < scope> </ scope> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < scope> </ scope> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < scope> </ scope> </ dependency> </ dependencies> < build> < plugins> < plugin> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ plugin> </ plugins> </ build> </ project> 
<?xml version="1.0" encoding="UTF-8"?> 
<! DOCTYPE  mapper  PUBLIC  "-//mybatis.org//DTD Mapper 3.0//EN"  "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > < mappernamespace = " com.fshop.mapper.ReceiverAddressMapper" > </ mapper> 
package  com. fshop. mapper ; import  com. fshop. entity.  ReceiverAddress ; 
import  com. baomidou. mybatisplus. core. mapper.  BaseMapper ; 
public  interface  ReceiverAddressMapper  extends  BaseMapper < ReceiverAddress > { }