idea中maven+ssm开发oa项目遇到问题汇总

1.target文件夹中不能生成mapper映射文件,一直报找不到错误
原因:idea不会吧src/main/java下的配置文件打包
解决方案:

<resources>
    <resource>
       <directory>src/main/java</directory>
        <includes>
        	<include>**/*.xml</include>
      	</includes>
      <filtering>true</filtering>
   </resource>
</resources>

2.编写jsp页面时el表达式不起作用
原因:maven创建项目时,web.xml头部声明默认是2.3,这个默认jsp关闭el表达式
解决方案:isELIgnored=“false”(推荐)

<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>

解决方案:更换头部声明为3.0(不推荐)

<?xml version="1.0" encoding="UTF-8"?>  
<web-app 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"  
          version="3.0">  
            
</web-app> 

3.post请求到后台乱码问题

<filter>
	<filter-name>CharacterEncodingFilter</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>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
</filter-mapping>

必须添加init-param部分内容!!!!!!!!!!!!!!!!!!!
必须添加init-param部分内容!!!!!!!!!!!!!!!!!!!
必须添加init-param部分内容!!!!!!!!!!!!!!!!!!!

1.encoding:字符集,即将过滤到的request的字符集设置为encoding指定的值,相当于

request.setCharacterEncoding("")

2.forceEncoding:字面意思是强制字符集,这个参数的值是指定response的字符集是否也设置成encoding所指定的字符集,所以你可以选择设置为true或false,当值为true时,相当于

request.setCharacterEncoding("");    
response.setCharacterEncoding("");

当值为false时,相当于

request.setCharacterEncoding(""); 

4.部门相关查询技术

知识点
递归,树形结构
在这里插入图片描述
mybatis
根据部门id查出该部门信息,并且携带所有子部门信息

<select id="getChildDepartment" resultType="Department" parameterType="Integer">
      SELECT * FROM department WHERE parentDepartmentid=#{departmentId}
 </select>

Test类

public class applicationContextTest {
    private DepartmentMapper bean;
    @Before
    public void init(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
        System.out.println(applicationContext.toString());
        bean = applicationContext.getBean(DepartmentMapper.class);
    }

    void digui(List<Department> list){
        for (Department department : list) {
            List<Department> department1 = bean.getChildDepartment(department.getDepartmentId());
            department.setChildDepartmentList(department1);
            digui(department1);
        }
    }

    @Test
    public void test(){
        List<Department> department = bean.getChildDepartment(12);
        digui(department);
        String s = JSON.toJSONString(department,true);
        System.out.println(s);
    }
}

结果

[
	{
		"childDepartmentList":[
			{
				"childDepartmentList":[
					{
						"childDepartmentList":[],
						"departmentId":16,
						"departmentName":"保安1部1组1个",
						"departmentNo":"6666",
						"parentDepartmentId":15
					}
				],
				"departmentId":15,
				"departmentName":"保安1部1组",
				"departmentNo":"222222222",
				"parentDepartmentId":13
			}
		],
		"departmentId":13,
		"departmentName":"保安1部",
		"departmentNo":"333333",
		"parentDepartmentId":12
	},
	{
		"childDepartmentList":[],
		"departmentId":14,
		"departmentName":"保安2部",
		"departmentNo":"444444",
		"parentDepartmentId":12
	}
]

5.一个用户对应多个角色,多个角色对应的权限list可能会有重复,如何进行去重呢?

答:利用HashSet

public static List removeDuplicate(List list) {   
    HashSet h = new HashSet(list);   
    list.clear();   
    list.addAll(h);   
    return list;   
}   

6.省市县三级联动前台实现

<div class="form-group">
	<label for="s_province" class="col-sm-2 control-label">祖籍</label>
	<div class="col-sm-3">
		<select id="s_province" name="province" class="form-control"></select>
	</div>
	<div class="col-sm-3">
		<select id="s_city" name="city" class="form-control"></select>
	</div>
	<div class="col-sm-3">
		<select id="s_county" name="county"  class="form-control"></select>
	</div>
</div>
<div id="show"></div>
<script class="resources library" src="http://sandbox.runjs.cn/uploads/rs/267/g3ugugjp/area.js" type="text/javascript"></script>
<script type="text/javascript">_init_area();</script>
<script type="text/javascript">
	var Gid  = document.getElementById ;
	var showArea = function(){
		Gid('show').innerHTML = "<h3>省" + Gid('s_province').value + " - 市" +
			Gid('s_city').value + " - 县/区" +
			Gid('s_county').value + "</h3>"
	}
	Gid('s_county').setAttribute('onchange','showArea()');
</script>

7.springmvc接受POJO参数,参数中有date日期类型属性,无法绑定到pojo对象上,导致400错误

解决方案:

@DateTimeFormat(pattern="yyyy-MM-dd")
private Date birthday;

8.js页面input框去空格问题

//去空格
$("input").blur(function () {
	console.log("blur");
	var trim=$(this).val().trim();
	//!!!inportant一步
	$(this).val(trim);
})

猜你喜欢

转载自blog.csdn.net/qq_39905910/article/details/83654002