springmvc+jdbc连接数据库(第一个微商项目,代理注册)

本文介绍如何在Java应用程序中生成并使用UUID作为主键和授权编码,同时展示了如何将UUID写入数据库的具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");手动自动生成Uuid本表主键(主要作用是数据库生成的是唯一的,可以用来生成比如说本表的主键,还有像这里的授权编码是每个人独有的,所以就要用这个来生成。)
String uuid,把生成的赋值给uudi,然后在把这个uuid用sql语句写入数据库里面,写入的前提,数据库里面要有这个uuid列的属性。
这里写入数据库的时候,不需要向其他属性一样还要在Page中写set,get方法,在这里就不用,直接写sql里面,然后在jdbcTemplate.update语句中也要相应的写上就可以了
@Service
@Transactional
public class UserService {

@Autowired
private JdbcTemplate jdbcTemplate;

public Json register(AgentRegistered_Page page){
Json json = new Json();
//手动自动生成Uuid本表主键
String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
//手动自动生成Accredit授权编码
String accredit=UUID.randomUUID().toString().trim().replaceAll("-", "");
String sql="insert into agency (Uuid,Accredit,Account,Password,Phonenumber,Realname,Idcardnumber,Agentregion,Nameofcompany,Referees,Agencyhead,Photoagencyasalegalperson,Thebusinesslicense,Duplicateofbusinesslicense,Thebankopensanaccountlicence,Pid,Encrypted_problem_one,Encrypted_problem_two,Encrypted_problem_three,Encrypted_answers_one,Encrypted_answers_two,Encrypted_answers_three,Province,City,Area) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
jdbcTemplate.update(sql,uuid,accredit,page.getAccount(),page.getPassword(),page.getPhonenumber(),page.getRealname(),page.getIdcardnumber(),page.getAgentregion(),page.getNameofcompany(),page.getReferees(),page.getAgencyhead(),page.getPhotoagencyasalegalperson(),page.getThebusinesslicense(),page.getDuplicateofbusinesslicense(),page.getThebankopensanaccountlicence(),page.getPid(),page.getEncrypted_problem_one(),page.getEncrypted_problem_two(),page.getEncrypted_problem_three(),page.getEncrypted_answers_one(),page.getEncrypted_answers_two(),page.getEncrypted_answers_three(),page.getProvince(),page.getCity(),page.getArea());
return json;
}
}

转载于:https://www.cnblogs.com/likeji/p/6110843.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值