junit junit 4.12 org.springframework.boot spring-boot-starter-test test com.alibaba easyexcel 2.1.7 com.alibaba fastjson 1.2.62 org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-test test com.mchange c3p0 0.9.5.2 com.baomidou mybatis-plus-boot-starter 3.4.0 org.springframework.boot spring-boot-starter-jdbc mysql mysql-connector-java runtime org.projectlombok lombok true org.springframework.boot spring-boot-starter-web org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test
server.port=8080 mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl spring.datasource.url=jdbc:mysql://localhost:3306/ddb_resources?serverTimezone=UTC spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.username=root spring.datasource.password=root
@Mapper public interface DdbBookNewWordMapper extends BaseMapper{ }
@Service public class DemoDAO { @Autowired DdbBookNewWordMapper mapper; public void save(List list) { // 如果是mybatis,尽量别直接调用多次insert,自己写一个mapper里面新增一个方法batchInsert,所有数据一次性插入 DdbBookNewWord newWord = new DdbBookNewWord(); System.out.println("插入数据开始==============================="); for (DataDemo001 info : list) { newWord.setAppType(0); newWord.setFkBookId(info.getFkBookId()); newWord.setWord(info.getWord()); newWord.setSimpleExplain(info.getSimpleExplain()); newWord.setImgUrl("/incoming/ddb/wordImg/"+info.getFkBookId()+"/"+info.getImgUrl()); newWord.setSoundUrl("/incoming/ddb/wordAudio/bookStudyMp3/"+info.getFkBookId()+"/"+info.getSoundUrl()); newWord.setCreateTimeInMs(1620983400709L); newWord.setUpdateTimeInMs(1620983400709L); System.out.println(newWord); mapper.insert(newWord); } System.out.println("结束========================="); } }
@Data @AllArgsConstructor @NoArgsConstructor @ToString public class DdbBookNewWord { private int id; private String fkBookId; private String word; private String simpleExplain; private String imgUrl; private long createTimeInMs; private long updateTimeInMs; private int appType; private String soundUrl; }
@Data public class DataDemo001 { private String fkBookId; private String bookeName; private String moudle; private String unit; private String word; private String soundUrl; private String imgUrl; private String simpleExplain; }
위 내용은 Java를 사용하여 Excel에서 MySQL로 데이터를 가져오는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!