company修改和回显
查看修改页面
@RequestMapping ( path= "/toEdit" , method = RequestMethod. GET)
public String toEdit ( ) {
return "company/company-update" ;
}
回显数据
Test
@Test
public void test03 ( ) {
String id= "1d067ff9-f11d-4572-a9a5-b95dbf5f8987" ;
Company company= service. findById ( id) ;
l. info ( "findById==" + company) ;
}
ICompanyService
Company findById ( String id) ;
CompanyServiceImpl
@Override
public Company findById ( String id) {
Company company= dao. findById ( id) ;
return company;
}
ICompanyDao
Company findById ( String id) ;
ICompanyDao.xml
< select id = " findById" parameterType = " String" resultType = " company" >
select
id,
name ,
expiration_date as expirationDate ,
address,
license_id as licenseId ,
representative ,
phone ,
company_size as companySize ,
industry ,
remarks ,
state,
balance ,
city
from ss_company
where id = #{id}
</ select>
controller层
@RequestMapping ( path = "/toEdit" , method = RequestMethod. GET)
public String toEdit ( String id, Model model) {
l. info ( "toEdit==" + id) ;
Company company= service. findById ( id) ;
l. info ( "company==" + company) ;
model. addAttribute ( "company" , company) ;
return "company/company-update" ;
}
jsp
< form id = " editForm" action = " ${path}/company/update.do" method = " post" >
< input type = " hidden" name = " id" value = " ${company.id}" >
< div class = " row data-type" style =" margin : 0px" >
< div class = " col-md-2 title" > 企业名称</ div>
< div class = " col-md-4 data" >
< input type = " text" class = " form-control" placeholder = " 企业名称" name = " name" value = " ${company.name}" >
</ div>
< div class = " col-md-2 title" > 营业执照</ div>
< div class = " col-md-4 data" >
< input type = " text" class = " form-control" placeholder = " 营业执照" name = " licenseId" value = " ${company.licenseId}" >
</ div>
< div class = " col-md-2 title" > 所在城市</ div>
< div class = " col-md-4 data" >
< input type = " text" class = " form-control" placeholder = " 所在地" name = " city" value = " ${company.city}" >
</ div>
< div class = " col-md-2 title" > 企业地址</ div>
< div class = " col-md-4 data" >
< input type = " text" class = " form-control" placeholder = " 企业地址" name = " address" value = " ${company.address}" >
</ div>
< div class = " col-md-2 title" > 法人代表</ div>
< div class = " col-md-4 data" >
< input type = " text" class = " form-control" placeholder = " 法人代表" name = " representative" value = " ${company.representative}" >
</ div>
< div class = " col-md-2 title" > 联系电话</ div>
< div class = " col-md-4 data" >
< input type = " text" class = " form-control" placeholder = " 联系电话" name = " phone" value = " ${company.phone}" >
</ div>
< div class = " col-md-2 title" > 公司规模</ div>
< div class = " col-md-4 data" >
< input type = " text" class = " form-control" placeholder = " 公司规模" name = " companySize" value = " ${company.companySize}" >
</ div>
< div class = " col-md-2 title" > 所属行业</ div>
< div class = " col-md-4 data" >
< input type = " text" class = " form-control" placeholder = " 所属行业" name = " industry" value = " ${company.industry}" >
</ div>
< div class = " col-md-2 title" > 状态</ div>
< div class = " col-md-4 data" >
< select class = " form-control select2" name = " state" style =" width : 100%; " >
<option value="0" ${company.state==0 ? 'selected':''}>未审核</ option>
<option value="1" ${company.state==1 ? 'selected':''}>已审核</ option>
</ select>
< input type = " text" class = " form-control" placeholder = " 状态" name = " state" value = " ${company.state}" >
</ div>
< div class = " col-md-2 title" > 余额</ div>
< div class = " col-md-4 data" >
< input type = " text" class = " form-control" placeholder = " 余额" name = " balance" value = " ${company.balance}" >
</ div>
< div class = " col-md-2 title rowHeight2x" > 备注</ div>
< div class = " col-md-10 data rowHeight2x" >
< textarea class = " form-control" rows = " 3" name = " remarks" > ${company.remarks}</ textarea>
</ div>
</ div>
</ form>
修改
Test
@Test
public void test04 ( ) {
String id= "1d067ff9-f11d-4572-a9a5-b95dbf5f8987" ;
Company company= service. findById ( id) ;
l. info ( "findById==" + company) ;
company. setAddress ( "湖北武汉" ) ;
l. info ( "company==" + company) ;
service. updateCompany ( company) ;
}
ICompanyService
void updateCompany ( Company company) ;
CompanyServiceImpl
@Override
public void updateCompany ( Company company) {
dao. update ( company) ;
}
ICompanyDao
void update ( Company company) ;
ICompanyDao.xml
< update id = " update" parameterType = " company" >
update ss_company
set name = #{name },
expiration_date= #{expirationDate},
address = #{address },
license_id = #{licenseId },
representative = #{representative },
phone = #{phone },
company_size = #{companySize },
industry = #{industry },
remarks = #{remarks },
state = #{state },
balance = #{balance },
city = #{city }
where id = #{id}
</ update>
controller层
@RequestMapping ( path = "/update" , method = RequestMethod. POST)
public String update ( Company company) {
l. info ( "update==" + company) ;
service. updateCompany ( company) ;
return "redirect:/company/toList.do" ;
}
jsp
< form id = " editForm" action = " ${path}/company/update.do" method = " post" >