Ajouter une page
![Insérez la description de l'image ici](https://img-blog.csdnimg.cn/2020102621104333.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMjA5ODg2,size_16,color_FFFFFF,t_70#pic_center)
Code derrière
CompanyController.java
- src \ main \ java \ com \ smp \ web \ controller \ company
@RequestMapping(path = "/toAdd",method = RequestMethod.GET)
public String toAdd(){
return "company/company-add";
}
Test de TestCompanyService.java
- src \ test \ java \ com \ smp \ service \ entreprise
@Test
public void test02(){
Company company=new Company("id1","name1",new Date(),"adress1","licenseId1","representative","phone","companySize","industry","remarks",0,100.0,"city");
service.saveCompany(company);
}
Company.java
- src \ main \ java \ com \ smp \ domaine \ entreprise
- Ajouter un ginseng complet
public Company(String id, String name, Date expirationDate, String address, String licenseId, String representative, String phone, String companySize, String industry, String remarks, Integer state, Double balance, String city) {
this.id = id;
this.name = name;
this.expirationDate = expirationDate;
this.address = address;
this.licenseId = licenseId;
this.representative = representative;
this.phone = phone;
this.companySize = companySize;
this.industry = industry;
this.remarks = remarks;
this.state = state;
this.balance = balance;
this.city = city;
}
ICompanyService.java
- src \ main \ java \ com \ smp \ service \ entreprise
void saveCompany(Company company);
CompanyServiceImpl.java
- src \ main \ java \ com \ smp \ service \ entreprise \ impl
@Override
public void saveCompany(Company company) {
String id= UUID.randomUUID().toString();
company.setId(id);
iCompanyDao.save(company);
}
ICompanyDao.java
- src \ main \ java \ com \ smp \ dao \ entreprise
void save(Company company);
ICompanyDao.xml
- src \ main \ resources \ com \ smp \ dao \ company
<insert id="save" parameterType="company">
insert into ss_company
(
id ,
name ,
expiration_date ,
address ,
license_id ,
representative ,
phone ,
company_size ,
industry ,
remarks ,
state ,
balance ,
city
)
values
(
#{id },
#{name },
#{expirationDate },
#{address },
#{licenseId },
#{representative },
#{phone },
#{companySize },
#{industry },
#{remarks },
#{state },
#{balance },
#{city}
)
</insert>
Code de la réception
CompanyController.java
- src \ main \ java \ com \ smp \ web \ controller \ company
@RequestMapping(path = "/add",method = RequestMethod.POST)
public String add(Company company){
l.info("add company="+company);
iCompanyService.saveCompany(company);
return "redirect:/company/...";
}
company-add.jsp
- src \ main \ webapp \ WEB-INF \ pages \ entreprise
这个界面中name要和实现类中的变量名一致
![Insérez la description de l'image ici](https://img-blog.csdnimg.cn/20201026202019408.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxMjA5ODg2,size_16,color_FFFFFF,t_70#pic_center)