我有一个Web应用程序,它使用Hibernate在数据库上进行CRUD操作.我收到一个错误,表示该表未映射.请参阅Java文件:
错误信息:
org.springframework.orm.hibernate3.HibernateQueryException: Books is not mapped [SELECT COUNT(*) FROM Books]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Books is not mapped [SELECT COUNT(*) FROM Books]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:660)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
...
Caused by: org.hibernate.hql.ast.QuerySyntaxException: Books is not mapped [SELECT COUNT(*) FROM Books]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
...
Run Code Online (Sandbox Code Playgroud)
这是我的DAO.java方法:
public int getTotalBooks(){
return DataAccessUtils.intResult(hibernateTemplate.find(
"SELECT COUNT(*) FROM Books"));
}
Run Code Online (Sandbox Code Playgroud)
Book.java:
@Entity
@Table(name="Books")
public class Book {
@Id
@GeneratedValue
@Column(name="id")
private int id;
@Column(name="title", nullable=false)
private String title; …Run Code Online (Sandbox Code Playgroud) 我创建了一个函数来检查是否定义了变量:
fm["isset"] = func(a interface{}) bool {
if a == nil || a == "" || a == 0 {
fmt.Println("is not set")
return false
}
fmt.Println("is set")
return false
}
tmpl := template.Must(template.New("").Funcs(fm).ParseFiles("templates/header.html"))
err := tmpl.ExecuteTemplate(w, "header", templateData)
Run Code Online (Sandbox Code Playgroud)
在模板中我有:
{{ if isset .Email }}
email is set
{{ end }}
Run Code Online (Sandbox Code Playgroud)
如果变量包含在templateData(它是包含映射和字符串的自定义结构)中,则此函数有效,但如果变量不存在则会给出错误.
错误是:
executing "header" at <.Email>: can't evaluate field Email in type base.customData
Run Code Online (Sandbox Code Playgroud)
在我的情况下,"base.go"是处理程序,"customData"由以下内容定义:type customData struct{..}.
我希望能够重用模板,并且只有在从处理程序发送一些变量时才显示某些部分.任何想法如何isset在模板端实现变量检查?
我也试过使用:{{ if .Email}} do stuff …
我有一个函数,其参数类型为interface {},如下所示:
func LoadTemplate(templateData interface{}) {
Run Code Online (Sandbox Code Playgroud)
在我的例子中,templateData是一个结构,但每次它都有不同的结构.我使用了"interface {}"类型,因为它允许我发送所有类型的数据.
我正在使用此templateData将数据发送到模板:
err := tmpl.ExecuteTemplate(w, baseTemplateName, templateData)
Run Code Online (Sandbox Code Playgroud)
但是现在我想添加一些新数据,我不知道怎么做,因为"interface"类型不允许我添加/追加任何东西.
我试图将接口转换为结构,但我不知道如何将数据附加到具有未知结构的结构.
如果我使用以下功能,我可以看到界面的数据:
templateData = appendAssetsToTemplateData(templateData)
func appendAssetsToTemplateData(t interface{}) interface{} {
switch reflect.TypeOf(t).Kind() {
case reflect.Struct:
fmt.Println("struct")
s := reflect.ValueOf(t)
fmt.Println(s)
//create a new struct based on current interface data
}
return t
}
Run Code Online (Sandbox Code Playgroud)
知道如何将子项附加到初始接口参数(templateData)?或者我如何将其转换为结构或其他内容以附加新的子/数据?
我有一个 div 元素。div 是一个图标。当您单击此图标时,将触发表单提交。在表单提交上有一些计算,这些计算的结果会打开一个新选项卡。
我使用“ window.open(url, '_blank'); ”
但在 safari 和 chrome 中,这个新标签被视为弹出窗口并被阻止。
我试图创建一个隐藏的 a href 并触发点击,以便它会在新选项卡中打开页面,但它不起作用。
知道如何解决这个问题吗?
编辑 - 找到解决方案
您需要在 $.ajax 成功方法中的单击事件上添加 window.open。这样它就会起作用。
$('#myButton').click(function () {
var redirectWindow = window.open('http://google.com', '_blank');
$.ajax({
type: 'POST',
url: '/echo/json/',
success: function (data) {
redirectWindow.location;
}
});
});
Run Code Online (Sandbox Code Playgroud)
我正在使用 Vue JS 2.5 和 Axios:
\n\n"vue": "^2.5.17",\n"vue-axios": "^2.1.4",\n"axios": "^0.18.0",\nRun Code Online (Sandbox Code Playgroud)\n\n我正在尝试像这样进行 POST 调用:
\n\nconst data = querystring.stringify({\n \'email\': email,\n \'password\': password,\n \'crossDomain\': true, //optional, added by me to test if it helps but it doesn\'t help\n });\n\nvar axiosConfig = {\n headers: {\n \'Content-Type\': \'application/x-www-form-urlencoded\',\n // "Access-Control-Allow-Origin": "*",\n \'Accept\': \'*\',\n }\n };\n\naxios.post(url, data, axiosConfig)\n .then((response) => {\n console.log(\'response\');\n console.log(response);\n })\n .catch((error) => {\n console.log(\'error\');\n console.log(error);\n });\nRun Code Online (Sandbox Code Playgroud)\n\n我也尝试过不使用“axiosConfig”参数。但每次它进入捕获时,都会显示以下消息:错误:网络错误
\n\n在浏览器的“网络”选项卡中,我得到 200 状态和良好的响应(带有有效的 json),它基本上可以工作,但 Axios 返回错误并且没有响应。
\n\n控制台还输出此警告: …
我使用漂亮的照片版本3.1.4.(http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/).我想从网址中删除"#prettyphoto [iframe]/number /".我设置了深层链接:false,但这没有用.我明白这可能是这些功能的问题:
function getHashtag(){url=location.href;hashtag=(url.indexOf('#prettyPhoto')!==-1)?decodeURI(url.substring(url.indexOf('#prettyPhoto')+1,url.length)):false;return hashtag;};
function setHashtag(){if(typeof theRel=='undefined')return;location.hash=theRel+'/'+rel_index+'/';};
function clearHashtag(){if(location.href.indexOf('#prettyPhoto')!==-1)location.hash="prettyPhoto";}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我有一个需要 MySql 5.6 的自定义应用程序。我能够使用本教程在 ubuntu 20.04 上安装 MySql 5.7:https : //askubuntu.com/a/1232993
如何在 ubuntu 20.04 上安装 MySql 5.6?
因为上面的教程只适用于MySql 5.7,我在网上没有找到任何可行的解决方案。
MySql 5.6 可以在 Ubuntu 20.04 上运行吗?我应该将操作系统降级到 Ubuntu 18.04 吗?
我想使用 Laravel Spark 为 API 创建不同的许可证。我想限制每月以及每小时/分钟的 API 调用。例如,基本许可证允许每月 10 000 次 API 调用,但我还想限制同一帐户每小时/分钟的 API 调用。这可以用 laravel Spark 来完成吗?
有:throttle 和rate_limit,但是我可以限制每月以及每小时/分钟的API 调用总数吗?例如:每月总共 10 000 次 api 调用,每小时/分钟最多 60 次 api 调用?
根据文档,我可以限制每分钟/小时的访问:https://laravel.com/docs/6.x/routing#rate-limiting
像这样的东西结合了节流和速率限制:
Route::middleware('auth:api', 'throttle:10|rate_limit,1')->group(function () {
Route::get('/user', function () { // });
});
Run Code Online (Sandbox Code Playgroud)
但我的主要问题是如何将每分钟/小时的速率限制与每月限制结合起来?
我有一个VueJS应用程序,其中包含以下配置:
1)config.index.js
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '',
/**
* Source Maps
*/
productionSourceMap: true,
// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra …Run Code Online (Sandbox Code Playgroud) javascript ×4
go ×2
jquery ×2
struct ×2
vue.js ×2
vuejs2 ×2
axios ×1
eclipse ×1
go-templates ×1
hibernate ×1
if-statement ×1
interface ×1
java ×1
laravel ×1
linux ×1
mysql ×1
mysql-5.6 ×1
npm ×1
onclick ×1
php ×1
plugins ×1
safari ×1
spring ×1
throttling ×1
ubuntu ×1
ubuntu-20.04 ×1
vue-router ×1
wordpress ×1