我有问题的西里尔字符在数据库中,并使用它的JavaSpring。
从chrome浏览器图像:
我用下一种方法创建数据库:
create database dbname
character set utf8
collate utf8_general_ci;
示例数据库表:(自动创建):
@Entity(name = "words")
public class Words {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "word")
private String word;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getWord() {
return word;
}
public void setWord(String word) {
this.word = word;
}
}
保存实体方式:
@Repository
public interface WordRepository extends JpaRepository<Word, Long> {
}
@Service
public class WordService{
@Autovired
private WordRepository wordRepository;
public saveAll(List<Word> wordList){
wordRepository.saveAll(wordList);
}
}
应用程序属性:
# Database settings
spring.datasource.url=jdbc:mysql://localhost:3306/dbname?useUnicode=yes&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.datasource.tomcat.connection-properties=useUnicode=true;characterEncoding=utf-8;
spring.datasource.sql-script-encoding=UTF-8
但是,结果是,当我在数据库中保存西里尔字符时,所有字符都显示为“?”。
我还必须做些什么来解决这个问题?
1条答案
按热度按时间8zzbczxx1#
删除amp;从字符串
在application.properties文件中。