# ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that correspond

语法由于Mysql版本不匹配造成的

**出现情况:修改mysql密码的时候用的

1
update user set password=password("123456") where user="root";

解决方案:**

5.6版本

1
update mysql.user set password=password('123456') where User="root" and Host = "localhost"; set password for root@localhost = password('123456');

5.7版本

1
2
update mysql.user set authentication_string=password('123456') 
where User="root" and Host="localhost";

8.0版本

阅读全文 »

Spring注解配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.bookstore.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.springframework.context.annotation.*;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;
import java.util.Properties;

/**
* @Author BaiYZ
* @Program BookStoreFrameWork
* @Description Spring 配置类
* @Date 2022-01-02 23:00:13
*/
@Configuration
@ComponentScan(value = "com.bookstore", excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Controller.class)})
@EnableAspectJAutoProxy(proxyTargetClass = false)
@EnableTransactionManagement()
public class SpringConfig {
//注册数据库连接池
@Bean
public DruidDataSource getDataSource() {
Properties dataSourceProperties = new Properties();
try {
dataSourceProperties.load(SpringConfig.class.getClassLoader().getResourceAsStream("dataSource.properties"));
return (DruidDataSource) DruidDataSourceFactory.createDataSource(dataSourceProperties);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

//创建JDBCTemplate
@Bean
public JdbcTemplate getJdbcTemplate(DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setDataSource(dataSource);
return jdbcTemplate;

}

//注册事务管理器
@Bean
public DataSourceTransactionManager getDataSourceTransactionManager(DataSource dataSource) {
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
dataSourceTransactionManager.setDataSource(dataSource);
return dataSourceTransactionManager;
}
}
阅读全文 »

web.xml 注解配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.bookstore.config;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;
import javax.servlet.annotation.WebFilter;
/*
在Servlet3.0环境中,容器会在类路径中查找实现javax.servlet.ServletContainerInitializer接口的类
如果找到的话就用它来配置Servlet容器。Spring提供了这个接口的实现,名为SpringServletContainerInitializer
这个类反过来又会查找实现WebApplicationInitializer的类并将配置的任务交给它们来完成。
Spring3.2引入了一个便利的WebApplicationInitializer基础实现,名为AbstractAnnotationConfigDispatcherServletInitializer
当我们的类扩展了AbstractAnnotationConfigDispatcherServletInitializer并将其部署到Servlet3.0容器的时候
容器会自动发现它,并用它来配置Servlet上下文。
*/
/**
* @Author BaiYZ
* @Program BookStoreFrameWork
* @Description web.xml注解配置
* @Date 2022-01-04 22:25:21
*/

public class WebInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
/**
* @Description: 根配置就是配置Spring配置类
* @Author: BaiYZ
* @Date: 2022/1/4 22:26
* @return: java.lang.Class<?>[]
*/
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{SpringConfig.class};
}

/**
* @Description: 配置SpringMVC映射配置(配置控制器)
* @Author: BaiYZ
* @Date: 2022/1/4 22:28
* @return: java.lang.Class<?>[]
*/
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{SpringMVCConfig.class};
}

/**
* @Description: 配置DispatcherServlet Mapping(配置控制器映射)URL-Pattern
* @Author: BaiYZ
* @Date: 2022/1/4 22:28
* @return: java.lang.String[]
*/
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}

/**
* @Description: 注册过滤器
* @Author: BaiYZ
* @Date: 2022/1/4 22:35
* @return: javax.servlet.Filter[]
*/
@Override
protected Filter[] getServletFilters() {
//先配置编码过滤器
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceResponseEncoding(true);
//隐藏请求分发过滤器,使用put delete post get不同请求分发请求
HiddenHttpMethodFilter hiddenHttpMethodFilter = new HiddenHttpMethodFilter();
return new Filter[]{characterEncodingFilter,hiddenHttpMethodFilter};
}

}
阅读全文 »

web.xml配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<!-- 添加日志监听器 最上面-->
<!--log4j配置文件地-->
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>classpath:log4j2.xml</param-value>
</context-param>
<!-- Log4j的监听器要放在spring监听器前面 -->
<listener>
<listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>

<!--配置编码格式过滤器为UTF-8-->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<!--配置请求编码格式UTF-8-->
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<!--配置相应编码-->
<init-param>
<param-name>forceResponseEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!--配置使用Restful请求方式分发请求分发器,使用post put get delete _Method属性(隐藏域)-->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!--加载配置Spring-->
<!-- Configure ContextLoaderListener to use AnnotationConfigWebApplicationContext
instead of the default XmlWebApplicationContext -->
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<!-- Configuration locations must consist of one or more comma- or space-delimited
fully-qualified @Configuration classes. Fully-qualified packages may also be
specified for component-scanning -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.bookstore.config.SpringConfig</param-value>
</context-param>
<!-- Bootstrap the root application context as usual using ContextLoaderListener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<!--配置SpringMVC DispatcherServlet-->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--配置初始化配置问文件目录-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<!--设置服务器加载启动-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

阅读全文 »