AI训练进行web前后端开发协助
周五我们进行了针对web开发辅助的ai训练,以下是训练过程:
首先我搭建好了环境
然后我根据编程习惯将web前后端分成了这几点:

之后我就将其丢给了deepseek,它直接帮我生成了上到mysql表格建立,下到前端jsp页面的所有文件,
哎,这之前怎么没觉得ai这么好用啊,要是用上这种开发速度那我不就有时间解决逻辑问题了吗?
但是ai一开始也不是能完美达到要求的,比如它生成的service文件并没有考虑到utilsfactory函数的调用,
package com.xxx.service;
import com.xxx.mapper.MaterialCategoryMapper;
import com.xxx.pojo.MaterialCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class MaterialCategoryService {
@Autowired
private MaterialCategoryMapper materialCategoryMapper;
// 添加物资类别
public int addMaterialCategory(MaterialCategory materialCategory) {
return materialCategoryMapper.insert(materialCategory);
}
// 删除物资类别
public int deleteMaterialCategory(Integer id) {
return materialCategoryMapper.deleteById(id);
}
// 更新物资类别
public int updateMaterialCategory(MaterialCategory materialCategory) {
return materialCategoryMapper.update(materialCategory);
}
// 根据ID查询物资类别
public MaterialCategory getMaterialCategoryById(Integer id) {
return materialCategoryMapper.selectById(id);
}
// 查询所有物资类别
public List<MaterialCategory> getAllMaterialCategories() {
return materialCategoryMapper.selectAll();
}
}
于是我将utilsfactory的文件还有mapper文件一同丢给它让它进行修改:
完美,而且相对健壮
package com.xxx.service;
import com.xxx.mapper.MaterialCategoryMapper;
import com.xxx.pojo.MaterialCategory;
import com.xxx.utils.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import java.util.List;
public class MaterialCategoryService {
private SqlSessionFactory sqlSessionFactory;
public MaterialCategoryService() {
// 初始化 SqlSessionFactory
sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
}
// 添加物资类别
public int addMaterialCategory(MaterialCategory materialCategory) {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
MaterialCategoryMapper mapper = sqlSession.getMapper(MaterialCategoryMapper.class);
int result = mapper.insert(materialCategory);
sqlSession.commit(); // 提交事务
return result;
} finally {
sqlSession.close(); // 关闭 SqlSession
}
}
// 删除物资类别
public int deleteMaterialCategory(Integer id) {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
MaterialCategoryMapper mapper = sqlSession.getMapper(MaterialCategoryMapper.class);
int result = mapper.deleteById(id);
sqlSession.commit(); // 提交事务
return result;
} finally {
sqlSession.close(); // 关闭 SqlSession
}
}
// 更新物资类别
public int updateMaterialCategory(MaterialCategory materialCategory) {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
MaterialCategoryMapper mapper = sqlSession.getMapper(MaterialCategoryMapper.class);
int result = mapper.update(materialCategory);
sqlSession.commit(); // 提交事务
return result;
} finally {
sqlSession.close(); // 关闭 SqlSession
}
}
// 根据ID查询物资类别
public MaterialCategory getMaterialCategoryById(Integer id) {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
MaterialCategoryMapper mapper = sqlSession.getMapper(MaterialCategoryMapper.class);
return mapper.selectById(id);
} finally {
sqlSession.close(); // 关闭 SqlSession
}
}
// 查询所有物资类别
public List<MaterialCategory> getAllMaterialCategories() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
MaterialCategoryMapper mapper = sqlSession.getMapper(MaterialCategoryMapper.class);
return mapper.selectAll();
} finally {
sqlSession.close(); // 关闭 SqlSession
}
}
}
部署完文件后我启动tomcat
跑起来了!(不知道该是悲是喜)
随后我让它生成删改查的相关servlet与jsp,它也干净地给出,但是在查的环节上出了问题:
部分数据没接收到?!
后面我又找到了原因:mapper文件中语句缺少@param,添加后也解决了问题
最后我又将一个新的库给了ai,让它生成全过程,再次进行部署,略微调试后也成功运行

浙公网安备 33010602011771号