0
点赞
收藏
分享

微信扫一扫

需要记住的关键字


目录

​​一、spring配置:applicationContext.xml​​

​​1.1扫描包​​

​​2.2 AOP注解代理​​

​​2.3 引入外部xml和property​​

​​2.4 注解方式的事务配置​​

​​2.5 spring-mvc.xml​​

​​2.6 web.xml (主要针对springmvc)​​

​​二、spring-test​​

​​三、javaAPI​​

​​3.1 请求转发 重定向​​

​​springMVC内​​

​​四、文件上传​​

​​前端:​​

​​springmvc.xml配置​​

​​X、bootstrap细节样式​​

​​1.调整两个标签之间水平间距​​

​​五、el表达式​​

​​5.1 简单的日期格式化​​

​​六、jquery技巧​​

​​6.1 数据回显,select-option的默认选择项​​

​​6.2 删除多个 js提交表单 获取复选框选中的数量​​

​​6.3 el简单for循环 变量自增式循环​​

​​6.4 前端js方法,传递参数时,若参数时字母数字等混合字符串,一定加上‘’表示传的是字符串,否则传递不了,方法失效​​

​​七、ajax debug:​​

一、spring配置:applicationContext.xml

1.1扫描包

<!--扫描包,查找@Component,@Controller,@Service,@Repository 创建bean对象-->
<context:component-scan base-package="cn.ahpu"></context:component-scan>

2.2 AOP注解代理

<!--开启AOP自动代理-注解方式代理-->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>

2.3 引入外部xml和property

<!--引入外部属性文件 classpath:最好加上-->
<context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
<!--引入外部配置文件-->
<import resource="applicationContext-dao.xml"></import>

2.4 注解方式的事务配置

<!--创建事务管理器对象-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!--注入数据源:数据存在于某次数据库连接中-连接存在于连接池(数据源)中-->
<property name="dataSource" ref="springDataSource"></property>
</bean>

<!--关联事务管理器对象-->
<tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>

<!--开启aop的注解:自动代理 或许不需要-->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>

2.5 spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<!--扫描包-->
<context:component-scan base-package="cn.ahpu"></context:component-scan>
<!--视图解析器 内部资源视图解析 简化return-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!--引入注解驱动-->
<mvc:annotation-driven></mvc:annotation-driven>

<!--自定义类型转换时可能需要-->
<!--配置类型转换工厂-->
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<!--框架自己转换不了的类型会到这里来找类转换-->
<bean class="cn.ahpu.converter.StringToDateConverter"></bean>
</set>
</property>
</bean>
<!--注解驱动 关联类型转换工厂-->
<mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven>

</beans>

2.6 web.xml (主要针对springmvc)

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>
<!--编码过滤器 处理post请求乱码 get请求乱码tomcat内配-->
<filter>
<filter-name>CharacterEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncoding</filter-name>
<url-pattern>/*</url-pattern> <!--只拦截所有请求 不拦截静态资源-->
</filter-mapping>


<!--前端控制器-->
<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>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern><!--拦截所有资源 请求+静态资源-->
</servlet-mapping>
</web-app>

二、spring-test

a. 替换Junit的运行器: 为spring与junit整合后的运行器
@RunWith(SpringJUnit4ClassRunner.class)
b. 指定配置文件路径, 会自动创建容器对象, 必须添加classpath   字符串数组或单个字符串都行
@ContextConfiguration({"classpath:applicationContext.xml"})   //classpath:不能省略    ()内直接一个字符串其实是在配置value属性值

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class TestAOPXml {

}

分子moudle时写法 注意分各个子moudle,只有在service层的moudle内的test里才能访问serviceimpl方法

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath*:spring/*.xml")
public class TestPageHelper {
@Autowired
ProductService productService;

@Test
public void test(){
productService.testFindByPageHelper(1,5);
}
}

三、javaAPI

3.1 请求转发 重定向

重定向:

response.sendRedirect("/show2.jsp");

转发:

request.getRequestDispatcher("/WEB-INF/show.jsp").forward(request,response);

springMVC内

return "redirect:findAll"; //重定向到findAll方法
return "forward:findAll"; //转发到findAll方法

更新数据库之后一定是重定向到某个方法,否则可能导致刷新重新操作数据库

四、文件上传

前端:

<%--上传文件的表单前提
1) 提交方式必须post (get只能提交少量数据 post提交大量数据)
2) 表单类型必须:enctype="multipart/form-data" 多功能表单数据
3) 必须有一个type=file的表单元素
--%>
<form action="" method="post" enctype="multipart/form-data">
<input type="text" name="username"><br>
<input type="file" name="upload"><br>
<input type="submit" value="上传">
</form>

springmvc.xml配置

<!-- 配置文件上传解析器 -->
<!-- id的值是固定的 直接复制 不要记忆-->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 设置上传文件的最大尺寸为5MB -->
<property name="maxUploadSize">
<value>5242880</value>
</property>
</bean>

X、bootstrap细节样式

1.调整两个标签之间水平间距

<span style="margin:0 10px;"></span>

需要记住的关键字_mvc

五、el表达式

5.1 简单的日期格式化

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatDate value="${order.orderTime}" pattern="yyyy-MM-dd HH:mm"></fmt:formatDate>

六、jquery技巧

6.1 数据回显,select-option的默认选择项

//修改界面 selected option的默认选项 固有属性用prop()
$("#productStatus option[value=${product.productStatus}]").prop("selected","selected");

6.2 删除多个 js提交表单 获取复选框选中的数量

//TODO
//删除多个 直接提交表单最为方便
function delMany() {
//获取选中的复选框数量
var len = $("input:checkbox:checked").length;
//alert("你一共选中了"+len+"个复选框");
if(len>0&&confirm("您确定删除这些吗?")){
//获取表单
//document.forms 获取所有的表单 只有一个就是document.forms[0]
var delForm=$("#delForm");
//表单提交
delForm.submit();//提交了 和点submit效果一样
}
}

6.3 el简单for循环 变量自增式循环

<c:forEach begin="1" end="${pageBean.totalPage}" var="i">
<li><a href="javascript:gotoPage(${i})">${i}</a></li>
</c:forEach>

6.4 前端js方法,传递参数时,若参数时字母数字等混合字符串,一定加上‘’表示传的是字符串,否则传递不了,方法失效

<button type="button" class="btn btn-default" title="复制链接"
onclick="copyUrl('${fileShare.id}')"><%--批量删除--%>
<i class="fa fa-copy"></i>
</button>

此id是uuid不是integer,integer不要加''也行,但是uuid不加‘’包起来,点击一直没反应,这种错误还难找!

七、ajax debug:

error:function (jqXHR,textStatus,errorThrown) {
alert("error:\n"+"\n"+textStatus+"\n"+errorThrown)
alert(jqXHR.readyState+"||"+jqXHR.status+"||"+jqXHR.statusText+"||"+jqXHR.responseText)
$("#msg").html(jqXHR.responseText.toString())
},

jqXHR.responseText.toString()中有详细的报错信息

返回pojo json失败,1.老牌序列化问题:类上加注解     2. 安全框架未放行 访问不到后端方法

八、lombok 全参构造函数

@AllArgsConstructor  //全参数构造方法
@Data //get/set/toString

需要记住的关键字_spring_02

 

举报

相关推荐

0 条评论