idea中maven+ssm開發oa專案遇到問題彙總
阿新 • • 發佈:2018-11-21
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);
})